Cancel Bukkit Timer by ID

Discussion in 'Plugin Development' started by Welite, Mar 2, 2014.

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

    Welite

    Hello, I need to run different timer instances and after some IF cancel on of the instances so I save the Timer ID to HashMap and then I get the id and try to cancel the timer, but it always cancel all timer instances not just the instance with that ID.


    My code:
    Code:java
    1.  
    2. taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    3. int i = 10;
    4. @Override
    5. public void run() {
    6. task.put(arena, taskId);
    7.  
    8. if (i==0) {
    9. getServer().getScheduler().cancelTask((task.get(arena))); //Here it cancels all instances of that scheduler not just the only 1 specified by ID
    10. task.remove(arena);
    11. }
    12. i--;
    13. } }, 20L, 20);
    14. }
    15.  
    16.  



    So for example when this timer is running 5 times when the variable i == 0 in one of the 5 timers it cancels all 5 timers not just the only one of them.
     
  2. Offline

    TopTobster5

    I may be wrong, but I think it is taskId you need to cancel, not arena.​
     
  3. Offline

    HungerCraftNL

    Code:
    if(i == 0){
      cancel();
    }
     
  4. Offline

    Minesuchtiiii

    this.getServer().getScheduler().cancelTask(taskid);
     
  5. Offline

    Welite

Thread Status:
Not open for further replies.

Share This Page