2020-05-02 16:14:47 +00:00
|
|
|
import { task, plugin } from '@ccms/api'
|
2020-09-22 10:42:39 +00:00
|
|
|
import { inject, provideSingleton } from '@ccms/container'
|
2020-01-15 08:43:00 +00:00
|
|
|
|
|
|
|
var Runnable = Java.type('java.lang.Runnable')
|
|
|
|
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(task.TaskManager)
|
2020-09-22 10:42:39 +00:00
|
|
|
export class BungeeTaskManager extends task.TaskManager {
|
2020-01-15 08:43:00 +00:00
|
|
|
@inject(plugin.PluginInstance)
|
2020-09-22 10:42:39 +00:00
|
|
|
private pluginInstance: any
|
2020-01-15 08:43:00 +00:00
|
|
|
|
2020-09-23 03:25:53 +00:00
|
|
|
create0(func: Function): task.Task {
|
|
|
|
return new BungeeTask(this.pluginInstance, func)
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
2020-01-17 03:08:51 +00:00
|
|
|
callSyncMethod(func: Function): any {
|
2020-09-22 10:42:39 +00:00
|
|
|
return func()
|
2020-01-17 03:08:51 +00:00
|
|
|
}
|
2020-09-23 03:25:53 +00:00
|
|
|
disable0() {
|
2020-04-03 03:36:06 +00:00
|
|
|
this.pluginInstance.getProxy().getScheduler().cancel(this.pluginInstance)
|
|
|
|
}
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class BungeeTask extends task.Task {
|
2020-09-22 10:42:39 +00:00
|
|
|
submit0(...args: any[]): task.Cancelable {
|
2020-05-30 02:43:33 +00:00
|
|
|
let run = new Runnable({ run: () => this.run(...args) })
|
2020-01-15 08:43:00 +00:00
|
|
|
if (this.isAsync) {
|
|
|
|
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
|
|
|
}
|
|
|
|
if (this.interval) {
|
2020-04-01 03:08:15 +00:00
|
|
|
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, this.interval * 50, TimeUnit.MILLISECONDS)
|
2020-01-15 08:43:00 +00:00
|
|
|
} else {
|
2020-04-01 03:08:15 +00:00
|
|
|
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, TimeUnit.MILLISECONDS)
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|