CountDown going down 2 seconds per second

Discussion in 'Plugin Development' started by candyfloss20, Aug 11, 2014.

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

    candyfloss20

    Well i can't solve this bug the countdown is counting down 2 seconds per second

    My Code:

    Code:java
    1. @SuppressWarnings("deprecation")
    2. public class Timer implements CommandExecutor {
    3. static Main main;
    4. int countdown = 30;
    5. int countdown1 = 600;
    6.  
    7. public Timer(Main plugin) {
    8. main = plugin;
    9. main.getCommand("start").setExecutor(this);
    10. }
    11.  
    12. @Override
    13. public boolean onCommand(CommandSender commandSender, Command command, String string, String[] args) {
    14. if (command.getName().equalsIgnoreCase("start")) {
    15. Player player = (Player) commandSender;
    16. if (player.getName().equalsIgnoreCase("candyfloss20") || player.getName().equalsIgnoreCase("dylz_the_pro")) {
    17. for (final Player p : Bukkit.getOnlinePlayers()) {
    18. p.setScoreboard(main.timerBoard);
    19. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, new Runnable() {
    20. public void run() {
    21. countdown--;
    22.  
    23. final Score score = main.o.getScore(Bukkit.getOfflinePlayer("§aStarting In:"));
    24. score.setScore(countdown);
    25.  
    26. final Score score1 = main.o.getScore(Bukkit.getOfflinePlayer("§aAlive: "));
    27. score1.setScore(Bukkit.getOnlinePlayers().length-Main.DEAD.size());
    28.  
    29. final Score score2 = main.o.getScore(Bukkit.getOfflinePlayer("§aGems: "));
    30. score2.setScore(MySQL.getGems(p.getUniqueId()));
    31.  
    32. BarAPI.setMessage(p, "§aStarting In: §5" + countdown + "§a Second(s)");
    33. p.setLevel(countdown);
    34. p.playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
    35. Bukkit.broadcastMessage(Main.PREFIX + "The game will start in: §5" + countdown + "§e Second(s)");
    36.  
    37. if (countdown == 0) {
    38. main.getServer().getScheduler().cancelAllTasks();
    39. BarAPI.removeBar(p);
    40. p.removePotionEffect(PotionEffectType.BLINDNESS);
    41. p.setLevel(0);
    42. p.getInventory().clear();
    43. p.getInventory().setArmorContents(null);
    44. p.setHealth(20);
    45. p.setSaturation(8F);
    46. p.setFoodLevel(20);
    47. p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 200, 1));
    48. p.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 200, 1));
    49. p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 200, 1));
    50. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 200, 1));
    51. Bukkit.broadcastMessage("§a----------------==[UHC]==----------------");
    52. Bukkit.broadcastMessage("§e- Gather loot and kill the other teams");
    53. Bukkit.broadcastMessage("§e- You can §c§lONLY§e Regen with Gold Apples");
    54. Bukkit.broadcastMessage("§e- Last team standing wins (+25,000 §aGems)");
    55. Bukkit.broadcastMessage("§e- World Boarder of §c§l1500 Blocks");
    56. Bukkit.broadcastMessage("§e- Map: §cWorld, §eBy: §cA Minecraft Server");
    57. Bukkit.broadcastMessage("§a----------------==[UHC]==----------------");
    58. Main.setState(GameState.NOPVP);
    59.  
    60. StartNoPvPCountDown();
    61. }
    62. }
    63. }, 0L, 20L);
    64. }
    65. }
    66. }
    67. return true;
    68. }
    69. public void StartNoPvPCountDown() {
    70. for (final Player p : Bukkit.getOnlinePlayers()) {
    71. p.setScoreboard(main.timerBoard1);
    72. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, new Runnable() {
    73. public void run() {
    74. countdown1--;
    75.  
    76. final Score score = main.o1.getScore(Bukkit.getOfflinePlayer("§cNoPvP Ends: "));
    77. score.setScore(countdown1);
    78.  
    79. final Score score1 = main.o1.getScore(Bukkit.getOfflinePlayer("§aAlive: "));
    80. score1.setScore(Bukkit.getOnlinePlayers().length-Main.DEAD.size());
    81.  
    82. final Score score2 = main.o1.getScore(Bukkit.getOfflinePlayer("§aGems: "));
    83. score2.setScore(MySQL.getGems(p.getUniqueId()));
    84.  
    85. BarAPI.setMessage(p, "§cNoPvP Ends In: §5" + countdown1 + "§a Second(s)");
    86. if (countdown1 == 0) {
    87. main.getServer().getScheduler().cancelAllTasks();
    88. Bukkit.broadcastMessage("§c§lPVP IS NOW ON");
    89. p.playSound(p.getLocation(), Sound.IRONGOLEM_DEATH,1,4);
    90. Main.setState(GameState.INGAME);
    91. }
    92. }
    93. }, 0L, 20L);
    94. }
    95. }
    96. }
     
  2. Offline

    xAstraah

    candyfloss20, You will most likely be using a Integer variable wrong then since you are running the Scheduler every second without delay so...
     
  3. Offline

    candyfloss20

  4. Offline

    dodo_hacker

    double the startvalue will solve the problem?
    or am i wrong?
     
  5. Offline

    KaitouKidFTW

    dodo_hacker You have runnable inside a loop. So when there is two people on the server, then the countdown will go down by two.
     
Thread Status:
Not open for further replies.

Share This Page