Bar XP CountDown

Discussion in 'Plugin Development' started by Mathie, Feb 5, 2016.

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

    Mathie

    Hi :)

    I still have a little problem.
    I try to do a little countdown on the exp bar of the game. I put in a run () function.

    The function brings up to date the level but only when the program exits the run function, I do not understand ...

    Code:
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                public void run() {
    
                    for(int i = 10; i>0; i--){
                        for(Player p : Bukkit.getOnlinePlayers()) {
                           
                            System.out.println(i);
                           
                            if (online != 1) {
                                break;
                            }
                           
                            if (i < 6 && i > 0) {
                                sendTitle(p, Integer.toString(i), "", 5, 10, 5);
                            }
    
                            p.setLevel(i);
    
                            try {
                                Thread.sleep(1000);   
                            } catch(InterruptedException ex) {
                                Thread.currentThread().interrupt();
                            }
                        }
                    }
                }
               
            }, 20L);
    Thanks :)
     
  2. Offline

    adam753

    scheduleSyncDelayedTask doesn't run on another thread, as far as I know, so using Thread.sleep like that is just going to stall your main thread for 10 seconds. You should look up scheduleSyncRepeatingTask instead.
     
Thread Status:
Not open for further replies.

Share This Page