@ -31,6 +31,10 @@ public class Base {
|
||||
return ProxyClass.class;
|
||||
}
|
||||
|
||||
public Class<?> getJavaScriptTaskClass() {
|
||||
return JavaScriptTask.class;
|
||||
}
|
||||
|
||||
public String read(String path) throws IOException {
|
||||
return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
39
src/main/java/pw/yumc/MiaoScript/JavaScriptTask.java
Normal file
39
src/main/java/pw/yumc/MiaoScript/JavaScriptTask.java
Normal file
@ -0,0 +1,39 @@
|
||||
package pw.yumc.MiaoScript;
|
||||
|
||||
import java.util.concurrent.Delayed;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class JavaScriptTask implements Delayed {
|
||||
private final Object task;
|
||||
private final long startTime;
|
||||
private final long executeTime;
|
||||
|
||||
public JavaScriptTask(Object task, long ms) {
|
||||
this.task = task;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
this.executeTime = ms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDelay(TimeUnit unit) {
|
||||
return unit.convert((this.startTime + this.executeTime) - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Delayed delayed) {
|
||||
JavaScriptTask task = (JavaScriptTask) delayed;
|
||||
return (int) ((this.startTime + this.executeTime) - (task.getStartTime() + task.getExecuteTime()));
|
||||
}
|
||||
|
||||
public Object getTask() {
|
||||
return this.task;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
public long getExecuteTime() {
|
||||
return this.executeTime;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user