Skip to content

Comments

Break handler fixes + Region Filter#1452

Merged
chsami merged 19 commits intochsami:developmentfrom
Netoxique:break_handler_fixes
Aug 31, 2025
Merged

Break handler fixes + Region Filter#1452
chsami merged 19 commits intochsami:developmentfrom
Netoxique:break_handler_fixes

Conversation

@Netoxique
Copy link
Contributor

@Netoxique Netoxique commented Aug 30, 2025

  • Fixed logging out even if "Logout" is disabled in Break Handler.

  • Fixed typo "RandomWorld"

  • Added "Region Filter" when "Random World" is enabled.

java_a5r3yWaIlS

Summary by CodeRabbit

  • New Features
    • Added Region Filter setting to control regions for random world selection.
    • Login and post-break world selection now respect region filters when using random worlds.
    • When not using random worlds, the client returns to the pre-break world.
    • Logout is skipped during micro breaks for smoother continuity.
  • Style
    • Renamed “UseRandomWorld” to “Use Random World”.
    • Reordered “Shutdown Client” setting within Break Behavior.
  • Chores
    • Updated plugin version to 2.1.0.

gmason0 and others added 19 commits August 23, 2025 03:43
…#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>
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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 30, 2025

Walkthrough

Introduces 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

Cohort / File(s) Summary
Region-based world selection and break-flow adjustments
runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerConfig.java, runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/BreakHandlerScript.java, runelite-client/src/main/java/net/runelite/client/plugins/microbot/breakhandler/RegionFilter.java
- Add RegionFilter enum (ANY/US/UK/GERMANY/AUSTRALIA) with display names and WorldRegion mapping
- New config: regionFilter() with default ANY; UI label tweak “Use Random World” and reordered “Shutdown Client” item
- Script: version to 2.1.0; track preBreakWorld and loggedOutDuringBreak; refine shouldLogout() to skip micro breaks; on login, choose random region-filtered world if configured or fallback to preBreakWorld; guard post-break world switching when a logout occurred

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 description

Minor 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 mismatch

Bump @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 break

loggedOutDuringBreak 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() helper

Keeps 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 branching

shouldLogout() 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 out

Rs2Player.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 hops

Avoid 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 4c7284d and 481b3be.

📒 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 fine

Moving 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 constants

Good 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 goal

This 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 with if (region != null), so passing null (RegionFilter.ANY) skips the region check and selects from all regions without NPE risk.

@chsami chsami merged commit 20d8ff2 into chsami:development Aug 31, 2025
2 checks passed
@chsami chsami mentioned this pull request Sep 3, 2025
@Netoxique Netoxique deleted the break_handler_fixes branch September 6, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants