Async-Tasks - Cancel Properly

Discussion in 'Plugin Development' started by Slikey, Mar 25, 2013.

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

    Slikey

    Hello,
    I wrote a plugin, that starts a procedure and I want to reset the Plugin completet via
    Code:
    Bukkit.reload();
    I cancel all tasks at onEnable() and onDisable(), but still gives me this error:
    This is my code, maybe you find my faults.. :(
    Code:
        public void onEnable() {
            Bukkit.getServer().getScheduler().cancelAllTasks();
            Bukkit.getServer().getScheduler().cancelTasks(this);
            registerListeners();
            new ZombieManager();
            // Starts the program
            Bukkit.getServer().getScheduler().runTaskAsynchronously(this, new GameProcedure());
            // Starts the reporter
            Bukkit.getServer().getScheduler().runTaskTimer(this, new ConsoleReporter(), 0L, 300L);
            System.out.println("[ServerPlug] Enabled!!");
        }
     
        public void onDisable() {
            Bukkit.getServer().getScheduler().cancelAllTasks();
            Bukkit.getServer().getScheduler().cancelTasks(this);
            HandlerList.unregisterAll(this);
            System.out.println("[ServerPlug] Deaktiviert!");
        }
     
  2. Offline

    ferrybig

    did you call the reload from a async task, then you have a problem
     
    Slikey likes this.
  3. Offline

    Slikey

    Thank you.. Really.. Thanks :) I do not understand why, but i have to find another way to do this :/
     
  4. Offline

    ferrybig

    if you reload from a asyncs task (what isn't recommand either because of concurenty bugs) then your task aren;t shutdown until the reload is done
     
    Slikey likes this.
  5. Offline

    Slikey

    Ah okay. You're right. I am so stupid ;) Thnaks again!
     
  6. Offline

    Digi

    You can create a sync task inside an async task to run code in the main thread, it would probably get rid of the nag because the async task would finish before the sync one triggers, or if it doesn't then add a few ticks as delay.
     
Thread Status:
Not open for further replies.

Share This Page