feat: add bungee package

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-01-15 16:43:00 +08:00
parent 1425c473fd
commit aa581afbe5
8 changed files with 244 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { task, plugin } from '@ms/api'
import { injectable, inject } from '@ms/container';
var Runnable = Java.type('java.lang.Runnable')
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
@injectable()
export class BungeeTaskManager implements task.TaskManager {
@inject(plugin.PluginInstance)
private pluginInstance: any;
create(func: Function): task.Task {
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
return new BungeeTask(this.pluginInstance, func);
}
}
export class BungeeTask extends task.Task {
submit(): task.Cancelable {
let run = new Runnable({ run: () => this.run() })
if (this.isAsync) {
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
}
if (this.interval) {
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, this.interval, TimeUnit.MILLISECONDS)
} else {
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, TimeUnit.MILLISECONDS)
}
}
}