diff --git a/pom.xml b/pom.xml index 83dc62c..907e8b2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoScript - 0.9.5 + 0.9.6 502647092 @@ -54,6 +54,7 @@ DEV + §620-11-19 §afeat: 新增 JavaScriptTask 类; §620-11-11 §afeat: 新增 package 版本锁定逻辑; §620-09-21 §afeat: 完善 upgrade 逻辑; §620-08-27 §afeat: 新增ProtocolLib依赖; @@ -177,7 +178,7 @@ org.projectlombok lombok - 1.18.6 + 1.18.10 org.kamranzafar @@ -187,24 +188,24 @@ org.spigotmc spigot-api - 1.15.2-R0.1-SNAPSHOT + 1.16.2-R0.1-SNAPSHOT compile org.spongepowered spongeapi - 7.1.0 + 7.2.0 compile net.md-5 bungeecord-api - 1.15-SNAPSHOT + 1.16-R0.4-SNAPSHOT cn.nukkit nukkit - 1.0-SNAPSHOT + 2.0.0-SNAPSHOT compile diff --git a/src/main/java/pw/yumc/MiaoScript/Base.java b/src/main/java/pw/yumc/MiaoScript/Base.java index b17019d..80e0765 100644 --- a/src/main/java/pw/yumc/MiaoScript/Base.java +++ b/src/main/java/pw/yumc/MiaoScript/Base.java @@ -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); } diff --git a/src/main/java/pw/yumc/MiaoScript/JavaScriptTask.java b/src/main/java/pw/yumc/MiaoScript/JavaScriptTask.java new file mode 100644 index 0000000..4579e67 --- /dev/null +++ b/src/main/java/pw/yumc/MiaoScript/JavaScriptTask.java @@ -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; + } +}