BravoTaco Posted October 13, 2019 Share Posted October 13, 2019 (edited) Code: Spoiler Conditional Sleep For New Threads: Spoiler private boolean conditionalSleep(BooleanSupplier condition, long maxTime, long checkTime) { long startTime = System.currentTimeMillis(); while (!condition.getAsBoolean() && (System.currentTimeMillis() - startTime) < maxTime) { try { Thread.sleep(checkTime); } catch (InterruptedException e) { e.printStackTrace(); } } return condition.getAsBoolean(); } Usage: if (conditionalSleep(() -> script.myPlayer().isAnimating(), 10000, 500)) { script.log("Player Is Animating!"); if (conditionalSleep(() -> !script.myPlayer().isAnimating(), 10000, 500)) { script.log("Player is No Longer Animating"); } } Animation Delay Sleep: Spoiler private boolean sleepWithAnimationDelay(int maxTimeToWaitForAnimationStart, int maxTimeForAnimationDelay) throws InterruptedException { new ConditionalSleep(maxTimeToWaitForAnimationStart, 20) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); long startTime = System.currentTimeMillis(); if (myPlayer().isAnimating()) { while (System.currentTimeMillis() - startTime < maxTimeForAnimationDelay) { if (myPlayer().isAnimating()) { startTime = System.currentTimeMillis(); sleep(20); } } } else { return false; } return true; } Usage: if (sleepWithAnimationDelay(10000, 3000)) { log("Animation Delay Over!"); } Edited October 13, 2019 by BravoTaco Quote Link to comment Share on other sites More sharing options...
Fishing Posted October 14, 2019 Share Posted October 14, 2019 Nice share Quote Link to comment Share on other sites More sharing options...
depern Posted October 14, 2019 Share Posted October 14, 2019 Nice method. Quote Link to comment Share on other sites More sharing options...