Solved Stop and restart a BukkitRunnable task

Discussion in 'Plugin Development' started by LeeTheENTP, Jan 23, 2017.

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

    LeeTheENTP

    Part of my plugin involves an item generator that can be upgraded. When the an instance of the Generator class (which extends BukkitRunnable) is created, a task is scheduled and run. This is my current code for the upgrade process:

    Code:
    public void levelUp()
        {
            level++;
            if(level == 0)
                level++;
      
            turnOff();
            calcTime();
            calcUpgradeCost();
            turnOn();
      
            Sign sign = (Sign)loc.getBlock().getState();
            sign.setLine(2, ChatColor.DARK_RED + "Level " + level + " (" + getTimeInSeconds() + "s)");
            sign.update();
        }
    Relevant Methods:
    • turnOff - runs this.cancel()
    • turnOn - runs this.runTaskTimer(main, 0, time)
    When this method is run, it throws an error into the console stating that the task is already scheduled, giving the task ID.

    I was under the impression that when a task is canceled, the scheduler forgets about it. Apparently, that is not the case. As such, what should I do instead to restart the task with the recalculated time (result of running calcTime())?

    Thanks in advance for the help!

    Solved. I changed it from BukkitRunnable to Runnable and made adjustments.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 23, 2017
Thread Status:
Not open for further replies.

Share This Page