feat: add JavaScriptTask class

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-11-20 10:30:05 +08:00
parent 12d07bf552
commit 7f32062dca
3 changed files with 50 additions and 6 deletions

13
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>MiaoScript</artifactId> <artifactId>MiaoScript</artifactId>
<version>0.9.5</version> <version>0.9.6</version>
<developers> <developers>
<developer> <developer>
<id>502647092</id> <id>502647092</id>
@ -54,6 +54,7 @@
<properties> <properties>
<env.GIT_COMMIT>DEV</env.GIT_COMMIT> <env.GIT_COMMIT>DEV</env.GIT_COMMIT>
<update.changes> <update.changes>
§620-11-19 §afeat: 新增 JavaScriptTask 类;
§620-11-11 §afeat: 新增 package 版本锁定逻辑; §620-11-11 §afeat: 新增 package 版本锁定逻辑;
§620-09-21 §afeat: 完善 upgrade 逻辑; §620-09-21 §afeat: 完善 upgrade 逻辑;
§620-08-27 §afeat: 新增ProtocolLib依赖; §620-08-27 §afeat: 新增ProtocolLib依赖;
@ -177,7 +178,7 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.6</version> <version>1.18.10</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.kamranzafar</groupId> <groupId>org.kamranzafar</groupId>
@ -187,24 +188,24 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version> <version>1.16.2-R0.1-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spongepowered</groupId> <groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId> <artifactId>spongeapi</artifactId>
<version>7.1.0</version> <version>7.2.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId> <artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version> <version>1.16-R0.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.nukkit</groupId> <groupId>cn.nukkit</groupId>
<artifactId>nukkit</artifactId> <artifactId>nukkit</artifactId>
<version>1.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -31,6 +31,10 @@ public class Base {
return ProxyClass.class; return ProxyClass.class;
} }
public Class<?> getJavaScriptTaskClass() {
return JavaScriptTask.class;
}
public String read(String path) throws IOException { public String read(String path) throws IOException {
return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8); return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8);
} }

View 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;
}
}