yfoo Posted September 2 Share Posted September 2 I want to start a break early. This doesn't work. OSB logs "Started random solver : " then immediately calls onExit, skipping BreakManager's onloop. package Util; import org.osbot.rs07.Bot; import org.osbot.rs07.randoms.BreakManager; public class BreakManagerHook extends BreakManager { private static boolean breakNow = false; public BreakManagerHook(Bot IiIiiiIiiII) { super(IiIiiiIiiII); } @Override public boolean shouldActivate() { if(super.shouldActivate() || breakNow) { breakNow = false; return true; } return false; } @Override public void onExit() { super.onExit(); log("Return from break hook!"); } public static void startBreakNow() { breakNow = true; } } Quote Link to comment Share on other sites More sharing options...
yfoo Posted September 2 Author Share Posted September 2 Ok this seems to work. shouldActivate() gets called multiple times, so I have to "short circuit" it. @Override public boolean shouldActivate() { if(breakNow) log("Early breaking"); return super.shouldActivate() || breakNow; } Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted September 2 Share Posted September 2 19 minutes ago, yfoo said: I want to start a break early. This doesn't work. OSB logs "Started random solver : " then immediately calls onExit, skipping BreakManager's onloop. Well the moment it start it also stops as you set it back to false after doing this if(super.shouldActivate() || breakNow) { Quote Link to comment Share on other sites More sharing options...
dubai Posted September 3 Share Posted September 3 Are you doing this to have you script break early say, when it's at the bank? Interesting approach if so, I disabled osbots break manager completely and just had it sleep until the break was over then let the login solver log the player back in and continue Quote Link to comment Share on other sites More sharing options...
yfoo Posted September 7 Author Share Posted September 7 On 9/3/2024 at 4:43 PM, dubai said: Are you doing this to have you script break early say, when it's at the bank? Interesting approach if so, I disabled osbots break manager completely and just had it sleep until the break was over then let the login solver log the player back in and continue Yes, I do not want a break to happen at a certain time. I was working on a blast mining script If there was not enough time remaining before break to do cycle then start the break early. Quote Link to comment Share on other sites More sharing options...
dubai Posted September 8 Share Posted September 8 10 hours ago, yfoo said: Yes, I do not want a break to happen at a certain time. I was working on a blast mining script If there was not enough time remaining before break to do cycle then start the break early. Yeah I gotcha, heaps of reasons to add custom breaks tbh. I started doing this but I never finished it... @Czar Where you at Quote Link to comment Share on other sites More sharing options...
yfoo Posted September 8 Author Share Posted September 8 (edited) 4 hours ago, dubai said: Yeah I gotcha, heaps of reasons to add custom breaks tbh. I started doing this but I never finished it... @Czar Where you at This was the end result I settled with. I also happened to need a hook to know when the break ended to potentially check if my position was crashed while I was away. The OnExit() allows me to know that. For now I'm not doing anything with it just logging (log("Return from break!");) package Util; import org.osbot.rs07.Bot; import org.osbot.rs07.randoms.BreakManager; public class BreakManagerHook extends BreakManager { private volatile boolean breakEarly; private volatile boolean shouldActivateCalled; private static BreakManagerHook instance; public static BreakManagerHook getInstance() { if(instance == null) { throw new NullPointerException("ExcavatePlantIgnite is null"); } return instance; } public static BreakManagerHook initInstance(Bot bot) { instance = new BreakManagerHook(bot); return instance; } private BreakManagerHook(Bot IiIiiiIiiII) { super(IiIiiiIiiII); } @Override public synchronized boolean shouldActivate() { if(breakEarly && !shouldActivateCalled) { log(String.format("Thread %d notifying...", Thread.currentThread().getId())); shouldActivateCalled = true; this.notify(); } if(super.shouldActivate() && breakEarly) { breakEarly = false; log("breakEarly -> false"); } return super.shouldActivate() || breakEarly; } @Override public void onExit() { super.onExit(); log("Return from break!"); } public synchronized void startBreakEarly() throws InterruptedException { breakEarly = true; shouldActivateCalled = false; while (!shouldActivateCalled) { log(String.format("Thread %d waiting until shouldActivate() called...", Thread.currentThread().getId())); this.wait(); } log("Exited startBreakEarly"); } } Edited September 8 by yfoo Quote Link to comment Share on other sites More sharing options...
dubai Posted September 15 Share Posted September 15 On 9/8/2024 at 4:11 PM, yfoo said: This was the end result I settled with. I also happened to need a hook to know when the break ended to potentially check if my position was crashed while I was away. The OnExit() allows me to know that. For now I'm not doing anything with it just logging (log("Return from break!");) public class BreakManagerHook extends BreakManager { This looks like it will work? have you tested it yet? Quote Link to comment Share on other sites More sharing options...
yfoo Posted September 16 Author Share Posted September 16 (edited) On 9/14/2024 at 9:49 PM, dubai said: This looks like it will work? have you tested it yet? When I wrote it like 2 weeks ago it worked. You need to override the break manager with an instance of the class Put this in onStart bot.getRandomExecutor().overrideOSBotRandom(BreakManagerHook.initInstance(bot)); Then use this to start a break early. BreakManagerHook.getInstance().startBreakEarly(); Edited September 16 by yfoo Quote Link to comment Share on other sites More sharing options...
dubai Posted September 18 Share Posted September 18 On 9/17/2024 at 9:44 AM, yfoo said: When I wrote it like 2 weeks ago it worked. You need to override the break manager with an instance of the class Put this in onStart bot.getRandomExecutor().overrideOSBotRandom(BreakManagerHook.initInstance(bot)); Then use this to start a break early. BreakManagerHook.getInstance().startBreakEarly(); Hope you don't mind if I just copy and paste this Quote Link to comment Share on other sites More sharing options...