Solved Countdown help

Discussion in 'Plugin Development' started by The Fancy Whale, Jun 25, 2014.

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

    The Fancy Whale

    For some reason startGame(); never fires
    Code:java
    1. countdown = 30;
    2. BukkitRunnable task = new BukkitRunnable() {
    3.  
    4. public void run(){
    5. for(Player p : Bukkit.getOnlinePlayers()){
    6. p.setLevel(countdown);
    7. }
    8. countdown--;
    9. if (countdown < 20 && countdown > 4){
    10. for (Player p : Bukkit.getOnlinePlayers()){
    11. p.playSound(p.getLocation(), Sound.NOTE_PLING, 4.0F, 0F);
    12. }
    13. }
    14. else if (countdown <= 4 && countdown >= 0){
    15. for (Player p : Bukkit.getOnlinePlayers()){
    16. p.playSound(p.getLocation(), Sound.SUCCESSFUL_HIT, 4.0F, 0F);
    17. }
    18. }
    19. else if (countdown == 0) {
    20. startGame();
    21. this.cancel();
    22.  
    23. }
    24. }
    25. };
    26. task.runTaskTimer(Main.getPlugin(), 0L, 20L);
     
  2. Offline

    BrennyMullan

    Your countdown == 0 will never run because you check if it equals 0 already with the > = 0​
     
    The Fancy Whale likes this.
  3. Offline

    spy_1134

    This block here will run if countdown == 0, because countdown <= 4 && countdown >= 0
    Code:java
    1. else if (countdown <= 4 && countdown >= 0){
    2. for (Player p : Bukkit.getOnlinePlayers()){
    3. p.playSound(p.getLocation(), Sound.SUCCESSFUL_HIT, 4.0F, 0F);
    4. }
    5. }
    6.  

    If the previous block of code runs, then this won't because this is set to run only if nothing else has: "else if". Just change it to if(countdown == 0) { ... }
    Code:java
    1. else if (countdown == 0) {
    2. startGame();
    3. this.cancel();
    4.  
    5. }
     
    The Fancy Whale likes this.
  4. Offline

    The Fancy Whale

    BrennyMullan spy_1134 Thanks for the help. Realized that right after I posted this and forgot to mark as solved.
     
  5. Offline

    BrennyMullan

    No problem
     
Thread Status:
Not open for further replies.

Share This Page