Skip to content

Instantly share code, notes, and snippets.

@battleguard
Created October 30, 2014 11:14
Show Gist options
  • Select an option

  • Save battleguard/11db781dfe007ee44c0d to your computer and use it in GitHub Desktop.

Select an option

Save battleguard/11db781dfe007ee44c0d to your computer and use it in GitHub Desktop.
debugging conditions
package org.battleguard.scripts.testscript;
import org.powerbot.script.Condition;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
public class DebugCondition extends Condition {
public static boolean wait(Callable<Boolean> condition, String text) {
return wait(condition, text, 600, 10);
}
public static boolean wait(Callable<Boolean> condition, String text, int frequency) {
return wait(condition, text, frequency, 6000 / frequency);
}
public static boolean wait(final Callable<Boolean> condition, String text, int frequency, int tries) {
final AtomicInteger counter = new AtomicInteger();
final Callable<Boolean> debugCallable = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
counter.incrementAndGet();
return condition.call();
}
};
final long start = System.currentTimeMillis();
final boolean returnValue = wait(debugCallable, frequency, tries);
final long end = System.currentTimeMillis() - start;
System.out.println(text + (returnValue ? " Success" : " Failed") + " (Waited: " +
end + "ms, F: " + frequency + "ms" + ", Condition Calls: " + counter.get() + ");");
return returnValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment