Class Time

java.lang.Object
net.storm.sdk.commons.Time

public class Time extends Object
A utility class for all time-related operations such as sleeping and waiting.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(Duration duration)
    Formats a duration into a human-readable HH:MM:SS string.
    static boolean
    sleep(int min, int max)
    Sleeps for a random amount of time between a given range.
    static boolean
    sleep(long ms)
    Sleeps for the specified duration in milliseconds.
    static boolean
    Sleeps for one game tick (approximately 600 milliseconds).
    static boolean
    sleepTicks(int ticks)
    Sleeps for the specified number of game ticks.
    static boolean
    sleepTicksUntil(BooleanSupplier supplier, int ticks)
    Sleeps for up to the specified number of ticks, or until a condition is true.
    static boolean
    sleepUntil(BooleanSupplier supplier, int timeOut)
    Sleeps until the given condition is true with default polling rate.
    static boolean
    sleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut)
    Sleeps until the given condition is true.
    static boolean
    sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut)
    Sleeps until the given condition is true, with reset capability and default polling rate.
    static boolean
    sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut)
    Sleeps until the given condition is true, with reset capability.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      true if the sleep was successful, false if 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 sleep
      max - the maximum amount of milliseconds to sleep
      Returns:
      true if the sleep was successful, false if 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 true
      resetSupplier - the condition that resets the timeout timer when true
      pollingRate - the interval in milliseconds to check conditions
      timeOut - the maximum time to wait in milliseconds
      Returns:
      true if the condition was met, false if 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 true
      resetSupplier - the condition that resets the timeout timer when true
      timeOut - the maximum time to wait in milliseconds
      Returns:
      true if the condition was met, false if timeout occurred
    • sleepUntil

      public static boolean sleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut)
      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 true
      pollingRate - the interval in milliseconds to check the condition
      timeOut - the maximum time to wait in milliseconds
      Returns:
      true if the condition was met, false if timeout occurred
    • sleepUntil

      public static boolean sleepUntil(BooleanSupplier supplier, int timeOut)
      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 true
      timeOut - the maximum time to wait in milliseconds
      Returns:
      true if the condition was met, false if 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:
      true if the sleep was successful, false if 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:
      true if the sleep was successful, false if interrupted
    • sleepTicksUntil

      public static boolean sleepTicksUntil(BooleanSupplier supplier, int ticks)
      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 true
      ticks - the maximum number of ticks to sleep
      Returns:
      true if the condition was met, false if timeout occurred
    • format

      public static String format(Duration duration)
      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