Problem with scheduler

Discussion in 'Plugin Development' started by maestro34, Apr 6, 2014.

Thread Status:
Not open for further replies.
  1. Hello guys,
    I made a countdown before the game starting and it doesn't decrement.

    Code:
    Code:java
    1. package me.maestro34.tower.manager;
    2.  
    3. import me.maestro34.tower.Main;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Sound;
    8. import org.bukkit.entity.Player;
    9.  
    10. public class TaskManager {
    11.  
    12. public static Main plugin;
    13.  
    14. public TaskManager(Main Main){
    15. plugin = Main;
    16. }
    17.  
    18. public static int SecondsToCountDown = 0;
    19. public static int taskID;
    20.  
    21. public static void startCountdown(final int time)
    22. {
    23. taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
    24. {
    25. public void run()
    26. {
    27.  
    28. int n = time;
    29.  
    30. if(n != -1)
    31. {
    32. if(n != 0)
    33. {
    34. String p = "s";
    35. if(time == 1){p = "";}
    36.  
    37. if(n <= 3)
    38. {
    39. for (Player player : Bukkit.getOnlinePlayers())
    40. {
    41. player.playSound(player.getLocation(), Sound.NOTE_PLING, 10, 1);
    42. }
    43.  
    44. Bukkit.broadcastMessage(ChatColor.GRAY + "The game start in " + ChatColor.AQUA + n + ChatColor.GRAY + " second" + p + " !");
    45. n--;
    46. }
    47. else
    48. {
    49. Bukkit.broadcastMessage(ChatColor.GRAY + "The game start in " + ChatColor.AQUA + n + ChatColor.GRAY + " second" + p + " !");
    50. n--;
    51. }
    52.  
    53. }
    54. else
    55. {
    56. Bukkit.broadcastMessage(ChatColor.GRAY + "The game started!");
    57. plugin.getServer().getScheduler().cancelTask(taskID);
    58. }
    59.  
    60. }
    61.  
    62. }
    63.  
    64. }, 0L, 20L);
    65.  
    66. }
    67.  
    68. }
    69.  


    Any help ?
     
  2. Offline

    St3venAU

    move int n = time; above public void run()
     
  3. Offline

    BillyGalbreath

Thread Status:
Not open for further replies.

Share This Page