Use this:
public boolean sleeped(String text, int timeout, BooleanSupplier condition) {
return new ConditionalSleep(timeout) {
@Override
public boolean condition() throws InterruptedException {
return condition.getAsBoolean();
}
}.sleep();
}
and in your script:
if (getBank().isOpen()) {
log("Bank is currently open");
return random(800, 1400);
}
log("Attempting to open bank...");
if (!getBank().open()) {
log("...didn't open bank, try again...");
return random(800, 1400);
}
boolean didSucceed = sleeped("Wait up to 10s for bank to open", 10000, () -> getBank().isOpen();
if (!didSucceed) {
log("Waited the whole 10 seconds and bank didn't open...");
return 600;
}
log("Bank successfully opened");
return 600;