feat: add JavaScriptTask class
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
12d07bf552
commit
7f32062dca
13
pom.xml
13
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MiaoScript</artifactId>
|
||||
<version>0.9.5</version>
|
||||
<version>0.9.6</version>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>502647092</id>
|
||||
@ -54,6 +54,7 @@
|
||||
<properties>
|
||||
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
|
||||
<update.changes>
|
||||
§620-11-19 §afeat: 新增 JavaScriptTask 类;
|
||||
§620-11-11 §afeat: 新增 package 版本锁定逻辑;
|
||||
§620-09-21 §afeat: 完善 upgrade 逻辑;
|
||||
§620-08-27 §afeat: 新增ProtocolLib依赖;
|
||||
@ -177,7 +178,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.6</version>
|
||||
<version>1.18.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.kamranzafar</groupId>
|
||||
@ -187,24 +188,24 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.2-R0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.1.0</version>
|
||||
<version>7.2.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.15-SNAPSHOT</version>
|
||||
<version>1.16-R0.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.nukkit</groupId>
|
||||
<artifactId>nukkit</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user