Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a repeating task schedule in Bukkit

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);
}
like image 427
STobiasS Avatar asked Sep 27 '22 19:09

STobiasS


1 Answers

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.

like image 129
Forseth11 Avatar answered Oct 06 '22 02:10

Forseth11