Hello. My Countdown Dont work. Can someone optimize my code? Thank you! Code: package Puncher; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; public final class Countdown extends JavaPlugin { public void onEnable() { int Countdown = 20; BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.scheduleSyncRepeatingTask(this, new Runnable() { @Override public void run() { if(Countdown == 10) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 9) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 8) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 7) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 6) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 5) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 4) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 3) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 2) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 1) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Second"); } if(Countdown == 0) { Bukkit.broadcastMessage("The match is now starting."); } } }, 0L, 20L); } }
@timtower output: The Match is now starting... Code: package Puncher; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; public final class Countdown extends JavaPlugin { public void onEnable() { int Countdown = 20; BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.scheduleSyncRepeatingTask(this, new Runnable() { @Override public void run() { if(Countdown == 10) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 9) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 8) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 7) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 6) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 5) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 4) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 3) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 2) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 1) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Second"); } if(Countdown > 0) { Bukkit.broadcastMessage("The match is now starting."); } } }, 0L, 20L); } }
@Minibros Check my comment, then check your code again. You are doing something else then what I said
@timtower OUTPUT: The Match is starting Without stopping CODE package Puncher; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; public final class Countdown extends JavaPlugin { public void onEnable() { int Countdown = 20; BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.scheduleSyncRepeatingTask(this, new Runnable() { @Override public void run() { if(Countdown == 10) { Bukkit.broadcastMessage("The match is starting in" + 10 + "Seconds"); } if(Countdown > 0) { Bukkit.broadcastMessage("The match is now starting."); } } }, 0L, 20L); } }
@Minibros Code: public void run() { if(Countdown >0) { Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds"); } if(Countdown == 0) { Bukkit.broadcastMessage("The match is now starting."); } } Not much difference.