你好任何想法如何制作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);
}
答案 0 :(得分:3)
您可以使用BukkitRunnable进行任务调度
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);
这样可以轻松创建任务并自行取消