Solved Problem when running multiple countdowns.

Discussion in 'Plugin Development' started by PatoTheBest, Feb 26, 2014.

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

    PatoTheBest

    When the timer is running for one arena it works perfectly, but when the timer cancels itself, it conflicts with other timers.
    Code:java
    1. public static void startGame(final int seconds1, final Arena arena) {
    2. if (!arena.runningCountdown() && arena.getPlayers().size() >= arena.getMinPlayers()){
    3.  
    4. seconds = seconds1;
    5.  
    6. arena.setRunningCountdown(true);
    7.  
    8. arena.setTaskID(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(TNTTag.main, new Runnable(){
    9. public void run() {
    10. if (timesToBoradcast.contains(seconds)){
    11. MessageManager.getInstance().sendInGamePlayersMessage(
    12. ChatColor.YELLOW + "" + seconds + ((seconds == 1) ? " second" : " seconds") + " until the game starts!", arena);
    13. }
    14.  
    15. for (String p : arena.getPlayers()){
    16. Player player = Bukkit.getPlayer(p);
    17. player.setLevel(seconds);
    18. arena.setBoard(player, seconds);
    19. }
    20.  
    21. if (seconds == 0){
    22. Bukkit.getScheduler().cancelTask(arena.getTaskID());
    23.  
    24. arena.setInGame(true);
    25.  
    26. Location loc = arena.getArenaLocation();
    27.  
    28. for (String p : arena.getPlayers()){
    29. Player player = Bukkit.getPlayer(p);
    30. player.teleport(loc);
    31. }
    32.  
    33.  
    34. MessageManager.getInstance().sendInGamePlayersMessage(ChatColor.YELLOW + "The TNT has been released!", arena);
    35.  
    36. pickRandomTNT(arena);
    37.  
    38. startRound(arena);
    39.  
    40. }
    41.  
    42. seconds--;
    43. }
    44. }
    45. , 20, 20L));
    46. }
    47. }




    The Countdown Class: https://github.com/PatoTheBest/TNTT...rg/pato/tnttag/managers/CountdownManager.java
    The Arena Class: https://github.com/PatoTheBest/TNTTag-TheMinigame/blob/master/src/org/pato/tnttag/util/Arena.java
    Full GitHub Code: https://github.com/PatoTheBest/TNTTag-TheMinigame

    seconds=seconds1;
    wasn't set for each arena, I feel dumb.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page