Class SleepService


  • @Singleton
    public class SleepService
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      SleepService()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void sleep​(int duration)
      Sleeps for a specified amount of time in milliseconds.
      static void sleep​(int start, int end)
      Sleeps for a random duration between start and end milliseconds.
      static void sleep​(long time)
      Sleeps for a specified amount of time in milliseconds.
      static void sleep​(long start, long end)
      Sleeps for a random duration between start and end milliseconds.
      static void sleepFor​(int ticks)
      Sleeps the current thread by the specified number of game ticks
      static void sleepGaussian​(int mean, int stddev)
      Sleeps for a duration based on a Gaussian distribution.
      static boolean sleepUntil​(java.util.function.BooleanSupplier awaitedCondition)
      Waits until the specified condition is true, with a default timeout of 5000ms.
      static boolean sleepUntil​(java.util.function.BooleanSupplier awaitedCondition, int time)
      Waits until the specified condition is true, or a timeout is reached.
      static void sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition)
      Waits until the specified condition is true.
      static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, int ticks)
      sleeps until the specified condition is true or the timeout is reached.
      static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, long timeoutMS)
      sleeps until the specified condition is true or the timeout is reached.
      static void sleepUntilIdle()
      Sleeps until the local player's animation is idle.
      static <T> T sleepUntilNotNull​(java.util.concurrent.Callable<T> method, int timeoutMillis)
      Repeatedly calls a method until it returns a non-null value, or a timeout is reached.
      static <T> T sleepUntilNotNull​(java.util.concurrent.Callable<T> method, int timeoutMillis, int sleepMillis)
      Repeatedly calls a method until it returns a non-null value, or a timeout is reached.
      static void sleepUntilTile​(int worldX, int worldY)
      Sleeps until the local player reaches the specified world tile.
      static boolean sleepUntilTrue​(java.util.function.BooleanSupplier awaitedCondition, int timeout)
      Waits until the specified condition is true, checking every 100ms, until a timeout is reached.
      static boolean sleepUntilTrue​(java.util.function.BooleanSupplier awaitedCondition, int time, int timeout)
      Waits until the specified condition is true, checking at a given interval, until a timeout is reached.
      static boolean sleepWhile​(java.util.function.BooleanSupplier condition, int timeout)
      Sleeps while the specified condition is true or until the timeout is reached.
      static void tick()
      Sleeps the current thread for one game tick
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SleepService

        public SleepService()
    • Method Detail

      • sleepUntil

        public static void sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition)
        Waits until the specified condition is true.
        Parameters:
        condition - the condition to be met
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         long timeoutMS)
        sleeps until the specified condition is true or the timeout is reached.
        Parameters:
        condition - the condition to be met
        timeoutMS - the maximum time to sleep in milliseconds
        Returns:
        true if the condition was met, false if the timeout was reached
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         int ticks)
        sleeps until the specified condition is true or the timeout is reached.
        Parameters:
        condition - the condition to be met
        ticks - the maximum time to sleep in game ticks
        Returns:
        true if the condition was met, false if the timeout was reached
      • sleepUntilIdle

        public static void sleepUntilIdle()
        Sleeps until the local player's animation is idle.
      • sleepUntilTile

        public static void sleepUntilTile​(int worldX,
                                          int worldY)
        Sleeps until the local player reaches the specified world tile.
        Parameters:
        worldX - the x-coordinate of the target tile
        worldY - the y-coordinate of the target tile
      • sleep

        public static void sleep​(int duration)
        Sleeps for a specified amount of time in milliseconds. This sleep is interruptible by script cancellation.
        Parameters:
        duration - the duration to sleep in milliseconds
      • sleep

        public static void sleep​(long time)
        Sleeps for a specified amount of time in milliseconds. This sleep is interruptible by script cancellation.
        Parameters:
        time - the duration to sleep in milliseconds
      • sleep

        public static void sleep​(long start,
                                 long end)
        Sleeps for a random duration between start and end milliseconds.
        Parameters:
        start - the minimum sleep time
        end - the maximum sleep time
      • sleep

        public static void sleep​(int start,
                                 int end)
        Sleeps for a random duration between start and end milliseconds.
        Parameters:
        start - the minimum sleep time
        end - the maximum sleep time
      • sleepGaussian

        public static void sleepGaussian​(int mean,
                                         int stddev)
        Sleeps for a duration based on a Gaussian distribution.
        Parameters:
        mean - the mean sleep time
        stddev - the standard deviation of the sleep time
      • sleepUntilNotNull

        public static <T> T sleepUntilNotNull​(java.util.concurrent.Callable<T> method,
                                              int timeoutMillis,
                                              int sleepMillis)
        Repeatedly calls a method until it returns a non-null value, or a timeout is reached.
        Type Parameters:
        T - the return type of the method
        Parameters:
        method - the method to call
        timeoutMillis - the maximum time to wait in milliseconds
        sleepMillis - the time to sleep between calls
        Returns:
        the non-null value, or null if the timeout was reached
      • sleepUntilNotNull

        public static <T> T sleepUntilNotNull​(java.util.concurrent.Callable<T> method,
                                              int timeoutMillis)
        Repeatedly calls a method until it returns a non-null value, or a timeout is reached. Sleeps 100ms between calls.
        Type Parameters:
        T - the return type of the method
        Parameters:
        method - the method to call
        timeoutMillis - the maximum time to wait in milliseconds
        Returns:
        the non-null value, or null if the timeout was reached
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.BooleanSupplier awaitedCondition)
        Waits until the specified condition is true, with a default timeout of 5000ms.
        Parameters:
        awaitedCondition - the condition to be met
        Returns:
        true if the condition was met, false if the timeout was reached
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.BooleanSupplier awaitedCondition,
                                         int time)
        Waits until the specified condition is true, or a timeout is reached.
        Parameters:
        awaitedCondition - the condition to be met
        time - the maximum time to wait in milliseconds
        Returns:
        true if the condition was met, false if the timeout was reached
      • tick

        public static void tick()
        Sleeps the current thread for one game tick
      • sleepFor

        public static void sleepFor​(int ticks)
        Sleeps the current thread by the specified number of game ticks
        Parameters:
        ticks - ticks
      • sleepUntilTrue

        public static boolean sleepUntilTrue​(java.util.function.BooleanSupplier awaitedCondition,
                                             int time,
                                             int timeout)
        Waits until the specified condition is true, checking at a given interval, until a timeout is reached.
        Parameters:
        awaitedCondition - the condition to be met
        time - the time to sleep between checks in milliseconds
        timeout - the maximum time to wait in milliseconds
        Returns:
        true if the condition was met, false if the timeout was reached
      • sleepUntilTrue

        public static boolean sleepUntilTrue​(java.util.function.BooleanSupplier awaitedCondition,
                                             int timeout)
        Waits until the specified condition is true, checking every 100ms, until a timeout is reached.
        Parameters:
        awaitedCondition - the condition to be met
        timeout - the maximum time to wait in milliseconds
        Returns:
        true if the condition was met, false if the timeout was reached
      • sleepWhile

        public static boolean sleepWhile​(java.util.function.BooleanSupplier condition,
                                         int timeout)
        Sleeps while the specified condition is true or until the timeout is reached.
        Parameters:
        condition - the condition to be met
        timeout - the maximum time to sleep in milliseconds
        Returns:
        true if the condition became false, false if the timeout was reached