Package com.kraken.api.service.util
Class SleepService
- java.lang.Object
-
- com.kraken.api.service.util.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 voidsleep(int duration)Sleeps for a specified amount of time in milliseconds.static voidsleep(int start, int end)Sleeps for a random duration between start and end milliseconds.static voidsleep(long time)Sleeps for a specified amount of time in milliseconds.static voidsleep(long start, long end)Sleeps for a random duration between start and end milliseconds.static voidsleepFor(int ticks)Sleeps the current thread by the specified number of game ticksstatic voidsleepGaussian(int mean, int stddev)Sleeps for a duration based on a Gaussian distribution.static booleansleepUntil(java.util.function.BooleanSupplier awaitedCondition)Waits until the specified condition is true, with a default timeout of 5000ms.static booleansleepUntil(java.util.function.BooleanSupplier awaitedCondition, int time)Waits until the specified condition is true, or a timeout is reached.static voidsleepUntil(java.util.function.Supplier<java.lang.Boolean> condition)Waits until the specified condition is true.static booleansleepUntil(java.util.function.Supplier<java.lang.Boolean> condition, int ticks)sleeps until the specified condition is true or the timeout is reached.static booleansleepUntil(java.util.function.Supplier<java.lang.Boolean> condition, long timeoutMS)sleeps until the specified condition is true or the timeout is reached.static voidsleepUntilIdle()Sleeps until the local player's animation is idle.static <T> TsleepUntilNotNull(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> TsleepUntilNotNull(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 voidsleepUntilTile(int worldX, int worldY)Sleeps until the local player reaches the specified world tile.static booleansleepUntilTrue(java.util.function.BooleanSupplier awaitedCondition, int timeout)Waits until the specified condition is true, checking every 100ms, until a timeout is reached.static booleansleepUntilTrue(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 booleansleepWhile(java.util.function.BooleanSupplier condition, int timeout)Sleeps while the specified condition is true or until the timeout is reached.static voidtick()Sleeps the current thread for one game tick
-
-
-
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 mettimeoutMS- 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 metticks- 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 tileworldY- 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 timeend- 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 timeend- 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 timestddev- 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 calltimeoutMillis- the maximum time to wait in millisecondssleepMillis- 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 calltimeoutMillis- 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 mettime- 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 mettime- the time to sleep between checks in millisecondstimeout- 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 mettimeout- 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 mettimeout- the maximum time to sleep in milliseconds- Returns:
- true if the condition became false, false if the timeout was reached
-
-