How do I cancel a task with this code?: Code (Text): --- public class Countdown extends BukkitRunnable { @Override public void run() { if(WaitingPlayers.waitingPlayers.size() < Main.getInstance().getConfig().getInt("min_players")) { for(String s : WaitingPlayers.waitingPlayers) { Bukkit.getServer().getPlayer(s).sendMessage(Main.getInstance().formatChat(Main.getInstance().getMessagesFile().getString("not_enough_players"))); } } } private void startCountdown() { new Countdown().runTaskTimer(Main.getInstance(), 20, 20); } } I know I can do Code (Text): Bukkit.getScheduler().cancelTask(int taskId); but where do I get the ID from?
What Phloxz said or you could just do something like Code (Text): Bukkit.getScheduler().cancelTask(int TaskName); Keep in mind it's an int, so if you wanted to use it, just define the task as an integer
You could just define the task as an Integer, for example Code (Text): task = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { - After you declare it as an integer.
Use Code (Text): Countdown countdown = new Countdown(); countdown.cancel(); Just store the countdown and cancel it.
What do you mean? If you don't want another task running at the same time. Just implement a sone logic like Code (Text): if(Bukkit.getScheduler().isCurrentlyRunning(task)) { //blah blah