Skip to content

Commit c434365

Browse files
authored
Merge pull request #1656 from chsami/development
Development
2 parents b6c1391 + 55f99c3 commit c434365

File tree

2 files changed

+68
-15
lines changed

2 files changed

+68
-15
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ project.build.group=net.runelite
3131
project.build.version=1.12.12.1
3232

3333
glslang.path=
34-
microbot.version=2.1.12
34+
microbot.version=2.1.13
3535
microbot.commit.sha=nogit
3636
microbot.repo.url=http://138.201.81.246:8081/repository/microbot-snapshot/
3737
microbot.repo.username=

runelite-client/src/main/java/net/runelite/client/plugins/microbot/util/antiban/AntibanPlugin.java

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import net.runelite.client.plugins.PluginDescriptor;
1414
import net.runelite.client.plugins.microbot.Microbot;
1515
import net.runelite.client.plugins.microbot.breakhandler.BreakHandlerPlugin;
16+
import net.runelite.client.plugins.microbot.util.events.PluginPauseEvent;
17+
import lombok.extern.slf4j.Slf4j;
1618
import net.runelite.client.plugins.microbot.util.antiban.enums.Activity;
1719
import net.runelite.client.plugins.microbot.util.antiban.enums.ActivityIntensity;
1820
import net.runelite.client.plugins.microbot.util.antiban.enums.CombatSkills;
@@ -79,7 +81,7 @@
7981
alwaysOn = true,
8082
hidden = true
8183
)
82-
84+
@Slf4j
8385
public class AntibanPlugin extends Plugin {
8486

8587
private static final int COOK_TIMEOUT = 3;
@@ -100,6 +102,16 @@ public class AntibanPlugin extends Plugin {
100102
private static final int MICRO_BREAK_DURATION_HIGH_MIN = 1;
101103
private static final int MICRO_BREAK_DURATION_HIGH_MAX = 30;
102104

105+
/**
106+
* Avoid spamming the user if they keep micro breaks on while the break handler is disabled.
107+
*/
108+
private boolean warnedBreakHandlerDisabled;
109+
110+
/**
111+
* Remembers last micro-break state to detect transitions (start/end).
112+
*/
113+
private boolean lastMicroBreakActive;
114+
103115
@Inject
104116
private OverlayManager overlayManager;
105117

@@ -179,6 +191,8 @@ public void run() {
179191
protected void shutDown() {
180192
overlayManager.removeIf(overlay -> overlay instanceof AntibanOverlay);
181193
clientToolbar.removeNavigation(navButton);
194+
195+
clearPauseFlags();
182196
}
183197

184198
@Subscribe
@@ -242,18 +256,7 @@ public void onGameTick(GameTick event) {
242256

243257
validateAndSetBreakDurations();
244258

245-
if (Rs2AntibanSettings.takeMicroBreaks && !Microbot.isPluginEnabled(BreakHandlerPlugin.class)) {
246-
if (Rs2AntibanSettings.devDebug)
247-
Microbot.showMessage("Micro breaks depend on the BreakHandlerPlugin, enabling it now.");
248-
249-
Microbot.log("BreakHandlerPlugin not enabled, enabling it now.");
250-
String name = BreakHandlerPlugin.class.getName();
251-
Plugin breakHandlerPlugin = Microbot.getPluginManager().getPlugins().stream()
252-
.filter(x -> x.getClass().getName().equals(name))
253-
.findFirst()
254-
.orElse(null);
255-
Microbot.startPlugin(breakHandlerPlugin);
256-
}
259+
handleMicroBreakIntegration();
257260

258261
if (Rs2Antiban.isMining()) {
259262
updateLastMiningAction();
@@ -274,6 +277,57 @@ public void onGameTick(GameTick event) {
274277
}
275278
}
276279

280+
/**
281+
* Micro-break / BreakHandler integration logic that respects the user's manual BreakHandler toggle.
282+
*
283+
* Behaviour:
284+
* - If user has micro-breaks on and BreakHandler is disabled, we warn once and do NOT auto-start.
285+
* - When micro-breaks end, we clear pause flags so scripts resume even if BreakHandler stays disabled.
286+
*/
287+
private void handleMicroBreakIntegration() {
288+
boolean microBreaksEnabled = Rs2AntibanSettings.takeMicroBreaks;
289+
290+
// Detect end of micro-break to clear flags even if BreakHandler stays enabled.
291+
if (lastMicroBreakActive && !Rs2AntibanSettings.microBreakActive) {
292+
clearPauseFlags();
293+
}
294+
lastMicroBreakActive = Rs2AntibanSettings.microBreakActive;
295+
296+
if (!microBreaksEnabled) {
297+
// User turned off micro-breaks; ensure pause flags are released.
298+
return;
299+
}
300+
301+
// Micro-breaks enabled: ensure BreakHandler is available, but respect manual disable.
302+
if (Microbot.isPluginEnabled(BreakHandlerPlugin.class)) {
303+
// Already on (user or us). Nothing else to do.
304+
return;
305+
}
306+
307+
// BreakHandler is off. If user turned it off, warn once and skip auto-start.
308+
if (warnedBreakHandlerDisabled) {
309+
return;
310+
}
311+
312+
// If a micro-break was triggered while BreakHandler is disabled, cancel it and unpause to avoid getting stuck.
313+
if (Rs2AntibanSettings.microBreakActive) {
314+
Rs2AntibanSettings.microBreakActive = false;
315+
clearPauseFlags();
316+
}
317+
318+
warnedBreakHandlerDisabled = true;
319+
Microbot.showMessage("Micro breaks need BreakHandler. Enable it to use micro breaks.");
320+
log.debug("Micro breaks requested but BreakHandler is disabled; respecting user choice.");
321+
}
322+
323+
/**
324+
* Clears global pause flags to guarantee scripts resume after micro-break.
325+
*/
326+
private void clearPauseFlags() {
327+
PluginPauseEvent.setPaused(false);
328+
Microbot.pauseAllScripts.compareAndSet(true, false);
329+
}
330+
277331
@Subscribe
278332
public void onStatChanged(StatChanged statChanged) {
279333
if (!Rs2AntibanSettings.antibanEnabled) {
@@ -374,4 +428,3 @@ public static void validateAndSetBreakDurations() {
374428
}
375429
}
376430
}
377-

0 commit comments

Comments
 (0)