Task not unscheduling itself.

Discussion in 'Spigot Plugin Help' started by tuskiomi, Jun 9, 2015.

  1. Hello All.
    I am back from my other bukkit thread. I guess the mods thought it wasn't Bukkit enough.
    So, I'll ask a conceputal question.
    Whenever I call a method from a runnable in my main class that is also in my main class, the runnable fails to remove itself from the event Q.
    How would I go about making a method that cancels a runnable task that can be called from the task itself?
    -I cannot use bukkitRunnables
    -the method must be able to be called from anywhere, Inside or outside the task.
    -There must be no parameters.
    -I'm using 1.8.(3)

    My code to do that now looks like this:

    Code (Text):

    public class example extends JavaPlugin implements Listener{
        List<Integer> eventIdBuffer = new ArrayList<Integer>();
        public void onEnable(){
            this.getServer().getPluginManager().registerEvents(this, this);
         
        }
     
        @EventHandler
        public void combust(EntityCombustEvent e){
                            eventIdBuffer.add(getServer().getScheduler().scheduleSyncRepeatingTask(this, fooMethod(e.getEntity().getLocation().add(0, 4, 0)), 1, 10));
                   
            }
        protected void unschedule() {
            getServer().getPlayer(playert).sendMessage("stopped task: "+eventIdBuffer.get(0));
            getServer().getScheduler().cancelTask(eventIdBuffer.get(0));
         
        }
        private Runnable fooMethod(Location l) {
                return new Runnable(){
                    int step = 0;
                    @Override
                    public void run() {
                        if(step >45)
                        unschedule();
                        step++; //unscheduling code
                     
                        doThings();
                    }};
         
        }
         
        }
     
    However what end up happening is the runnable repeatedly tries to cancel itself, but fails, and no tasks are cancelled.
     
  2. Is the task actually being scheduled?
     
  3. You never scheduled the task...
     
  4. public void combust(EntityCombustEvent e){
    eventIdBuffer.add(getServer().getScheduler().scheduleSyncRepeatingTask(this, fooMethod(e.getEntity().getLocation().add(0, 4, 0)), 1, 10));

    }
     
  5. Oops. I am blind ;-;