How to set scoreboard, for my code ;/

Discussion in 'Plugin Development' started by bfgbfggf, May 5, 2013.

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


    I have problem with set scoreboard.
    I have that code (That code is from one of many test)
    But only sidebar work, A testing everything... and always only sidebar works fine, other show a wrong score.
    Side bar must show for every player, score of that player.
    Player list must show score of every online player
    and this same with below nickname.

    But in my code player see only own score in Playerlist, other player have "0", And see own score below every nick.

    How to write that? ;/


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


    To get the type, use getType() from org.bukkit.entity.Entity, and to check if it's a baby, use getAge() from org.bukkit.entity.Ageable.
    bfgbfggf likes this.
  3. Offline


    ach... I just try to use EntityType... :D Ok one problem solved :p thanks
    But sill is second ;/
  4. Offline


    Sorry, I haven't worked with scoreboards before.
  5. Offline


  6. Offline


    Tzeentchful seems to know all about scoreboards if you have a problem with them maybe give him a buzz :)
  7. Offline


  8. Offline


    You creating more than one scoreboard for each player. The scoreboard object contains all the different objectives inside of it, so you only need to create one scoreboard and put all objectives in it and send it to all the players. Though this may not work if you want to change the sidebar for the specific player. If you wanted to do that then you would have have to create a new scoreboard for each player (not for each objective like you have done) and put it in a list and loop though them and update each one.
    bfgbfggf likes this.
  9. Offline


    Ok, big thanks. you are a genius :p. But I have problem with that sidebar, can you make simply example?
  10. Offline


    Here I quickly wrote a class to handle what you want to do. Remember to unregister the player from the map when they logout!

    2. /* Holds the scoreboard for each player. The key is the
    3. * players name and the value is their associated scoreboard. */
    4. private Map<String, Scoreboard> playerScoreboards = new HashMap<String, Scoreboard>();
    6. /* constructs new Scoreboard for a player and puts it
    7. * in the HashMap.*/
    8. public void register(Player player) {
    9. Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    10. Objective side = scoreboard.registerNewObjective("side", "dummy");
    11. // Add your items to the sidebar here
    12. side.setDisplaySlot(DisplaySlot.SIDEBAR);
    14. Objective list = scoreboard.registerNewObjective("list", "dummy");
    15. // Add all the items for the player list here
    16. list.setDisplaySlot(DisplaySlot.PLAYER_LIST);
    18. Objective name = scoreboard.registerNewObjective("name", "dummy");
    19. // Add all the items for below player names
    20. name.setDisplaySlot(DisplaySlot.BELOW_NAME);
    22. playerScoreboards.put(player.getName(), scoreboard);
    23. player.setScoreboard(scoreboard);
    24. }
    26. /* Call this from the player quit event. If you don't it will
    27. * cause nasty memory leaks! */
    28. public void unregister(String player) {
    29. playerScoreboards.remove(player);
    30. }
    32. /* This method will change a value for all players registered. */
    33. public void changeAll(DisplaySlot slot, OfflinePlayer scoreName, int value ) {
    34. for(Scoreboard current : playerScoreboards.values()) {
    35. current.getObjective(slot).getScore(scoreName).setScore(value);
    36. }
    37. }
    39. /* This will change a score for a specific player. */
    40. public void changeSingle(String player, DisplaySlotslot, OfflinePlayer scoreName, int value ) {
    41. if(playerScoreboards.containsKey(player)) {
    42. Scoreboardscoreboard = playerScoreboards.get(player);
    43. scoreboard.getObjective(slot).getScore(scoreName).setScore(value);
    44. }
    46. }
    CubieX, bfgbfggf and xGhOsTkiLLeRx like this.
  11. Offline


    Ok I try that. but how to set different Display name for every player?

    from old code:
    String DisName = players.getString("UseRank");
    sideBar.setDisplayName(ChatColor.WHITE + DisName);

    Just get objective form
    public void changeSingle
    and use .setDisplayName ? :D

    And... it's possible to turn off sorting from highest to lowest score?
  12. Offline


    Just do it in the register method.
    1. Objective side = scoreboard.registerNewObjective("side", "dummy");
    2. // Add your items to the sidebar here
    3. side.setDisplaySlot(DisplaySlot.SIDEBAR);
    4. side.setDisplayName("Your string here")

    And no, it's imposible. The sorting is handled client side.
Thread Status:
Not open for further replies.

Share This Page