Solved BukkitRunnable problem - Not scheduled yet

Discussion in 'Spigot Plugin Development' started by gronnmann, Jun 18, 2016.

  1. I am making a minigame plugin, but have came to a problem with a runnable, on the moment I try to cancel it. The error code is the following:
    Code (Text):
    [17:34:28 WARN]: Exception in thread "Craft Scheduler Thread - 125447"
    [17:34:28 WARN]: org.apache.commons.lang.UnhandledException: Plugin LaserWars v1.1 generated an exception while executing task 85
            at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalStateException: Not scheduled yet
            at org.bukkit.scheduler.BukkitRunnable.getTaskId(BukkitRunnable.java:134)
            at io.github.gronnmann.laserwars.Gibber.cancelTask(Gibber.java:41)
            at io.github.gronnmann.laserwars.LaserShot.run(LaserShot.java:31)
            at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftTask.run(CraftTask.java:71)
            at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
            ... 3 more
    The source is:
    https://github.com/gronnmann/LaserW.../io/github/gronnmann/laserwars/LaserShot.java

    The plugin also doesn't detect when the "shot" touches another player.
     
  2. Perhaps make the cancel line inside a delayed task to run a few ticks later?
     
  3. MiniDigger

    Supporter

    you need to call your runnable throu the bukkit scheduler, do not call the run method directly
     
    • Like Like x 1
    • Agree Agree x 1
  4. It's because you're calling cancel() twice, once inside the if statement and once when you loop through online players. You are probably thinking that cancel() acts like return, but it doesn't. It just tells the Scheduler not to run it again. Your solution is to return after you cancel().
     
  5. To be more precise, you have to use the methods provided by the BukkitRunnable object and NOT just pass the BukkitRunnable to the scheduler.
     
  6. Return didn't work.
    I have both tried making the scheduler cancel it and making it cancel itself. Have also tried making it call a event in another class which would stop it. Nothing worked....
     
  7. Return after you cancel the second time, too. I just noticed that you have a third cancel(). The error you're getting means that you are trying to cancel a task that isn't scheduled.

    EDIT: Your stacktrace is pointing to the first call to cancel(). Are you cancelling it elsewhere before then? What is on Gibber.java:41?
     
  8. at that time there weren't anything at Gibber 41.
     
  9. You're gonna have to post your code for Gibber, anyway...
     
  10. @gronnmann
    scheduleAsyncRepeatingTask() should be used when you work with Runnables specifically, not when you have a BukkitRunnable. Use BukkitRunnable#runTaskTimerAsynchronously()

    Everytime you call cancel(), return immediately afterwards.
     
    • Informative Informative x 1
  11. The stacktrace you posted doesn't match up with the code you provided. The error causing your stacktrace is caused by line 41 in a method in Gibber called cancelTask().
    @megamichiel has a good point about not using deprecated methods... but that's not going to cause your error. We need to see a stacktrace and the code that corresponds with it.
     
  12. Code (Text):
    Bukkit.getScheduler().scheduleAsyncRepeatingTask(pl, shot, 1, 1);
    Needs to be

    Code (Text):
    shot.runTaskTimerAsynchronously(pl, 1, 1);
    This is what @Rocoty was talking about. The scheduler takes a Runnable, but BukkitRunnables start themselves.
     
    • Agree Agree x 1
  13. Oh, I think server had wrong version. The code at GitHub is now new, and this is the stack trace I just received:
    Code (Text):
    [19:53:29 WARN]: Exception in thread "Craft Scheduler Thread - 102"
    [19:53:29 WARN]: org.apache.commons.lang.UnhandledException: Plugin LaserWars v1.1 generated an exception while executing task 6
            at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalStateException: Not scheduled yet
            at org.bukkit.scheduler.BukkitRunnable.getTaskId(BukkitRunnable.java:134)
            at org.bukkit.scheduler.BukkitRunnable.cancel(BukkitRunnable.java:18)
            at io.github.gronnmann.laserwars.LaserShot.run(LaserShot.java:39)
            at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftTask.run(CraftTask.java:71)
            at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
            ... 3 more
     
  14. @gronnmann
     
  15. Thanks. I set it to shot.runTaskTimer(pl, 1, 1) and everything worked!
     
    • Like Like x 2
  16. As I know , cancel a not scheduler task , will get this execption
     
    • Funny Funny x 2