Explv Posted August 4, 2017 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
Tom Posted August 4, 2017 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();
GoldenGates Posted August 4, 2017 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. ._.
Explv Posted August 4, 2017 Author 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
Tom Posted August 4, 2017 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
GoldenGates Posted August 4, 2017 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.
Final Posted August 4, 2017 Posted August 4, 2017 3 hours ago, Easy said: Thanks for the blatantly obvious meme
NoxMerc Posted December 31, 2018 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