Solved Cancelling a repeating task... What am i doing wrong!?

Discussion in 'Plugin Development' started by amitlin14, Aug 6, 2013.

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

    amitlin14

    It has been driving me CRAZY! what am i doing wrong!? I tried everything! but no matter what i do, it always gives me a java.lang.IllegalStateException: Not scheduled yet.

    This is how i call the repeating task
    Code:java
    1. GameTask task = new GameTask();
    2.  
    3. Bukkit.getScheduler().runTaskTimer(Infection.instance, new GameTask(), 20, 20);


    And this is the latest version of attempts at getting it to work
    Code:java
    1. public static class GameTask extends BukkitRunnable {
    2. static long timer = 60 * 8;
    3.  
    4. public void run() {
    5. for (Player player : Bukkit.getOnlinePlayers())
    6. player.setLevel((int) timer);
    7.  
    8. timer--;
    9. if (timer == 450)
    10. randomZombify();
    11.  
    12. if (timer < 470)
    13. {
    14. try
    15. {
    16. if (Bukkit.getScheduler().isCurrentlyRunning(this.getTaskId()) || Bukkit.getScheduler().isQueued(this.getTaskId()))
    17. Bukkit.getScheduler().cancelTask(this.getTaskId());
    18. } catch (Exception e)
    19. {
    20. this.cancel();
    21. }
    22. }
    23. }


    Please tell me what am i doing wrong, its driving me insane ):
     
  2. Offline

    newboyhun

    amitlin14
    I didn't code with Bukkit api in a while, but i can't remember a 'getTaskId()' method in BukkitRunnable.

    This is how i did:

    Code:
    private static class MyRunnable implements Runnable {
      public int id;
     
      @Override
      public void run() {
        Bukkit.getScheduler().cancelTask(this.id);
      }
    }
     
    MyRunnable sch = new MyRunnable();
    sch.id = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, sch, 10, 10);
    
     
  3. Offline

    amitlin14

    newboyhun The error is gone, but the scheduler doesnt cancel ):
     
  4. Offline

    evilguy4000

    amitlin14
    What is your goal with the sheduler and why does it need to cancel?
     
  5. Offline

    Tarestudio

    amitlin14
    You have to start the schedule with the method of the object: task.runTaskTimer(Infection.instance, 20L, 20L);
     
  6. Offline

    amitlin14

    Tarestudio It... It worked... oh my god. What is this sorcery?!
     
Thread Status:
Not open for further replies.

Share This Page