Cancelling Scheduled Class

Discussion in 'Plugin Development' started by danthonywalker, Nov 19, 2013.

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

    danthonywalker

    I can start the timer, but I can't seem to cancel it. Can someone tell me what I'm doing wrong? And yes, the cancel() is being reached to, but doesn't seem to be doing anything.

    Code:java
    1. public class GameLogic extends BukkitRunnable implements Listener
    2. {
    3. private int countdown = 0;
    4. private Core plugin;
    5.  
    6. public GameLogic(Core coreClass)
    7. {
    8. plugin = coreClass;
    9. }
    10.  
    11. @EventHandler
    12. public void playerJoin(PlayerJoinEvent event)
    13. {
    14.  
    15. if(plugin.getServer().getOnlinePlayers().length == plugin.getConfig().getInt("GameLogic.MinPlayersStart"))
    16. {
    17. countdown = plugin.getConfig().getInt("GameLogic.CountdownTimerStart");
    18. runTaskTimer(plugin, 0, 20); //Starts Countdown Timer
    19. }
    20.  
    21. }
    22.  
    23. @EventHandler
    24. public void playerLeave(PlayerQuitEvent event)
    25. {
    26.  
    27. if(plugin.getServer().getOnlinePlayers().length == plugin.getConfig().getInt("GameLogic.MinPlayersStart"))
    28. {
    29. countdown = plugin.getConfig().getInt("GameLogic.CountdownTimerStart");
    30. cancel(); //Cancels Countdown Timer
    31. }
    32.  
    33. }
    34.  
    35. public void run()
    36. {
    37. countdown--;
    38.  
    39. if(countdown == 0)
    40. {
    41. cancel();
    42. }
    43.  
    44. }
    45.  
    46. }


    Rephrase, after doing some print statements the scheduled task does appear to cancel, but I cannot reschedule it. I just get this error.

    Code:
    Caused by: java.lang.IllegalStateException: Already scheduled as 22
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page