Need help with fixing scoreboard lagg

Discussion in 'Spigot Plugin Development' started by MichaelP, May 6, 2015.

  1. Hey if i update my scoreboard it makes lagg
    i know its getOfflinePlayer but i don't know how to use it without that please help code:
    gemsnumber.addPlayer(Bukkit.getOfflinePlayer(ChatColor.BLUE.toString()));
     
  2. gigosaurus

    Supporter

  3. it don't work:
    gemstext.addPlayer(addEntry(ChatColor.RED.toString()));
     
  4. gigosaurus

    Supporter

    No. AddEntry is a method of Team, so it would be like this:
    Code (Java):
    gemstext.addEntry(ChatColor.RED.toString());
     
  5. @MichaelP you need to call addEntry on gemstext, and remove addPlayer.
     
  6. Thanks i try :D
     
  7. i did that but the lagg is not fixed :(
    My full script http://pastebin.com/9MEdnxKQ
     
  8. Scoreboard lag so it's off sync or like server lag?
    I can't seem to get scoreboard to sync with a timer I run on the server.
     
  9. if the scoreboard is enabled players lagg if its disabled then do players not lagg
     
  10. Easiest thing to do would to buy the Featherboard plugin, But in this case, the
    PHP:
    gemstext.addEntry(ChatColor.BLUE.toString());
    If that doesnt work, i think its something in your run() method.
     
  11. Can u help me with that becuz i'm not the best scripter xd
     
  12. gigosaurus

    Supporter

    It's quite easy to see where the problem is. You're running socket.connect on the main thread 4 times a second for each player...
    Also don't annotate @SuppressWarnings unless you know what you are doing. The warning you ignored there was telling you that you're not closing the socket or streams after use, which is potentially a huge memory leak.

    To fix: run the socket code in an async scheduler (make sure to close it all afterwards) and then inside that have a synchronized task which runs all the scoreboard code (because you should only use the Bukkit API on the main server thread).
     
  13. Ow yes LOL! that are tons of connections do i think.
    Can u please help me with the async scheduler?
     
  14. gigosaurus

    Supporter

    Replace .runTaskTimer with .runTaskTimerAsynchronously on line 193 (going by the pastebin line numbers).
    Add socket.close() out.close() in.close() at line 160 (or if you're using jdk 1.7, look up how to use try-with-resources).
    Then surround the rest of the code you have inside the BukkitRunnable with a new BukkitRunnable .runTask()
     
  15. A new BukkitRunnable for the setPrefix lines?
     
  16. gigosaurus

    Supporter

    and the obj.setDisplayName line, as that is also part of the Bukkit API.
     
  17. Can u make an axample?
     
  18. Now is it no longer updating :(
     
  19. I am pretty sure you do not need to get the amount of players on the server 4 times per second for each player, start a timer as soon as the server starts(onEnable()) and make it calculate the amount of players online and store it into a integer.
     
  20. Thats true! Thanks