Solved Timer with Scheduler help!

Discussion in 'Plugin Development' started by Irantwomiles, Mar 26, 2015.

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

    Irantwomiles

    Im so confused right now. I've set up this scheduler which is just a regular int set equal to zero and every second it adds 1 to it. But when I have 2 players on the server it adds 2 and when theres 3 players on it adds 3 and on and on. I really dont know why this is happening. Any help would be greatly appreciated! heres code to my Scheduler.

    Code:
    public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this , new Runnable() {
                @SuppressWarnings("deprecation")
                @Override
                public void run() {
                    for(Player p : Bukkit.getOnlinePlayers()) {
                       
                        second += 1;
                        setupScoreboard(p);
                       
                       
                    }
                }
            }, 0, 20);
        }
     
  2. Offline

    ark9026

    Line 8, you get all online players, meaning it adds 1 for every person online. You don't need the online players, you can use a regular player system, but I won't just spoonfeed the code into your hands.
     
  3. Offline

    Irantwomiles

    @ark9026 thanks for the reply, and whats with this "Spoonfeeding" thing going on lately. It was just a question I didnt ask for code.
     
  4. Invisible

    nverdier

    @Irantwomiles Well a lot of people want the code, and we have learned to say that straight up so the OP doesn't expect it.
     
  5. Offline

    Irantwomiles

    @ark9026 Thanks that did the job, If someone else is having the same issue this is what I did.

    Code:
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this , new Runnable() {
                @SuppressWarnings("deprecation")
                @Override
                public void run() {
                    for(Player p : Bukkit.getOnlinePlayers()) {
                        setupScoreboard(p);
                    }
                    second += 1;
                }
            }, 0, 20);
        }
    just moved the second += 1; outside of the for loop. Thanks again ark

    @nverdier I understand, but lately everything I posted its always someone saying "im not gonna spoon feed you code" like I didnt ask for any code. I just wanted someone who is better than me to give me some advice on how I could improve. But Thanks to ark9026 I fixed it so I'll just change this to solved!
     
    Last edited by a moderator: Mar 26, 2015
  6. Invisible

    nverdier

    @Irantwomiles He did give you advice. And he told you he wasn't going to spoonfeed. Glad it's solved :D
     
  7. Offline

    Irantwomiles

    @nverdier ya thats why I still thanked him! Well anyways gl
     
  8. Offline

    ark9026

Thread Status:
Not open for further replies.

Share This Page