Updating Scoreboard (Help!)

Discussion in 'Plugin Development' started by 123ang, Aug 8, 2014.

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

    123ang

    I've been stuck on this all day, searching around and haven't found anything; so I'm going to ask for help here :). I have my code where it's in a runnable and it's updating the player count objective every 1 second. When 1 person logs in and, another person is already on the server, the person who was already on the server gets a duplicate of the objective, and the player who just logged in is completely fine.

    Player That was already in when another person joined:
    [​IMG]

    Person that just logged in:
    [​IMG]


    See what I mean. I just don't know how to fix it :(.

    My Code:
    Code:java
    1. @EventHandler
    2. public void mainScoreboard(PlayerJoinEvent e){
    3.  
    4.  
    5. Player player = e.getPlayer();
    6.  
    7. ScoreboardManager manager = Bukkit.getScoreboardManager();
    8. final Scoreboard board = manager.getNewScoreboard();
    9.  
    10. final Objective objective = board.registerNewObjective("test", "dummy");
    11.  
    12.  
    13. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    14.  
    15.  
    16. objective.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + " Evolution ");
    17.  
    18. Score blank15 = objective.getScore(ChatColor.GREEN + "");
    19. blank15.setScore(15);
    20.  
    21. Score players = objective.getScore(ChatColor.YELLOW + "Players");
    22. players.setScore(14);
    23.  
    24. final Team white2 = board.registerNewTeam("white2");
    25. white2.setPrefix(ChatColor.WHITE + "");
    26.  
    27. final Team onlinep = board.registerNewTeam("");
    28.  
    29.  
    30. final Team maxp = board.registerNewTeam("maxp");
    31. maxp.setPrefix(white2.getPrefix() + Bukkit.getMaxPlayers());
    32.  
    33. new BukkitRunnable(){
    34. @SuppressWarnings("deprecation")
    35. public void run(){
    36.  
    37.  
    38. onlinep.setPrefix(white2.getPrefix() + Bukkit.getOnlinePlayers().length);
    39.  
    40. Score online = objective.getScore(onlinep.getPrefix() + "/16");
    41. online.setScore(13);
    42.  
    43. }
    44. }.runTaskTimer(this, 0, 20);
    45.  
    46. player.setScoreboard(board);
    47.  
    48.  
    49.  
    50.  
    51.  
    52.  
    53.  
    54.  
    55.  
    56. }


    Thanks for any help in advance!

    Anyone got any suggestions, anyone at all :(?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    xAstraah

  3. Offline

    xTigerRebornx

    123ang You never get rid of the old Score, meaning it will still be there when a new Player joins
     
  4. Offline

    123ang

    xTigerRebornx Okay, so how would I remove the old score?

    xAstraah Yes that was an extremely useful library, however, there is no way to update the scoreboard using that library. Unless you can find a way to do it :(.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    xAstraah

  6. Offline

    123ang

    RenegadeEagle xAstraah Yes, but I'm using the library, and the library doesn't like it when you use any type of runnable to set the score :(.
     
  7. If you look at the newer posts someone posted an update method.
     
  8. Offline

    123ang

  9. What doesn't work? Be a bit more specific :p
     
    GrandmaJam likes this.
  10. Offline

    123ang

    RenegadeEagle Like, I stick it in a runnable, and it doesn't update what so ever.
     
    GrandmaJam likes this.
  11. If it was me I would do scoreboard.getScoreBoard().resetScores(); and do it with the regular Bukkit API.
     
  12. Offline

    123ang

    RenegadeEagle what do you mean? Could you give me an example?
     
  13. Part of me is wishing you were not using that library.
    Scoreboards imo are the worst part of the bukkit api to work with. I'm not even sure who made this, but I remember seeing it in a skype chat and I just keep it book marked because I know the scoreboard works.
    https://github.com/unenergizer/MPMi.../com/minepile/mpmg/util/GameManager.java#L196
    Sorry for no credits to whoever made this. ;c
     
    GrandmaJam likes this.
  14. Offline

    123ang

    RenegadeEagle I have absolutely no idea how to use that, and all of it hooks into other classes.
     
  15. Offline

    123ang

    Nothing?
     
Thread Status:
Not open for further replies.

Share This Page