Interface ITime
This interface defines various sleep methods that can be used to pause execution for specified durations or until certain conditions are met. It supports both millisecond-based and game tick-based timing.
Important: All sleep methods will refuse to execute on the client
thread to prevent hanging the game client. They will return false
if called from the client thread.
Example usage:
// Simple sleep for 1 second
time.sleep(1000);
// Random sleep between 500-1500ms
time.sleep(500, 1500);
// Sleep until inventory is full, with 5 second timeout
time.sleepUntil(() -> Inventory.isFull(), 5000);
// Sleep for 3 game ticks
time.sleepTicks(3);
// Sleep until condition or max 5 ticks
time.sleepTicksUntil(() -> player.isIdle(), 5);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default polling rate in milliseconds used when checking conditions. -
Method Summary
Modifier and TypeMethodDescriptionbooleansleep(int min, int max) Sleeps for a random amount of time within the specified range.booleansleep(long ms) Sleeps for the specified number of milliseconds.default booleanSleeps for one game tick.booleansleepTicks(int ticks) Sleeps for the specified number of game ticks.booleansleepTicksUntil(BooleanSupplier supplier, int ticks) Sleeps for the specified number of game ticks or until a condition becomes true.default booleansleepUntil(BooleanSupplier supplier, int timeOut) Sleeps until the given condition becomes true or timeout is reached.default booleansleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut) Sleeps until the given condition becomes true or timeout is reached.default booleansleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut) Sleeps until the given condition becomes true or timeout is reached.booleansleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut) Sleeps until the given condition becomes true or timeout is reached.
-
Field Details
-
DEFAULT_POLLING_RATE
static final int DEFAULT_POLLING_RATEThe default polling rate in milliseconds used when checking conditions. This determines how frequently the sleep methods check their exit conditions.- See Also:
-
-
Method Details
-
sleep
boolean sleep(long ms) Sleeps for the specified number of milliseconds.This method will not execute on the client thread, as this may hang the client.
- Parameters:
ms- the amount of milliseconds to sleep- Returns:
trueif the sleep completed successfully,falseif interrupted or called on client thread
-
sleep
boolean sleep(int min, int max) Sleeps for a random amount of time within the specified range.The actual sleep duration is randomly selected between min and max (inclusive). This method will not execute on the client thread, as this may hang the client.
- Parameters:
min- the minimum amount of milliseconds to sleepmax- the maximum amount of milliseconds to sleep- Returns:
trueif the sleep completed successfully,falseif interrupted or called on client thread
-
sleepUntil
boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut) Sleeps until the given condition becomes true or timeout is reached.The condition is checked at the specified polling rate. If the reset supplier returns true, the timeout timer is reset. This method will not execute on the client thread, as this may hang the client.
- Parameters:
supplier- the completion condition that ends the sleep when trueresetSupplier- the condition that resets the timeout timer when truepollingRate- the interval in milliseconds between condition checkstimeOut- the maximum time in milliseconds to wait before timing out- Returns:
trueif the condition became true before timeout,falseif timed out, interrupted, or called on client thread
-
sleepUntil
Sleeps until the given condition becomes true or timeout is reached.Uses the
DEFAULT_POLLING_RATEfor condition checking. This method will not execute on the client thread, as this may hang the client.- Parameters:
supplier- the completion condition that ends the sleep when trueresetSupplier- the condition that resets the timeout timer when truetimeOut- the maximum time in milliseconds to wait before timing out- Returns:
trueif the condition became true before timeout,falseif timed out, interrupted, or called on client thread
-
sleepUntil
Sleeps until the given condition becomes true or timeout is reached.This method will not execute on the client thread, as this may hang the client.
- Parameters:
supplier- the completion condition that ends the sleep when truepollingRate- the interval in milliseconds between condition checkstimeOut- the maximum time in milliseconds to wait before timing out- Returns:
trueif the condition became true before timeout,falseif timed out, interrupted, or called on client thread
-
sleepUntil
Sleeps until the given condition becomes true or timeout is reached.Uses the
DEFAULT_POLLING_RATEfor condition checking. This method will not execute on the client thread, as this may hang the client.- Parameters:
supplier- the completion condition that ends the sleep when truetimeOut- the maximum time in milliseconds to wait before timing out- Returns:
trueif the condition became true before timeout,falseif timed out, interrupted, or called on client thread
-
sleepTicks
boolean sleepTicks(int ticks) Sleeps for the specified number of game ticks.A game tick is approximately 600 milliseconds. This method will not execute on the client thread, as this may hang the client. It will also return false if called while on the login screen.
- Parameters:
ticks- the number of game ticks to sleep- Returns:
trueif the sleep completed successfully,falseif interrupted, called on client thread, or on login screen
-
sleepTick
default boolean sleepTick()Sleeps for one game tick.This is a convenience method equivalent to calling
sleepTicks(1). A game tick is approximately 600 milliseconds. This method will not execute on the client thread, as this may hang the client.- Returns:
trueif the sleep completed successfully,falseif interrupted, called on client thread, or on login screen
-
sleepTicksUntil
Sleeps for the specified number of game ticks or until a condition becomes true.The sleep ends early if the supplier condition returns true before the specified number of ticks have elapsed. This method will not execute on the client thread, as this may hang the client.
- Parameters:
supplier- the break condition that ends the sleep early when trueticks- the maximum number of game ticks to sleep- Returns:
trueif the sleep completed (either by condition or tick count),falseif interrupted, called on client thread, or on login screen
-