Botre Posted March 27, 2016 Share Posted March 27, 2016 (edited) Quick snippet that allows you to pass lambda expressions in order to evaluate ConditionalSleep. Syntactic sugar: CSleep.create(2400, 200, () -> !myPlayer().getPosition().equals(cache)).sleep(); vs. new ConditionalSleep(2400,200) {@Override public boolean condition() throws InterruptedException { return !myPlayer().getPosition().equals(cache); }}.sleep(); Snippet: package org.botre; import java.util.function.Function; import org.osbot.rs07.utility.ConditionalSleep; public final class CSleep { private CSleep() { } public static ConditionalSleep create(int maximumMs, int deviationMs, BooleanSupplier condition) { return new ConditionalSleep(maximumMs, deviationMs) { @Override public boolean condition() throws InterruptedException { return condition.getAsBoolean(); } }; } } Edited April 1, 2016 by Botre 4 Quote Link to comment Share on other sites More sharing options...
Botre Posted April 1, 2016 Author Share Posted April 1, 2016 Updated to use BooleanSupplier instead of Predicate<T> https://docs.oracle.com/javase/8/docs/api/java/util/function/BooleanSupplier.html 1 Quote Link to comment Share on other sites More sharing options...
DragonAlpha Posted April 3, 2016 Share Posted April 3, 2016 Amazing Quote Link to comment Share on other sites More sharing options...
Scripter 3 Posted April 3, 2016 Share Posted April 3, 2016 Nice work. Thanks for the snippet Quote Link to comment Share on other sites More sharing options...
Explv Posted April 16, 2016 Share Posted April 16, 2016 (edited) package org.botre; import java.util.function.Function; import org.osbot.rs07.utility.ConditionalSleep; public final class CSleep { private CSleep() { } public static ConditionalSleep create(int maximumMs, int deviationMs, BooleanSupplier condition) { return new ConditionalSleep(maximumMs, deviationMs) { @Override public boolean condition() throws InterruptedException { return condition.getAsBoolean(); } }; } } Alternatively you could just extend the ConditionalSleep class: import org.osbot.rs07.utility.ConditionalSleep; import java.util.function.BooleanSupplier; public final class FConditionalSleep extends ConditionalSleep { private final BooleanSupplier condition; public FConditionalSleep(final BooleanSupplier condition, int timeout) { super(timeout); this.condition = condition; } @Override public boolean condition() throws InterruptedException { return condition.getAsBoolean(); } } new FConditionalSleep(() -> myPlayer().isAnimating(), 5000).sleep(); Edited April 16, 2016 by Explv 3 Quote Link to comment Share on other sites More sharing options...