Break handler fixes + Region Filter#1452
Conversation
…#1440) * feat(sandminer): drop empty waterskins when humidify is disabled * refactor(sandminer): drop empty waterskins only when idle and drop all --------- Co-authored-by: Pert <your.email@example.com>
…chsami#1440)" This reverts commit 8da3f86.
Updated login handling to select a random world when “Use RandomWorld” is enabled. Skipped additional world hopping after breaks when a logout already handled the switch, preventing unnecessary double hops.
…re enabled and no break is active, sending requests to Break Handler appropriately.
…breaks are enabled and no break is active, sending requests to Break Handler appropriately." This reverts commit 04f081a.
…ses." This reverts commit 6ea7322.
WalkthroughIntroduces region-aware world selection to the break handler. Adds RegionFilter enum and a corresponding config item. Break flow now records the pre-break world, tracks logout occurrence, adjusts logout logic for micro breaks, and selects login target world using either a random region-filtered world or the pre-break world. Version bumped. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Scheduler as Break Scheduler
participant Script as BreakHandlerScript
participant Config as BreakHandlerConfig
participant Login as Login API
participant Worlds as World List
Scheduler->>Script: Initiate break
Script->>Script: preBreakWorld = currentWorld
Script->>Script: loggedOutDuringBreak = shouldLogout(microBreakActive, schedule, config)
alt Micro break
Script->>Script: Pause without logout
else Logout break
Script->>Login: Request logout
end
Scheduler->>Script: Resume play
alt Active profile present
Script->>Config: useRandomWorld(), regionFilter()
alt useRandomWorld = true
Script->>Worlds: getRandomWorld(member, regionFilter.region)
Worlds-->>Script: randomWorld
Script->>Login: Login(profile, randomWorld)
else
Script->>Login: Login(profile, preBreakWorld)
end
else No active profile
Script->>Login: Login()
end
note over Script,Login: Post-break world switch is skipped if loggedOutDuringBreak = true
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (8)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerConfig.java (1)
135-144: Region filter: clarify applicability in the descriptionMinor copy improvement so users know it only matters when random world hopping is enabled.
- description = "Restrict random worlds to a specific region", + description = "Restrict random worlds to a specific region (applies when 'Use Random World' is enabled)",runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/RegionFilter.java (1)
21-26: Rename field ‘name’ to ‘displayName’ to avoid confusion with Enum.name()This avoids overshadowing/confusion and reads clearer in code.
- private final String name; + private final String displayName; @Override public String toString() { - return name; + return displayName; }runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerScript.java (6)
42-47: Javadoc version mismatchBump @Version in the header to match the new version field.
- * @version 2.0.0 + * @version 2.1.0
109-112: Reset per-break flags after finishing a breakloggedOutDuringBreak and preBreakWorld persist across breaks; reset them during cleanup to avoid stale state influencing the next break.
private void cleanupBreakState() { breakDuration = -1; setBreakDurationTime = Duration.ZERO; + loggedOutDuringBreak = false; + preBreakWorld = -1; }Also applies to: 656-659
331-333: Prefer Rs2Player.getWorld() helperKeeps usage consistent with the rest of the codebase and reduces direct client coupling.
- preBreakWorld = Microbot.getClient().getWorld(); + preBreakWorld = Rs2Player.getWorld();
335-343: Simplify logout vs. micro-break branchingshouldLogout() already returns false during micro breaks. The extra micro-break clause in loggedOutDuringBreak and the if-condition is redundant.
- boolean logout = shouldLogout(); - loggedOutDuringBreak = logout && !(Rs2AntibanSettings.microBreakActive && config.onlyMicroBreaks()); - if (!logout || (Rs2AntibanSettings.microBreakActive && config.onlyMicroBreaks())) { + boolean logout = shouldLogout(); + loggedOutDuringBreak = logout; + if (!logout) { setBreakDuration(); transitionToState(BreakHandlerState.MICRO_BREAK_ACTIVE); } else { transitionToState(BreakHandlerState.LOGOUT_REQUESTED); }
456-464: Use membership cached before logout to choose worlds while logged outRs2Player.isMember() may be unreliable while logged out. Cache membership at break start and reuse it for login/world selection.
Add a field near other state fields:
- private boolean loggedOutDuringBreak = false; + private boolean loggedOutDuringBreak = false; + private boolean preBreakWasMember = false;Capture it when initiating the break:
- preBreakWorld = Rs2Player.getWorld(); + preBreakWorld = Rs2Player.getWorld(); + preBreakWasMember = Rs2Player.isMember();Use the cached value on login:
- int world = config.useRandomWorld() - ? Login.getRandomWorld(Rs2Player.isMember(), config.regionFilter().getRegion()) + int world = config.useRandomWorld() + ? Login.getRandomWorld(preBreakWasMember, config.regionFilter().getRegion()) : preBreakWorld;And for post-break hop:
- int randomWorld = Login.getRandomWorld(Rs2Player.isMember(), config.regionFilter().getRegion()); + int randomWorld = Login.getRandomWorld(preBreakWasMember, config.regionFilter().getRegion());Also applies to: 629-631
627-635: Skip redundant world hopsAvoid hopping if the selected random world equals the current world.
- int randomWorld = Login.getRandomWorld(preBreakWasMember, config.regionFilter().getRegion()); - Microbot.hopToWorld(randomWorld); - log.info("Switched to world {}", randomWorld); + int randomWorld = Login.getRandomWorld(preBreakWasMember, config.regionFilter().getRegion()); + if (Rs2Player.getWorld() != randomWorld) { + Microbot.hopToWorld(randomWorld); + log.info("Switched to world {}", randomWorld); + } else { + log.info("Randomly selected current world {}; skipping hop", randomWorld); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerConfig.java(2 hunks)runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerScript.java(6 hunks)runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/RegionFilter.java(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-30T15:17:12.028Z
Learnt from: T-edit
PR: chsami/Microbot#1448
File: runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java:22-24
Timestamp: 2025-08-30T15:17:12.028Z
Learning: In the RuneLite codebase, the WorldRegion enum constants are: UNITED_STATES_OF_AMERICA, UNITED_KINGDOM, AUSTRALIA, and GERMANY. The US region constant is specifically UNITED_STATES_OF_AMERICA, not UNITED_STATES.
Applied to files:
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/RegionFilter.java
🧬 Code graph analysis (1)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerScript.java (1)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/player/Rs2Player.java (1)
Rs2Player(67-2062)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (5)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerConfig.java (2)
126-133: UI label fix looks good“Use Random World” reads well and matches the PR intent.
146-151: Reordering position is fineMoving Shutdown Client to position 4 to make room for Region Filter is consistent and non-breaking.
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/RegionFilter.java (1)
12-16: Correct WorldRegion constantsGood catch on UNITED_STATES_OF_AMERICA; matches known enum values in this codebase.
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerScript.java (2)
567-571: Logout gating logic aligns with PR goalThis change prevents logout during micro breaks and respects the “Logout” toggle unless outside the play schedule. Matches “Fixed logging out even if ‘Logout’ is disabled”.
460-463: Null region handling is safe
Login.getRandomWorld(boolean, WorldRegion) guards the region filter withif (region != null), so passing null (RegionFilter.ANY) skips the region check and selects from all regions without NPE risk.
Fixed logging out even if "Logout" is disabled in Break Handler.
Fixed typo "RandomWorld"
Added "Region Filter" when "Random World" is enabled.
Summary by CodeRabbit