Package net.eternalclient.api.utilities
Class MethodProvider
- java.lang.Object
-
- net.eternalclient.api.utilities.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 passedstatic 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.
-
-
-
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 millisecondsmax
- 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 checktimeout
- 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 checkmin
- the minimum sleep duration in millisecondsmax
- the maximum sleep duration in millisecondstimeout
- 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 continuetimeout
- the maximum time to sleep in millisecondspolling
- 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 conditionresetCondition
- a supplier that provides a boolean value to reset the start timetimeout
- 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 conditiontimeout
- 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 checkedresetCondition
- the condition to reset the start timetimeout
- the maximum time to wait in millisecondspolling
- 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 truetimeout
- the maximum time to wait for the condition to be met, in millisecondspolling
- 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 forpolling
- 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 fortickTimeout
- 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 forresetCondition
- the supplier that determines the condition to reset the start timetickTimeout
- the maximum number of ticks to wait before timing out- Returns:
- true if the condition is met before the timeout, false otherwise
-
-