Class Time

java.lang.Object
privbot.context.Time

public final class Time extends Object
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 Details

    • sleep

      public static boolean sleep(long ms)
      Sleeps the calling (script) thread for ms milliseconds.
      Returns:
      true after a full sleep; false without sleeping when called on the client thread or when the thread is already interrupted, and false when 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 as sleep(long).
    • sleepUntil

      public static boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int pollingRate, int timeOut)
      Polls supplier until it returns true or timeOut ms pass.

      Each poll of supplier and resetSupplier runs through GameThread.ensure(java.util.function.Supplier), so the conditions may read the client directly. A poll that cannot be served counts as "not yet". When resetSupplier returns true the timeout restarts from that moment (for example while the player is still moving toward the target).

      Parameters:
      pollingRate - milliseconds between polls
      timeOut - milliseconds before giving up, measured from the start or the last reset
      Returns:
      true once the condition holds; false on timeout, on interrupt, or immediately when called on the client thread
    • sleepUntil

      public static boolean sleepUntil(BooleanSupplier supplier, BooleanSupplier resetSupplier, int timeOut)
    • sleepUntil

      public static boolean sleepUntil(BooleanSupplier supplier, int pollingRate, int timeOut)
    • sleepUntil

      public static boolean sleepUntil(BooleanSupplier supplier, int timeOut)
      Polls supplier every 10 ms until it is true or timeOut ms pass. Returns false on timeout, interrupt, or when called on the client thread.
    • sleepWhile

      public static boolean sleepWhile(BooleanSupplier supplier, int timeOut)
      Polls every 10 ms while supplier is true. Returns true once it turns false; false on timeout, interrupt, or when called on the client thread.
    • sleepWhile

      public static boolean sleepWhile(BooleanSupplier supplier, int pollingRate, int timeOut)
      sleepWhile(BooleanSupplier, int) with a custom polling interval in milliseconds.
    • sleepTicks

      public static boolean sleepTicks(int ticks)
      Waits for ticks game ticks by watching the client's tick count. There is no overall timeout: a client that stops ticking holds the caller here.
      Returns:
      true after the ticks; false when called on the client thread, when GameThread has no client, or on interrupt. A tick-count read that cannot be served before the first poll returns false; one that fails later counts as the tick having passed.
    • sleepTick

      public static boolean sleepTick()
      Waits for one game tick; see sleepTicks(int).
    • sleepTicksUntil

      public static boolean sleepTicksUntil(BooleanSupplier supplier, int ticks)
      Checks supplier once per game tick, for at most ticks ticks. The condition is read through GameThread.ensure(java.util.function.Supplier).
      Returns:
      true as soon as the condition holds; false when it never did, on interrupt, or when called on the client thread
    • format

      public static String format(Duration duration)
      Formats a duration as HH:mm:ss (absolute value; hours are not capped at 24).