Solved Scoreboard kills cpu

Discussion in 'Plugin Development' started by glasseater, Jan 25, 2016.

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

    glasseater

    Hey guys,

    So I just noticed today that the performance in my new scoreboard just went down.

    I used to use this (THE PERFORMANCE WAS FINE)


    Code:
    final Score money = o.getScore("§bCoins");
                 money.setScore(SQL.getValue(p.getName(), "money"));
                 final Score deaths = o.getScore("§bDeaths");
                 deaths.setScore(SQL.getValue(p.getName(), "deaths"));
    Then I used this (THIS KILLS CPU):
    Code:
      final Score name = o.getScore(Bukkit.getOfflinePlayer("§c§lPlayer"));
                 final Score name2 = o.getScore(Bukkit.getOfflinePlayer("§7" + p.getName()));
                 final Score blank1 = o.getScore(Bukkit.getOfflinePlayer("§1"));
                 final Score kills = o.getScore(Bukkit.getOfflinePlayer("§c§lKills"));
                 final Score kills2 = o.getScore(Bukkit.getOfflinePlayer("§7" + SQL.getValue(p.getName(), "kills")));
                 final Score blank2 = o.getScore(Bukkit.getOfflinePlayer("§2"));
                 final Score deaths = o.getScore(Bukkit.getOfflinePlayer("§c§lDeaths"));
                 final Score deaths2 = o.getScore(Bukkit.getOfflinePlayer("§7" + SQL.getValue(p.getName(), "deaths")));
                 final Score blank3 = o.getScore(Bukkit.getOfflinePlayer("§3"));
                 final Score money = o.getScore(Bukkit.getOfflinePlayer("§c§lMoney"));
                 final Score money2 = o.getScore(Bukkit.getOfflinePlayer("§7" + SQL.getValue(p.getName(), "money")));
                 name.setScore(18);
                 name2.setScore(17);
                 blank1.setScore(15);
                 kills.setScore(14);
                 kills2.setScore(13);
                 blank2.setScore(12);
                 deaths.setScore(11);
                 deaths2.setScore(10);
                 blank3.setScore(9);
                 money.setScore(8);
                 money2.setScore(7);
                 p.setScoreboard(sb);
    I like the way the second one looks, but it kills performance it takes up 91% CPU. The first one used 20% CPU. Is there any way I can fix this? I would really like to use this one instead of the first.

    Thanks in advance!

    Glass
     
  2. Offline

    mythbusterma

    @glasseater

    If you're running this locally, you can see what is taking all the CPU by running a profiler on the application.
     
  3. Offline

    Zombie_Striker

    @glasseater
    Most likely it's the amount of times that bit of code runs. Can you post how the scorebored gets updated?
     
  4. Offline

    teej107

    @glasseater setting scoreboard shouldn't kill CPU. Your code is fine in terms of CPU usage. Btw you can get scores without an OfflinePlayer. Just use a String.
     
  5. Offline

    glasseater

    @teej107 @Zombie_Striker

    @mythbusterma I use a plugin called TopLite and the second scoreboard I used was using up the cpu. Also how can I use a string instead of an offlineplayer? I didn't know I could do that!
     
  6. Offline

    Zombie_Striker

    @glasseater
    Okay, but how does the scoreboard get updated? How many times in a second does it get updated? Do you run any other processes when setting the scoreboard?
     
  7. Offline

    glasseater

    @Zombie_Striker
    Well I created it in a method, so I call the method when a player gets killed, on death, on join, and on balance update.

    EDIT: Solved! Thanks for everyones help!
     
    Last edited: Jan 25, 2016
  8. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page