mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Moved conditional sleep method, depracted Script#sleep(SleepCondition,
int)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
import org.parabot.environment.scripts.framework.SleepCondition;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds various Time utilities
|
||||
@@ -7,7 +9,7 @@ package org.parabot.environment.api.utils;
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Time {
|
||||
public final class Time {
|
||||
|
||||
/**
|
||||
* Sleeps for a given amount of time
|
||||
@@ -22,6 +24,11 @@ public class Time {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param minumum
|
||||
* @param maximum
|
||||
*/
|
||||
public static void sleep(final int minumum, final int maximum) {
|
||||
try {
|
||||
Thread.sleep(Random.between(minumum, maximum));
|
||||
@@ -30,6 +37,30 @@ public class Time {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleeps until the SleepCondition is valid.
|
||||
*
|
||||
* @param conn
|
||||
* the condition.
|
||||
* @param timeout
|
||||
* the time in miliseconds before it stops sleeping.
|
||||
* @return whether it ran successfully without timing out.
|
||||
*/
|
||||
public static boolean sleep(SleepCondition conn, int timeout) {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!conn.isValid()) {
|
||||
if (start + timeout < System.currentTimeMillis()) {
|
||||
return false;
|
||||
}
|
||||
Time.sleep(50);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current time in milliseconds
|
||||
* @return time in ms
|
||||
*/
|
||||
public static long get() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@@ -123,21 +123,17 @@ public class Script implements Runnable {
|
||||
/**
|
||||
* Sleeps until the SleepCondition is valid.
|
||||
*
|
||||
* <B>DEPRECATED!</b> use {@link Time#sleep(SleepCondition, int)}
|
||||
*
|
||||
* @param conn
|
||||
* the condition.
|
||||
* @param timeout
|
||||
* the time in miliseconds before it stops sleeping.
|
||||
* @return whether it ran successfully without timing out.
|
||||
*/
|
||||
@Deprecated
|
||||
public final boolean sleep(SleepCondition conn, int timeout) {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!conn.isValid()) {
|
||||
if (start + timeout < System.currentTimeMillis()) {
|
||||
return false;
|
||||
}
|
||||
Time.sleep(50);
|
||||
}
|
||||
return true;
|
||||
return Time.sleep(conn, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user