The Hero of Time Posted April 6, 2016 Share Posted April 6, 2016 so basically, i want to put conditionalsleep in a method, so that i dont have to paste all those lines of codes everytime this is what i got. i know it doesn't work, but i was wondering if someone could explain why it doesn't work. This works new ConditionalSleep(7000) { @Override public boolean condition() throws InterruptedException { return ctx.getInventory().getAmount("Plank") > amountOfPlankInInventory; } }.sleep(); This doesn't public void condSleep(int timeout,boolean statement) { new ConditionalSleep(timeout) { @Override public boolean condition() throws InterruptedException { return statement; } }.sleep(); } condSleep(7000,ctx.getInventory().getAmount("Plank") > amountOfPlankInInventory); Quote Link to comment Share on other sites More sharing options...
Xerion Posted April 6, 2016 Share Posted April 6, 2016 Using lambda would make your first method a lot cleaner. For the second method you could change the boolean from the statement to Callable<Boolean>. The thing you are doing wrong is that currently the statement will never change. The value is assigned when the method is called and will never change.Anyway more info here: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html Quote Link to comment Share on other sites More sharing options...
FrostBug Posted April 6, 2016 Share Posted April 6, 2016 (edited) public void condSleep(int timeout,boolean statement) { new ConditionalSleep(timeout) { @Override public boolean condition() throws InterruptedException { return statement; } }.sleep(); } condSleep(7000,ctx.getInventory().getAmount("Plank") > amountOfPlankInInventory); The method receives a boolean 'statement', which is evaluated to either true or false at the time of the method call. It's not going to magically change during the execution of the conditional sleep. So either you sleep the full time, or not at all. Edited April 6, 2016 by FrostBug Quote Link to comment Share on other sites More sharing options...
Botre Posted April 6, 2016 Share Posted April 6, 2016 Use a BooleanSupplier instead of a plain boolean ^^ https://docs.oracle.com/javase/8/docs/api/java/util/function/BooleanSupplier.html Quote Link to comment Share on other sites More sharing options...
DragonAlpha Posted April 6, 2016 Share Posted April 6, 2016 Use a BooleanSupplier instead of a plain boolean ^^ https://docs.oracle.com/javase/8/docs/api/java/util/function/BooleanSupplier.html This. Botre helped me with this yesterday. Quote Link to comment Share on other sites More sharing options...