Class MethodProvider


  • public class MethodProvider
    extends java.lang.Object
    The `MethodProvider` class provides various static methods for time-related operations, sleeping, and checking conditions.
    • Constructor Summary

      Constructors 
      Constructor Description
      MethodProvider()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String format​(long timePeriod)
      Formats the given time period in milliseconds into a string representation of hours, minutes, and seconds.
      static java.lang.String format​(java.time.Duration duration)
      Formats a Duration object into a String representation.
      static void sleep​(double time)
      Sleeps the current thread for the specified time.
      static void sleep​(int time)
      Causes the current thread to sleep for the specified amount of time.
      static void sleep​(int min, int max)
      Sleeps for a random duration between the given minimum and maximum values (in milliseconds).
      static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout)
      Sleeps until the given condition is true or the timeout is reached.
      static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout, int polling)
      Sleeps until the given condition returns true, up to the given timeout, while checking the condition at the specified polling interval.
      static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, int min, int max, int timeout)
      Sleeps until a given condition is met within a specified time range.
      static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, java.util.function.Supplier<java.lang.Boolean> resetCondition, int timeout)
      Sleeps until the given condition is met or the timeout is reached.
      static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, java.util.function.Supplier<java.lang.Boolean> resetCondition, int timeout, int polling)
      Sleeps until the condition is met or the timeout is reached, and returns true if the condition is met.
      static boolean sleepUntilAllowLoggedOut​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout)  
      static boolean sleepUntilAllowLoggedOut​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout, int polling)  
      static boolean sleepUntilAllowLoggedOut​(java.util.function.Supplier<java.lang.Boolean> condition, int min, int max, int timeout)  
      static boolean sleepUntilWhileAnimating​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout)  
      static boolean sleepUntilWhileAnimating​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout, int polling)
      Sleeps until the specified condition is met or the timeout is reached, while checking for animation every polling milliseconds.
      static boolean sleepUntilWhileAnimating​(java.util.function.Supplier<java.lang.Boolean> condition, int min, int max, int timeout)  
      static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout)
      Sleeps while the given condition is true, up to the specified timeout.
      static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition, int timeout, int polling)
      Sleeps while the condition supplied by the supplier is true, for a specified timeout and polling interval.
      static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition, int min, int max, int timeout)  
      static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition, java.util.function.Supplier<java.lang.Boolean> resetCondition, int timeout)  
      static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition, java.util.function.Supplier<java.lang.Boolean> resetCondition, int timeout, int polling)
      Sleeps while the specified condition is true and the timeout has not been exceeded.
      static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition, java.util.function.Supplier<java.lang.Boolean> resetCondition, int min, int max, int timeout)  
      static void tickSleep​(int ticks)
      Sleeps until a specified number of ticks have passed
      static void tickSleep​(int ticks, int polling)
      Sleeps for a certain amount of time until the game tick count reaches the specified value.
      static boolean tickSleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, int tickTimeout)
      Pauses execution until a certain condition is met or a timeout occurs.
      static boolean tickSleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition, java.util.function.Supplier<java.lang.Boolean> resetCondition, long tickTimeout)
      Pauses execution until a certain condition is met or a timeout occurs, while checking for a reset condition.
      static long timeFromMark​(long start)
      Calculates the time elapsed from a given start time in milliseconds.
      • Methods inherited from class java.lang.Object

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

      • MethodProvider

        public MethodProvider()
    • Method Detail

      • timeFromMark

        public static long timeFromMark​(long start)
        Calculates the time elapsed from a given start time in milliseconds.
        Parameters:
        start - the start time in milliseconds
        Returns:
        the time elapsed in milliseconds
      • format

        public static java.lang.String format​(long timePeriod)
        Formats the given time period in milliseconds into a string representation of hours, minutes, and seconds.
        Parameters:
        timePeriod - the time period in milliseconds to be formatted
        Returns:
        the formatted string in the format "hh:mm:ss"
      • format

        public static java.lang.String format​(java.time.Duration duration)
        Formats a Duration object into a String representation.
        Parameters:
        duration - the Duration object to be formatted
        Returns:
        the formatted String representation of the Duration
      • sleep

        public static void sleep​(int time)
        Causes the current thread to sleep for the specified amount of time.
        Parameters:
        time - the duration in milliseconds to sleep
      • sleep

        public static void sleep​(double time)
        Sleeps the current thread for the specified time.
        Parameters:
        time - the duration to sleep in milliseconds
      • sleep

        public static void sleep​(int min,
                                 int max)
        Sleeps for a random duration between the given minimum and maximum values (in milliseconds).
        Parameters:
        min - the minimum duration in milliseconds
        max - the maximum duration in milliseconds
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         int timeout)
        Sleeps until the given condition is true or the timeout is reached.
        Parameters:
        condition - the condition to check
        timeout - the maximum time to wait in milliseconds
        Returns:
        true if the condition became true before the timeout, false otherwise
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         int min,
                                         int max,
                                         int timeout)
        Sleeps until a given condition is met within a specified time range.
        Parameters:
        condition - the condition to check
        min - the minimum sleep duration in milliseconds
        max - the maximum sleep duration in milliseconds
        timeout - the timeout duration in milliseconds
        Returns:
        true if the condition is met within the timeout, false otherwise
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         int timeout,
                                         int polling)
        Sleeps until the given condition returns true, up to the given timeout, while checking the condition at the specified polling interval.
        Parameters:
        condition - a supplier that checks the condition to determine if the sleep should continue
        timeout - the maximum time to sleep in milliseconds
        polling - the interval at which to check the condition in milliseconds
        Returns:
        true if the condition becomes true within the specified timeout, false otherwise
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         java.util.function.Supplier<java.lang.Boolean> resetCondition,
                                         int timeout,
                                         int polling)
        Sleeps until the condition is met or the timeout is reached, and returns true if the condition is met.
        Parameters:
        condition - a Supplier representing the condition to be met.
        resetCondition - a Supplier representing the condition to reset the start time.
        timeout - the maximum time in milliseconds to wait for the condition to be met.
        polling - the time in milliseconds between checks for the condition.
        Returns:
        true if the condition is met before the timeout, false otherwise.
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         java.util.function.Supplier<java.lang.Boolean> resetCondition,
                                         int timeout)
        Sleeps until the given condition is met or the timeout is reached.
        Parameters:
        condition - a supplier that provides a boolean value to determine the condition
        resetCondition - a supplier that provides a boolean value to reset the start time
        timeout - the maximum time to wait in milliseconds
        Returns:
        true if the condition is met before the timeout, false otherwise
      • sleepWhile

        public static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         int timeout)
        Sleeps while the given condition is true, up to the specified timeout.
        Parameters:
        condition - a supplier that evaluates the condition
        timeout - the maximum time to sleep (in milliseconds)
        Returns:
        true if the condition was false within the timeout, false otherwise
      • sleepWhile

        public static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         int min,
                                         int max,
                                         int timeout)
      • sleepWhile

        public static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         int timeout,
                                         int polling)
        Sleeps while the condition supplied by the supplier is true, for a specified timeout and polling interval.
        Parameters:
        condition - a Supplier representing the condition to check.
        timeout - the maximum time to sleep for.
        polling - the interval between checking the condition.
        Returns:
        true if the condition becomes false within the given timeout, false otherwise.
      • sleepWhile

        public static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         java.util.function.Supplier<java.lang.Boolean> resetCondition,
                                         int timeout)
      • sleepWhile

        public static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         java.util.function.Supplier<java.lang.Boolean> resetCondition,
                                         int min,
                                         int max,
                                         int timeout)
      • sleepWhile

        public static boolean sleepWhile​(java.util.function.Supplier<java.lang.Boolean> condition,
                                         java.util.function.Supplier<java.lang.Boolean> resetCondition,
                                         int timeout,
                                         int polling)
        Sleeps while the specified condition is true and the timeout has not been exceeded.
        Parameters:
        condition - the condition to be checked
        resetCondition - the condition to reset the start time
        timeout - the maximum time to wait in milliseconds
        polling - the time between checks in milliseconds
        Returns:
        true if the condition became false before the timeout, false otherwise
      • sleepUntilWhileAnimating

        public static boolean sleepUntilWhileAnimating​(java.util.function.Supplier<java.lang.Boolean> condition,
                                                       int timeout)
      • sleepUntilWhileAnimating

        public static boolean sleepUntilWhileAnimating​(java.util.function.Supplier<java.lang.Boolean> condition,
                                                       int min,
                                                       int max,
                                                       int timeout)
      • sleepUntilWhileAnimating

        public static boolean sleepUntilWhileAnimating​(java.util.function.Supplier<java.lang.Boolean> condition,
                                                       int timeout,
                                                       int polling)
        Sleeps until the specified condition is met or the timeout is reached, while checking for animation every polling milliseconds.
        Parameters:
        condition - the condition to be met for the method to return true
        timeout - the maximum time to wait for the condition to be met, in milliseconds
        polling - the interval in milliseconds to check for animation while waiting
        Returns:
        true if the condition is met, false if timeout is reached or the current thread is the RSClient's client thread
      • sleepUntilAllowLoggedOut

        public static boolean sleepUntilAllowLoggedOut​(java.util.function.Supplier<java.lang.Boolean> condition,
                                                       int timeout)
      • sleepUntilAllowLoggedOut

        public static boolean sleepUntilAllowLoggedOut​(java.util.function.Supplier<java.lang.Boolean> condition,
                                                       int min,
                                                       int max,
                                                       int timeout)
      • sleepUntilAllowLoggedOut

        public static boolean sleepUntilAllowLoggedOut​(java.util.function.Supplier<java.lang.Boolean> condition,
                                                       int timeout,
                                                       int polling)
      • tickSleep

        public static void tickSleep​(int ticks)
        Sleeps until a specified number of ticks have passed
        Parameters:
        ticks - the number of ticks
      • tickSleep

        public static void tickSleep​(int ticks,
                                     int polling)
        Sleeps for a certain amount of time until the game tick count reaches the specified value.
        Parameters:
        ticks - the number of ticks to sleep for
        polling - the time in milliseconds to wait between each poll
      • tickSleepUntil

        public static boolean tickSleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                             int tickTimeout)
        Pauses execution until a certain condition is met or a timeout occurs.
        Parameters:
        condition - the supplier that determines the condition to wait for
        tickTimeout - the maximum number of ticks to wait before timing out
        Returns:
        true if the condition is met before the timeout, false otherwise
      • tickSleepUntil

        public static boolean tickSleepUntil​(java.util.function.Supplier<java.lang.Boolean> condition,
                                             java.util.function.Supplier<java.lang.Boolean> resetCondition,
                                             long tickTimeout)
        Pauses execution until a certain condition is met or a timeout occurs, while checking for a reset condition.
        Parameters:
        condition - the supplier that determines the condition to wait for
        resetCondition - the supplier that determines the condition to reset the start time
        tickTimeout - the maximum number of ticks to wait before timing out
        Returns:
        true if the condition is met before the timeout, false otherwise