April 6, 20169 yr 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);
April 6, 20169 yr 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
April 6, 20169 yr 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, 20169 yr by FrostBug
April 6, 20169 yr Use a BooleanSupplier instead of a plain boolean ^^ https://docs.oracle.com/javase/8/docs/api/java/util/function/BooleanSupplier.html
April 6, 20169 yr 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.
Create an account or sign in to comment