fix: task disable error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-11-13 09:40:34 +08:00
parent c64d167893
commit d769a9c8ca
11 changed files with 122 additions and 70 deletions

View File

@ -7,17 +7,14 @@ const Callable = Java.type('java.util.concurrent.Callable')
@provideSingleton(task.TaskManager)
export class BukkitTaskManager extends task.TaskManager {
@inject(plugin.PluginInstance)
private pluginInstance: any
create0(func: Function): task.Task {
return new BukkitTask(this.pluginInstance, func)
create0(owner: plugin.Plugin, func: Function, id: number): task.Task {
return new BukkitTask(owner, func, id)
}
callSyncMethod(func: Function): any {
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
return Bukkit.getScheduler().callSyncMethod(base.getInstance(), new Callable({ call: () => func() })).get()
}
disable0() {
Bukkit.getScheduler().cancelTasks(this.pluginInstance)
Bukkit.getScheduler().cancelTasks(base.getInstance())
}
}
@ -26,9 +23,9 @@ export class BukkitTask extends task.Task {
let run = new BukkitRunnable({ run: () => this.run(...args) })
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
if (this.interval) {
return run[funcName](this.plugin, this.laterTime, this.interval)
return run[funcName](base.getInstance(), this.laterTime, this.interval)
} else {
return run[funcName](this.plugin, this.laterTime)
return run[funcName](base.getInstance(), this.laterTime)
}
}
}