Stopping a repeating task

Discussion in 'Plugin Development' started by phimt, Jun 16, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    Whats the best way to stop a repeating Sync task? Is it possible to stop a task within the runnable? I have a repeating task that checks a few blocks for certain materials, and should stop when the check is true, as there is no need for it afterward.

  2. You can stop it even inside the runnable. If you have only this task, it's easy to do.
    Otherwise you'd need to save the id that you get returned when creating a task. Using that id you can cancel the task.
    int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(..);
  3. Offline


    Alternatively don't make it a repeating task, but rather a normal task that will re-register itself if it needs to be repeated.
  4. Offline


    Thanks, I got it to work :D.
  5. Offline


    With wich way did you do that :D?
    Can you may post it?

    Mfg Eistee
  6. Offline


    One way to do it is to pass the Scheduler object to the constructor of the Runnable, and have the Runnable register itself and save the ID returned.,

    Then, in the Runnable's run() method, determine if you have reached the stopping case, an if you have, use the Scheduler to cancel the task by its ID.
  7. Offline


    I had a method that sets up a delayed task call itself if the condition was not met
Thread Status:
Not open for further replies.

Share This Page