Countdown won't start

Discussion in 'Plugin Development' started by mickedplay, Mar 20, 2014.

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

    mickedplay

    If a player join, the countdown won't start. What did I wrong?
    In the command /ctf join I added:
    Code:java
    1. {
    2. Game.startGame();
    3. }


    Code:java
    1. public static void startGame()
    2. {
    3. if(CTF.status.getStatus() == 2)
    4. {
    5. if(CTF.playersInLobby.size() >= 2 && CTF.isLobbyToGameCountdownActive == false)
    6. {
    7. CTF.isLobbyToGameCountdownActive = true;
    8. Bukkit.getScheduler().scheduleSyncRepeatingTask(CTF.getInstance(), new Runnable()
    9. {
    10. @Override
    11. public void run()
    12. {
    13. Game.countdown--;
    14. if(Game.countdown == 30)
    15. {
    16. for(Player playersInLobby : CTF.playersInLobby)
    17. {
    18. playersInLobby.sendMessage(CTF.prefix + "Spiel startet in: " + "&6" + Game.countdown);
    19. }
    20. }
    21. if(Game.countdown == 20)
    22. {
    23. for(Player playersInLobby : CTF.playersInLobby)
    24. {
    25. playersInLobby.sendMessage(CTF.prefix + "Spiel startet in: " + "&6" + Game.countdown);
    26. }
    27. }
    28. if(Game.countdown < 11 && Game.countdown != 0)
    29. {
    30. for(Player playersInLobby : CTF.playersInLobby)
    31. {
    32. playersInLobby.sendMessage(CTF.prefix + "Spiel startet in: " + "&6" + Game.countdown);
    33. }
    34. }
    35. if(Game.countdown == 0)
    36. {
    37. Bukkit.getScheduler().cancelTask(Game.countdown);
    38. for(Player playersInLobby : CTF.playersInLobby)
    39. {
    40. playersInLobby.sendMessage(CTF.prefix + "Spiel endet in 10 Minuten!");
    41. }
    42. Status.GAME.setStatus();
    43. Player p = (Player) CTF.playersInLobby;
    44. ChooseClass.classContents();
    45. if(CTF.teamRed.contains(p))
    46. {
    47. String world = cfg.getString("RedSpawn.world");
    48. double x = cfg.getDouble("RedSpawn.x");
    49. double y = cfg.getDouble("RedSpawn.y");
    50. double z = cfg.getDouble("RedSpawn.z");
    51. double yaw = cfg.getDouble("RedSpawn.yaw");
    52. double pitch = cfg.getDouble("RedSpawn.pitch");
    53.  
    54. Location redSpawn = new Location(Bukkit.getWorld(world), x, y, z);
    55. redSpawn.setYaw((float) yaw);
    56. redSpawn.setPitch((float) pitch);
    57. p.teleport(redSpawn);
    58. }
    59. else if(CTF.teamBlue.contains(p))
    60. {
    61. String world = cfg.getString("BlueSpawn.world");
    62. double x = cfg.getDouble("BlueSpawn.x");
    63. double y = cfg.getDouble("BlueSpawn.y");
    64. double z = cfg.getDouble("BlueSpawn.z");
    65. double yaw = cfg.getDouble("BlueSpawn");
    66. double pitch = cfg.getDouble("BlueSpawn.pitch");
    67.  
    68. Location blueSpawn = new Location(Bukkit.getWorld(world), x, y, z);
    69. blueSpawn.setYaw((float) yaw);
    70. blueSpawn.setPitch((float) pitch);
    71. p.teleport(blueSpawn);
    72. }
    73. runGame();
    74. }
    75. }
    76. }, 0L, 20L);
    77. }
    78. }
    79. }

    Unfortunately there's no error message in the console.
    Thanks!
     
  2. Offline

    StealerSlain

    I don't think you need to put
    Code:java
    1. if(Game.countdown == 30)

    in run method
     
  3. Offline

    GameplayJDK

    mickedplay
    When it just doesn't start, the condition of the if statements are not true.
     
  4. Offline

    Noxyro

    mickedplay As an established german project-structure doctor, I highly recommend to you the new medicine "extracted methods" for your Runnable and "constant variables" for your if compares.
    I also prescribe you a "comment" therapy.

    Now to your problem:
    I dont know what's outside your startGame() method, but are you actually adding the players that typ /ctf join to the CTF.playersInLobby ? Else the statement CTF.playersInLobby.size() >= 2 will never become true and therefore the game would never start. Also i don't know what your CTF.status.getStatus() stands for and where it is set.

    Greetings - Noxyro

    Edit 1: Oh! And also you're casting CTF.playersInLobby to Player in line 43, but as i can read from your if statement in line 5 CTF.playersInLobby is some sort of Collection like an ArrayList or a HashMap, so casting it directly to Player will produce an error.
     
Thread Status:
Not open for further replies.

Share This Page