Hello, I have a game plugin and I need to run a countdown and when it gets to 0 end the task. how would i do that? I have tried using the scheduler but I am not able to cancel the task /: Any help is appriciated. Code:java public void onEnable(){ new ArenaManager(this); ArenaManager.getManager().getArena().setGameState(GameState.Lobby); Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this); //CountDown from 600 to 0 and do ArenaManager.getManager().getArena().startGame when its 0 then stop the task, } Has anybody used a countdown or have a different method? The trouble I'm having is when the counter is 0 I can't cancel the task B U M P How do I get the id of the task I created? No replys? I'll check again in the morning <merged bumps xD - Iroh> Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
TehVoyager Use: Code:java BukkitTask task = Bukkit.getScheduler().runTaskTimer(<Plugin Instance>, <Runnable>, <Init Delay>, <Repeat Delay>); To cancel: Code:java task.cancel(); I might be a little off, I'm not on my computer right now.
The_Doctor_123 I've tried to do that but I don't know what to do for the runnable, I made a countdown class the implemented runnable and put the run method but it didn't work The_Doctor_123 When I try this it says that count hasn't been initialized Code:java BukkitTask count = Bukkit.getScheduler().runTaskTimer(this, new Runnable(){ @Override public void run() { if(counter == 0){ count.cancel(); } } }, 0, 20); EDIT by Moderator: merged posts, please use the edit button instead of double posting.
TehVoyager Yes, count hasn't been defined yet to the Runnable's knowledge. You can define a Runnable and make a method to pass on the BukkitTask Object. Or, don't cancel the task inside of the Runnable.