5

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);
}
Matej Kormuth
  • 2,139
  • 3
  • 35
  • 52
STobiasS
  • 75
  • 2
  • 6

1 Answers1

4

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.

Forseth11
  • 1,418
  • 1
  • 12
  • 21