I am writing a minigame for Minecraft and have a problem with the schedule. I don't know how to stop the schedule. Please tell me how I can stop running this loop / Timer / Schedule:
public void WarteTimer() {
count = Bukkit.getScheduler().scheduleSyncRepeatingTask(
(Plugin) this,
new Runnable() {
@Override
public void run() {
if (countdown > 0) {
Bukkit.broadcastMessage("§6Countdown : " +countdown);
countdown--;
} else {
Game();
//Bukkit.getScheduler().cancelTask(count);
//countdown = 5;
}
}
},
0L,
20L);
}
To stop a scheduler in bukkit you have to get the id for the scheduler and call the Bukkit scheduler cancel method.
I see you have already set count
equal to the scheduler. I am assuming count
is an integer.
To stop a scheduler simply put:
Bukkit.getScheduler().cancelTask(taskID);
In your case you will use :
Bukkit.getScheduler().cancelTask(count);
You can run this line where ever and it will stop your scheduler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With