From 97e58fa736e1b80b9d5a7687fde824bc7d33b91f Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Sun, 21 Jun 2026 16:21:11 +0200 Subject: [PATCH] Do not enforce 0-99 priority rule on system events System events (WinEvent, BattleEndedEvent, SkippedTurnEvent, RoundEndedEvent, etc.) have a fixed priority of 100, which is outside the 0-99 range allowed for robot-defined events. When something stamps such an event with its default priority, Event.setPriorityHidden() clamped it to 99 and printed misleading 'SYSTEM: Priority must be between 0 and 99' / 'Priority for robocode.WinEvent will be 99' warnings to the robot console. Fix setPriorityHidden() to return early for critical (system) events, leaving their priority untouched and emitting no warning. Also make EventManager.setEventPriority() return after warning a robot that it may not change a system event's priority, so the change is genuinely ignored. isCriticalEvent() is package-private and robocode.* classes cannot be defined by the robot class loader, so robots cannot override it to abuse this path. --- robocode.api/src/main/java/robocode/Event.java | 7 +++++++ .../java/net/sf/robocode/host/events/EventManager.java | 1 + 2 files changed, 8 insertions(+) diff --git a/robocode.api/src/main/java/robocode/Event.java b/robocode.api/src/main/java/robocode/Event.java index 5c27c4999..54aec7003 100644 --- a/robocode.api/src/main/java/robocode/Event.java +++ b/robocode.api/src/main/java/robocode/Event.java @@ -170,6 +170,13 @@ private void setTimeHidden(long time) { */ // This method must be invisible on Robot API private void setPriorityHidden(int newPriority) { + // System events have a fixed priority (e.g. 100) that is outside the 0-99 range allowed for + // robot-defined events. The priority of a system event must not be changed, and the 0-99 rule + // must not be enforced for them, as that would clamp their priority and emit misleading + // warnings on the robot console. + if (isCriticalEvent()) { + return; + } if (newPriority < 0) { Logger.printlnToRobotsConsole("SYSTEM: Priority must be between 0 and 99"); Logger.printlnToRobotsConsole("SYSTEM: Priority for " + this.getClass().getName() + " will be 0"); diff --git a/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java b/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java index 54d826ac3..f628558b7 100644 --- a/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java +++ b/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java @@ -510,6 +510,7 @@ public void setEventPriority(String eventClass, int priority) { } if (HiddenAccess.isCriticalEvent(event)) { robotProxy.println("SYSTEM: You may not change the priority of a system event."); + return; } HiddenAccess.setEventPriority(event, priority); }