how can i cancel/stop the bukkit runnable

Discussion in 'Plugin Development' started by BasimTM, Nov 20, 2020.

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

    BasimTM

    hello i've been trying for 2 days i tried and searched in every website
    please someone tell me how can i stop this bukkit runnable task
    why the cancel(): not working
    Code:
    public class stest extends JavaPlugin {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            new BukkitRunnable() {
            
            
            @Override
        
            public void run() {
                if (cmd.getName().equalsIgnoreCase("Srun")) {
                    for(Player online : Bukkit.getOnlinePlayers()) {
                    
                        player.teleport(online);
                        online.teleport(player);
                    
                    
                    }
                
                }
                if (cmd.getName().equalsIgnoreCase("Sstop")) {
                    this.cancel();
                }
            
            }
        
        }.runTaskTimer(this, 60, 60);
        return true;
    }
    }
     
  2. Offline

    Kars

    @BasimTM cancel isn't working (in your case) because you aren't calling it on the first runnable that you schedule the first time. You are canceling a second one.
    To cancel the first one, you must somehow keep track of the first runnable and cancel that.
     
Thread Status:
Not open for further replies.

Share This Page