Interface ITime


public interface ITime
Provides methods for thread sleeping and timing operations.

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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default polling rate in milliseconds used when checking conditions.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    sleep(int min, int max)
    Sleeps for a random amount of time within the specified range.
    boolean
    sleep(long ms)
    Sleeps for the specified number of milliseconds.
    default boolean
    Sleeps for one game tick.
    boolean
    sleepTicks(int ticks)
    Sleeps for the specified number of game ticks.
    boolean
    sleepTicksUntil(BooleanSupplier supplier, int ticks)
    Sleeps for the specified number of game ticks or until a condition becomes true.
    default boolean
    sleepUntil(BooleanSupplier supplier, int timeOut)
    Sleeps until the given condition becomes true or timeout is reached.
    default boolean
    sleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut)
    Sleeps until the given condition becomes true or timeout is reached.
    default boolean
    sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut)
    Sleeps until the given condition becomes true or timeout is reached.
    boolean
    sleepUntil(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_RATE
      The 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:
      true if the sleep completed successfully, false if 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 sleep
      max - the maximum amount of milliseconds to sleep
      Returns:
      true if the sleep completed successfully, false if 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 true
      resetSupplier - the condition that resets the timeout timer when true
      pollingRate - the interval in milliseconds between condition checks
      timeOut - the maximum time in milliseconds to wait before timing out
      Returns:
      true if the condition became true before timeout, false if timed out, interrupted, or called on client thread
    • sleepUntil

      default boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut)
      Sleeps until the given condition becomes true or timeout is reached.

      Uses the DEFAULT_POLLING_RATE for 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 true
      resetSupplier - the condition that resets the timeout timer when true
      timeOut - the maximum time in milliseconds to wait before timing out
      Returns:
      true if the condition became true before timeout, false if timed out, interrupted, or called on client thread
    • sleepUntil

      default boolean sleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut)
      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 true
      pollingRate - the interval in milliseconds between condition checks
      timeOut - the maximum time in milliseconds to wait before timing out
      Returns:
      true if the condition became true before timeout, false if timed out, interrupted, or called on client thread
    • sleepUntil

      default boolean sleepUntil(BooleanSupplier supplier, int timeOut)
      Sleeps until the given condition becomes true or timeout is reached.

      Uses the DEFAULT_POLLING_RATE for 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 true
      timeOut - the maximum time in milliseconds to wait before timing out
      Returns:
      true if the condition became true before timeout, false if 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:
      true if the sleep completed successfully, false if 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:
      true if the sleep completed successfully, false if interrupted, called on client thread, or on login screen
    • sleepTicksUntil

      boolean sleepTicksUntil(BooleanSupplier supplier, int ticks)
      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 true
      ticks - the maximum number of game ticks to sleep
      Returns:
      true if the sleep completed (either by condition or tick count), false if interrupted, called on client thread, or on login screen