Cancelling this task?

Discussion in 'Plugin Development' started by jolbol1, Oct 23, 2014.

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

    jolbol1

    Hey guys i need to cancel this task, but am unsure on how to do that.
    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(myPlugin, new Runnable() {


    How do i cancel that specific task.
     
  2. Offline

    Dudemister1999

    jolbol1 It'll return an instance of BukkitTask. So what you do is BukkitTask t = yourCode, then call t.cancel() when done.
     
  3. Offline

    jolbol1

    If i do that i get all sorts of errors, can you give me an example of what you mean?
     
  4. Offline

    fireblast709

    jolbol1 Dudemister1999 the schedule methods return task ids (ints), which you can use in the cancel(int) method. If you use BukkitRunnables you get BukkitTasks, which you can simply invoke cancel() on.
     
  5. jolbol1 Here is an example, Its not tested yet
    Code:java
    1. int NameOfSchedule = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(myPlugin, new Runnable() {
    2. @Override
    3. public void run() {
    4.  
    5. }
    6. }
    7.  
    8.  
    9. //When you want to cancel it just call
    10. Bukkit.getServer().getScheduler().cancel(NameOfSchedule)
     
  6. Offline

    jolbol1

    Mine sort of works like that except i used cancelAllTasks for scheduler, is that a bad thing?
     
  7. Offline

    teej107

    Yes, you could stop other plugins from working correctly.
     
  8. Yes it is very bad, as it could stop other plugins from working, but it is very easy to update your plugins, if you need any help about canceling schedules ask me
     
Thread Status:
Not open for further replies.

Share This Page