Bukkit 可运行提示

Bukkit runnable tips

您好,有什么想法可以让 scheduleSyncDelayedTask 不取消之前的任务,应该是 运行 稍后再取消?

for(int x = 0; x < 8; x++){
    int taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(), new Runnable() {        
        @Override
        public void run() {                 
            CreateItems.createItemsOnStand2(player, bedna, listitems);      
        }
    }, 30*x , 2+x);

    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable() {
        public void run() {
            Bukkit.getScheduler().cancelTask(taskID);
        }
    }, (x==0) ? 30 : 30*x);     
}

可以使用BukkitRunnables进行任务调度

new BukkitRunnable() {
    @Override
    public void run() {
        //Code you need running
        this.cancel();    //Cancelling
    }
}.runTaskTimer(pluginInstance, delayTime, repeatingTime);



 new BukkitRunnable() {
    @Override
    public void run() {
        //Code you need running
        this.cancel();    //Cancelling
    }
}.runTaskLater(pluginInstance, delayTime);

它使得任务可以轻松创建和自行取消