Class Time
This class provides various methods for pausing execution, including:
- Fixed-duration sleeps
- Random-range sleeps
- Conditional sleeps with timeout
- Tick-based sleeps (game tick synchronization)
Important: Sleep methods will not execute on the client thread to prevent hanging the game client. Always use these methods from a separate thread.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringFormats a duration into a human-readable HH:MM:SS string.static booleansleep(int min, int max) Sleeps for a random amount of time between a given range.static booleansleep(long ms) Sleeps for the specified duration in milliseconds.static booleanSleeps for one game tick (approximately 600 milliseconds).static booleansleepTicks(int ticks) Sleeps for the specified number of game ticks.static booleansleepTicksUntil(BooleanSupplier supplier, int ticks) Sleeps for up to the specified number of ticks, or until a condition is true.static booleansleepUntil(BooleanSupplier supplier, int timeOut) Sleeps until the given condition is true with default polling rate.static booleansleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut) Sleeps until the given condition is true.static booleansleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut) Sleeps until the given condition is true, with reset capability and default polling rate.static booleansleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut) Sleeps until the given condition is true, with reset capability.
-
Constructor Details
-
Time
public Time()
-
-
Method Details
-
sleep
public static boolean sleep(long ms) Sleeps for the specified duration in milliseconds.Sleep 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 was successful,falseif interrupted
-
sleep
public static boolean sleep(int min, int max) Sleeps for a random amount of time between a given range.Sleep 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 was successful,falseif interrupted
-
sleepUntil
public static boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut) Sleeps until the given condition is true, with reset capability.Sleep 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 to check conditionstimeOut- the maximum time to wait in milliseconds- Returns:
trueif the condition was met,falseif timeout occurred
-
sleepUntil
public static boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut) Sleeps until the given condition is true, with reset capability and default polling rate.Sleep 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 to wait in milliseconds- Returns:
trueif the condition was met,falseif timeout occurred
-
sleepUntil
Sleeps until the given condition is true.Sleep 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 to check the conditiontimeOut- the maximum time to wait in milliseconds- Returns:
trueif the condition was met,falseif timeout occurred
-
sleepUntil
Sleeps until the given condition is true with default polling rate.Sleep 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 to wait in milliseconds- Returns:
trueif the condition was met,falseif timeout occurred
-
sleepTicks
public static boolean sleepTicks(int ticks) Sleeps for the specified number of game ticks.A game tick is approximately 600 milliseconds. Sleep will not execute on the client thread, as this may hang the client.
- Parameters:
ticks- the number of game ticks to sleep- Returns:
trueif the sleep was successful,falseif interrupted
-
sleepTick
public static boolean sleepTick()Sleeps for one game tick (approximately 600 milliseconds).Sleep will not execute on the client thread, as this may hang the client.
- Returns:
trueif the sleep was successful,falseif interrupted
-
sleepTicksUntil
Sleeps for up to the specified number of ticks, or until a condition is true.This is useful for waiting for an action to complete with a tick-based timeout.
- Parameters:
supplier- the break condition that ends the sleep when trueticks- the maximum number of ticks to sleep- Returns:
trueif the condition was met,falseif timeout occurred
-
format
Formats a duration into a human-readable HH:MM:SS string.- Parameters:
duration- the duration value to format- Returns:
- a formatted string in HH:MM:SS format
-