Class Time
java.lang.Object
privbot.context.Time
Script-thread sleep utilities — matching the Unethicalite
Time /
DreamBot Sleep API.
All blocking methods refuse to run on the client thread and return
false if called there, preventing accidental game freezes.
Usage in nodes:
Time.sleep(100, 200);
Time.sleepUntil(() -> !ctx.lobby.rewardChestAvailable(), 4000);
Time.sleepTicks(2);
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringFormats a duration asHH:mm:ss(absolute value; hours are not capped at 24).static booleansleep(int min, int max) Sleeps for a uniformly random duration in[min, max]milliseconds.static booleansleep(long ms) Sleeps the calling (script) thread formsmilliseconds.static booleanWaits for one game tick; seesleepTicks(int).static booleansleepTicks(int ticks) Waits forticksgame ticks by watching the client's tick count.static booleansleepTicksUntil(BooleanSupplier supplier, int ticks) Checkssupplieronce per game tick, for at mostticksticks.static booleansleepUntil(BooleanSupplier supplier, int timeOut) Pollssupplierevery 10 ms until it istrueortimeOutms pass.static booleansleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut) sleepUntil(BooleanSupplier, BooleanSupplier, int, int)with no reset condition.static booleansleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut) sleepUntil(BooleanSupplier, BooleanSupplier, int, int)polling every 10 ms.static booleansleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut) Pollssupplieruntil it returnstrueortimeOutms pass.static booleansleepWhile(BooleanSupplier supplier, int timeOut) Polls every 10 ms whilesupplieristrue.static booleansleepWhile(BooleanSupplier supplier, int pollingRate, int timeOut) sleepWhile(BooleanSupplier, int)with a custom polling interval in milliseconds.
-
Method Details
-
sleep
public static boolean sleep(long ms) Sleeps the calling (script) thread formsmilliseconds.- Returns:
trueafter a full sleep;falsewithout sleeping when called on the client thread or when the thread is already interrupted, andfalsewhen interrupted mid-sleep (the interrupt flag is restored, so the caller should unwind)
-
sleep
public static boolean sleep(int min, int max) Sleeps for a uniformly random duration in[min, max]milliseconds. Same return contract assleep(long). -
sleepUntil
public static boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut) Pollssupplieruntil it returnstrueortimeOutms pass.Each poll of
supplierandresetSupplierruns throughGameThread.ensure(java.util.function.Supplier), so the conditions may read the client directly. A poll that cannot be served counts as "not yet". WhenresetSupplierreturnstruethe timeout restarts from that moment (for example while the player is still moving toward the target).- Parameters:
pollingRate- milliseconds between pollstimeOut- milliseconds before giving up, measured from the start or the last reset- Returns:
trueonce the condition holds;falseon timeout, on interrupt, or immediately when called on the client thread
-
sleepUntil
public static boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut) sleepUntil(BooleanSupplier, BooleanSupplier, int, int)polling every 10 ms. -
sleepUntil
sleepUntil(BooleanSupplier, BooleanSupplier, int, int)with no reset condition. -
sleepUntil
Pollssupplierevery 10 ms until it istrueortimeOutms pass. Returnsfalseon timeout, interrupt, or when called on the client thread. -
sleepWhile
Polls every 10 ms whilesupplieristrue. Returnstrueonce it turnsfalse;falseon timeout, interrupt, or when called on the client thread. -
sleepWhile
sleepWhile(BooleanSupplier, int)with a custom polling interval in milliseconds. -
sleepTicks
public static boolean sleepTicks(int ticks) Waits forticksgame ticks by watching the client's tick count. There is no overall timeout: a client that stops ticking holds the caller here.- Returns:
trueafter the ticks;falsewhen called on the client thread, whenGameThreadhas no client, or on interrupt. A tick-count read that cannot be served before the first poll returnsfalse; one that fails later counts as the tick having passed.
-
sleepTick
public static boolean sleepTick()Waits for one game tick; seesleepTicks(int). -
sleepTicksUntil
Checkssupplieronce per game tick, for at mostticksticks. The condition is read throughGameThread.ensure(java.util.function.Supplier).- Returns:
trueas soon as the condition holds;falsewhen it never did, on interrupt, or when called on the client thread
-
format
-