Solved Help with countdown

Discussion in 'Plugin Development' started by RainoBoy97, Jul 31, 2013.

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

    RainoBoy97

    Hello!

    I have a simple problem with a countdown here, it works fine but, when it comes to 1 it just skips it.

    Code:
    public static void startCounter(final int sec) {
    if (Bukkit.getOnlinePlayers().length >= 1) {
    new BukkitRunnable() {
    int count = sec;
    public void run() {
    if (count > 1 && count != 0) {
    if (count % 15 == 0) {
    Msg.broad("<green>Game starting in <red><b>" + count + " <green>seconds!");
    } else if (count <= 5 && count > 1) {
    Msg.broad("<green>Game starting in <red><b>" + count + " <green>seconds!");
    } else if (count == 1) {
    Msg.broad("<green>Game starting in <red><b>" + count + " <green>second!");
    }
    } else if (count == 0) {
    Msg.broad("<green><b>MATCH STARTING!");
    this.cancel();
    }
    count--;
    }
    }.runTaskTimer(BvZ.get(), 0L, 20L);
    }
    }
    
    Thanks!
     
  2. Offline

    adam753

    Your problem is this:
    Code:
    if (count > 1 && count != 0) {
            //Stuff
    } else if (count == 0) {
            //Other stuff
    
    When the count is 1, the top line will be FALSE, because 1>1 is false, So neither block of code will happen. I would suggest changing these two lines to this:
    Code:
    if (count != 0) {
            //Stuff
    } else {
            //Other stuff
    
    Which is much simpler.
     
  3. Offline

    RainoBoy97

    Oh thanks, that was a stupid mistake xD I see what I did wrong now ;)
     
Thread Status:
Not open for further replies.

Share This Page