@@ -1,34 +1,32 @@
 | 
			
		||||
import { task, plugin } from '@ccms/api'
 | 
			
		||||
import { inject, provideSingleton } from '@ccms/container';
 | 
			
		||||
import { inject, provideSingleton } from '@ccms/container'
 | 
			
		||||
 | 
			
		||||
const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable');
 | 
			
		||||
const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable')
 | 
			
		||||
 | 
			
		||||
@provideSingleton(task.TaskManager)
 | 
			
		||||
export class NukkitTaskManager implements task.TaskManager {
 | 
			
		||||
export class NukkitTaskManager extends task.TaskManager {
 | 
			
		||||
    @inject(plugin.PluginInstance)
 | 
			
		||||
    private pluginInstance: any;
 | 
			
		||||
    private pluginInstance: any
 | 
			
		||||
 | 
			
		||||
    create(func: Function): task.Task {
 | 
			
		||||
        if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
 | 
			
		||||
        return new NukkitTask(this.pluginInstance, func);
 | 
			
		||||
    create0(func: Function): task.Task {
 | 
			
		||||
        return new NukkitTask(this.pluginInstance, func)
 | 
			
		||||
    }
 | 
			
		||||
    callSyncMethod(func: Function): any {
 | 
			
		||||
        return func()
 | 
			
		||||
    }
 | 
			
		||||
    disable() {
 | 
			
		||||
    disable0() {
 | 
			
		||||
        base.getInstance().getServer().getScheduler().cancelTask(this.pluginInstance)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class NukkitTask extends task.Task {
 | 
			
		||||
    submit(...args: any[]): task.Cancelable {
 | 
			
		||||
    submit0(...args: any[]): task.Cancelable {
 | 
			
		||||
        let run = new NukkitRunnable({ run: () => this.run(...args) })
 | 
			
		||||
        let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
 | 
			
		||||
        if (this.interval) {
 | 
			
		||||
            run[funcName](this.plugin, this.laterTime, this.interval);
 | 
			
		||||
            return run[funcName](this.plugin, this.laterTime, this.interval)
 | 
			
		||||
        } else {
 | 
			
		||||
            run[funcName](this.plugin, this.laterTime);
 | 
			
		||||
            return run[funcName](this.plugin, this.laterTime)
 | 
			
		||||
        }
 | 
			
		||||
        return run;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user