Solved UHC Plugin - Countdown Timer doesnt work

Discussion in 'Plugin Development' started by VNGC, Mar 31, 2020.

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

    VNGC

    Hey, i am making a own Private-UHC plugin, and im using /start to start a timer from 60 secs down to 0, and then teleport all players randomly to the map, but the timer doesnt work how it should, i want it to be showed at 60 50 40 30 20 15 10 5 4 3 2 and 1 secs, but if its on 5, it goes down every second on 3, 1 and done. 4 and 2 are not showing. whats wrong?

    sry if its hard to read, i am german ;c

    heres my code part:
    Code:
    } else if (cmd.getName().equalsIgnoreCase("start")) {
                if (sender instanceof Player) {
                    if (sender.hasPermission("UHC.host")) {
    
                        StartUHC = Bukkit.getScheduler().scheduleSyncRepeatingTask(main.getPlugin(), new Runnable() {
    
                            int countdown = 60;
    
                            @Override
                            public void run() {
                                if (countdown <= 0) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Players get teleportet!");
                                    Bukkit.getScheduler().cancelTask(StartUHC);
                                    return;
                                }
                                if (countdown == 60) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 50) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 40) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 30) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 20) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 15) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 10) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 5) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 4) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 3) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 2) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                } else if (countdown == 1) {
                                    Bukkit.broadcastMessage(
                                            Data.Prefix + "§6Das Spiel beginnt in §b" + countdown + " Sekunden!");
                                    countdown--;
                                }
                                countdown--;
                            }
                        }, 0, 20);
    
                    }
                }

    and this is how it looks:

    upload_2020-4-1_5-20-41.png
     
  2. Offline

    bowlerguy66

    @VNGC It looks like you're subtracting from the countdown two times; either remove the countdown--; at the bottom or remove each countdown--; from every time you broadcast a message.
     
  3. Offline

    VNGC

    its working, ty! but why did it only affected the 4 and 2?

    and another question, how can i add the timer to the actionbar above the hotbar? is there an method something like "actionbar.set(countdown);" ?
     
    Last edited: Mar 31, 2020
  4. Offline

    bowlerguy66

    It only affected 4 and 2 because, after 5 seconds, you were printing each time a second went down. If you were to print out the timer each time before you fixed it, you would see that it would skip numbers each time.

    There's a library for using the ActionBar, but I'm not sure if it's out of date or working or anything. Try this
     
  5. Offline

    VNGC

    yeah, but how can i send the countdown? it looks like i cant send an int

    nvm got it. used String cdstring = String.ValueOf(countdown):

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
Thread Status:
Not open for further replies.

Share This Page