Explv Posted August 4, 2017 Share Posted August 4, 2017 (edited) import org.osbot.rs07.utility.ConditionalSleep; import java.util.function.BooleanSupplier; public final class Sleep extends ConditionalSleep { private final BooleanSupplier condition; public Sleep(final BooleanSupplier condition, final int timeout) { super(timeout); this.condition = condition; } public Sleep(final BooleanSupplier condition, final int timeout, final int interval) { super(timeout, interval); this.condition = condition; } @Override public final boolean condition() throws InterruptedException { return condition.getAsBoolean(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) { return new Sleep(condition, timeout).sleep(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout, final int interval) { return new Sleep(condition, timeout, interval).sleep(); } } Usage: Sleep sleep = new Sleep(() -> myPlayer().isAnimating(), 5000); sleep.sleep(); Or: Sleep.sleepUntil(() -> myPlayer().isAnimating(), 5000); Edited August 4, 2017 by Explv 3 1 1 Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted August 4, 2017 Share Posted August 4, 2017 Is much easier #greynames 1 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted August 4, 2017 Share Posted August 4, 2017 Wow gr8 Quote Link to comment Share on other sites More sharing options...
Tom Posted August 4, 2017 Share Posted August 4, 2017 public class CustomSleep extends ConditionalSleep{ private BooleanSupplier condition; public CustomSleep(BooleanSupplier condition, int timeout) { super(timeout); this.condition = condition; } @Override public boolean condition() throws InterruptedException { return condition.getAsBoolean(); } } Example usage new CustomSleep(() -> myPlayer().isAnimating(), 2000).sleep(); Quote Link to comment Share on other sites More sharing options...
Eliot Posted August 4, 2017 Share Posted August 4, 2017 Nice snippet, but I prefer 1 Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted August 4, 2017 Share Posted August 4, 2017 1 minute ago, Tom said: public class CustomSleep extends ConditionalSleep{ private BooleanSupplier condition; public CustomSleep(BooleanSupplier condition, int timeout) { super(timeout); this.condition = condition; } @Override public boolean condition() throws InterruptedException { return condition.getAsBoolean(); } } Example usage new CustomSleep(() -> myPlayer().isAnimating(), 2000).sleep(); He just has an interval parameter to change how often to check I believe, otherwise it's the same. ._. Quote Link to comment Share on other sites More sharing options...
Explv Posted August 4, 2017 Author Share Posted August 4, 2017 (edited) 1 minute ago, Eliot said: Nice snippet, but I prefer You should be demoted REEEEEEEEEE Edited August 4, 2017 by Explv 1 Quote Link to comment Share on other sites More sharing options...
Tom Posted August 4, 2017 Share Posted August 4, 2017 2 minutes ago, GoldenGates said: He just has an interval parameter to change how often to check I believe, otherwise it's the same. ._. Yeah but the snippet is mine and not his Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted August 4, 2017 Share Posted August 4, 2017 4 minutes ago, Tom said: Yeah but the snippet is mine and not his Oh ok then you should file a lawsuit on his cunty Mgee ass. Quote Link to comment Share on other sites More sharing options...
ProjectPact Posted August 4, 2017 Share Posted August 4, 2017 You guys should try sleep(5000); Quote Link to comment Share on other sites More sharing options...
bugsinmycode Posted August 4, 2017 Share Posted August 4, 2017 Cool snippet, thanks for sharing. Quote Link to comment Share on other sites More sharing options...
Easy Posted August 4, 2017 Share Posted August 4, 2017 (edited) Edited August 4, 2017 by Easy Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted August 4, 2017 Share Posted August 4, 2017 Thanks papa Quote Link to comment Share on other sites More sharing options...
Final Posted August 4, 2017 Share Posted August 4, 2017 3 hours ago, Easy said: Thanks for the blatantly obvious meme Quote Link to comment Share on other sites More sharing options...
NoxMerc Posted December 31, 2018 Share Posted December 31, 2018 (edited) Thought I'd add a comment here instead of a new thread. Made a smol addition to the Sleep class that saves some lines of code down the road. public static <k> k untilNotNull(final Supplier<k> locator, final int timeout, final int interval) { Sleep.until(() -> locator.get() != null, timeout, interval); return locator.get(); } Using this, you can essentially wait for an item to be not-null, and it'll return it. Like so: RS2Object coal = Sleep.untilNotNull(() -> ctx.getObjects().closest(ent -> MiningEntity.COAL.hasOre(ent)), 15_000, 750); if (coal == null) //ABORT I could save an additional call to the locator by wrapping the <k> in a mutable final object, but meh. Edited December 31, 2018 by NoxMerc Quote Link to comment Share on other sites More sharing options...