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-11-13 01:40:34 +00:00
|
|
|
create0(owner: plugin.Plugin, func: Function, id: number): task.Task {
|
|
|
|
return new BungeeTask(owner, func, id)
|
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-11-13 01:40:34 +00:00
|
|
|
base.getInstance().getProxy().getScheduler().cancel(base.getInstance())
|
2020-04-03 03:36:06 +00:00
|
|
|
}
|
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) {
|
2020-11-13 01:40:34 +00:00
|
|
|
return base.getInstance().getProxy().getScheduler().runAsync(base.getInstance(), run)
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
|
|
|
if (this.interval) {
|
2020-11-13 01:40:34 +00:00
|
|
|
return base.getInstance().getProxy().getScheduler().schedule(base.getInstance(), run, this.laterTime * 50, this.interval * 50, TimeUnit.MILLISECONDS)
|
2020-01-15 08:43:00 +00:00
|
|
|
} else {
|
2020-11-13 01:40:34 +00:00
|
|
|
return base.getInstance().getProxy().getScheduler().schedule(base.getInstance(), run, this.laterTime * 50, TimeUnit.MILLISECONDS)
|
2020-01-15 08:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|