Can someone help me, In my plugin I am trying to add a countdown feature. So basically you do a command like /countdown, then in chat it broadcasts, 5,4,3,2,1. In seconds. Thanks for your help!
You can create a class like CountdownTask, and you make it extend BukkitRunnable. Than you have to create a run method in which you can do Bukkit.broadcast() i think. After that when the command /countdown is done you do Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, countdowntask, 0L, 20);
Code:java public void CountDown(){mytaskid2 = ConfigurableMessages.getPlugin().getServer().getScheduler().runTaskTimer(ConfigurableMessages.getPlugin(), new Runnable() {int number = 5;public void run() {if(number != -1) {if(number !=0) {Bukkit.broadcastMessage(ChatColor.GOLD + "" + number);number--;for(Player player: Bukkit.getOnlinePlayers()){player.playSound(player.getLocation(), Sound.NOTE_PLING, 4.0F, player.getLocation().getPitch());}}else{Bukkit.broadcastMessage(ChatColor.DARK_RED + "Start!");number--;mytaskid2.cancel();for(Player player: Bukkit.getOnlinePlayers()){player.playSound(player.getLocation(), Sound.EXPLODE, 4.0F, player.getLocation().getPitch());} }}}}, 0L, 20L);} Simple countdown, which I use in my project.
How can I make a command perform that? Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code:java public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ if(cmd.getName().equalsIgnoreCase("countdown")){ CountDown(); return true; } return false;}
Sicka_gp In publicvoid CountDown(){ it highlights void and the { Also, how can I make it do 1 minute until start, then 30 seconds until start, then have 10,9,8,7,6,5,4,3,2,1. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
In his code, It doesnt have a space With this CountDown(){ In mine it does. Just trying to help you even though Im not the most knowledgable at bukkit WAIT, DO YOU HAVE @EVENTHANDLER OVER THE TOP?! EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I suggest you go look at some java tutorials online to get a better grip of the language. I could tell you how to code the countdown the way you want but I have a feeling that a lot of users use the plugin development section to simply learn java or have other people punch out code for them, which as I understand it is not this section's purpose. Your problem is not rooted in a specific Bukkit or Minecraft related issue you can't figure out but in your lack of java knowledge.