Solved Player belowname scoreboard

Discussion in 'Plugin Development' started by Erall, Oct 25, 2013.

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

    Erall

    Hi,

    I'm working on a plugin and I need to set for each player a value under their names.
    This value is already shown on a scoreboard in the side of the screen, but I would like to set it also under their names.
    By example :
    Player kills on the right side of the screen, and below the same player's head.
    The question is, do I have to use the same scoreboard, or should I create a new one, with another objective ?
     
  2. Offline

    chasechocolate

    Same scoreboard, but create a new objective with the below name display slot.
     
  3. Offline

    Erall

    I thought about it again in the afternoon, and maybe I didn't explain me well.
    Here's what I'm doing :
    Code:java
    1. public void updateScoreBoard(Player player, int score){
    2. if (!playerScoreBoards.containsKey(player))
    3. {
    4. playerScoreBoards.put(player, manager.getNewScoreboard());
    5. board = playerScoreBoards.get(player);
    6. sidescore = board.registerNewObjective("score" , "dummy");
    7. headscore = board.registerNewObjective("headscore" , "dummy");
    8. }
    9. board = playerScoreBoards.get(player);
    10.  
    11. updateHeadBar(player, score);
    12. updateSideBar(player, score);
    13. player.setScoreboard(board);
    14. }
    15.  
    16. private void updateHeadBar(Player player, int score)
    17. {
    18. headscore = board.getObjective("headscore");
    19. headscore.setDisplaySlot(DisplaySlot.BELOW_NAME);
    20. headscore.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:")).setScore(score);
    21. }

    My side pannel is working well it's why I don't show it.
    But when I'm doing this, it shows the score badly, and under all the others players except the one I want to have it.

    Any help ?

    [Edit] Waoh, sent in the same time ><

    Okay I fixed it, thanks to people on IRC
    Code:java
    1. public void updateScoreBoard(Player player, int score){
    2. if (!playerScoreBoards.containsKey(player))
    3. {
    4. playerScoreBoards.put(player, manager.getNewScoreboard());
    5. board = playerScoreBoards.get(player);
    6. //Side pannel
    7. sidetime = board.registerNewObjective("pannel" , "dummy");
    8. sidetime.setDisplayName("§eYour score");
    9. sidetime.setDisplaySlot(DisplaySlot.SIDEBAR);
    10.  
    11. //Below head score
    12. headtime = board.registerNewObjective("headscore" , "dummy");
    13. headtime.setDisplayName(ChatColor.GREEN + "s");
    14. headtime.setDisplaySlot(DisplaySlot.BELOW_NAME);
    15. }
    16. board = playerScoreBoards.get(player);
    17.  
    18. headtime = board.getObjective("headscore");
    19. sidetime = board.getObjective("pannel");
    20.  
    21. sidetime.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Score:")).setScore(score);
    22. for(Player online : Bukkit.getOnlinePlayers()){
    23. if(online.getLocation().distance(player.getLocation()) <= 50)
    24. headtime.getScore(online).setScore(mynewscore);
    25. }
    26. player.setScoreboard(board);
    27. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page