您好,您有什么想法可以使 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);
它使得任务可以很容易地创建并且可以自行取消
关于java - Bukkit 可运行提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37955355/