Solved Scoreboards per player?

Discussion in 'Plugin Development' started by HeyAwesomePeople, Sep 2, 2013.

Thread Status:
Not open for further replies.
  1. Hello. Is it possible to show a scoreboard per player? I am using this code currently but it doesn't show per player. It shows the scoreboard of the last player it loops through to everyone online.
    Code:
    Code:java
    1. public void updateScoreboard() {
    2. ScoreboardManager manager = Bukkit.getScoreboardManager();
    3. Scoreboard board = manager.getNewScoreboard();
    4. Objective objective = board.registerNewObjective("stats", "dummy");
    5. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    6.  
    7. objective.setDisplayName("" + ChatColor.BOLD + ChatColor.BLACK + "["
    8. + ChatColor.DARK_RED + "SurvivorZ" + ChatColor.BOLD
    9. + ChatColor.BLACK + "]");
    10.  
    11. Score pKills = objective.getScore(Bukkit.getOfflinePlayer(""
    12. + ChatColor.GREEN + "Player Kills"));
    13.  
    14. Score zKills = objective.getScore(Bukkit.getOfflinePlayer(""
    15. + ChatColor.GREEN + "Zombie Kills"));
    16.  
    17. Score deaths = objective.getScore(Bukkit.getOfflinePlayer(""
    18. + ChatColor.GREEN + "Deaths"));
    19. Score money = objective.getScore(Bukkit.getOfflinePlayer(""
    20. + ChatColor.YELLOW + "[Unused] Money"));
    21. // TODO Use BitCoins to show money
    22. for (Player player : Bukkit.getOnlinePlayers()) {
    23. pKills.setScore(getIcConfig().getInt(
    24. "Players." + player.getName() + ".playerKills"));
    25. zKills.setScore(getIcConfig().getInt(
    26. "Players." + player.getName() + ".zombieKills"));
    27. deaths.setScore(getIcConfig().getInt(
    28. "Players." + player.getName() + ".deaths"));
    29. money.setScore(0);
    30. player.setScoreboard(board);
    31. }
    32. }

    How would I make a scoreboard per player?
    Thanks in advance.
     
  2. Offline

    Drkmaster83

    I'm pretty sure you'd create the Scoreboard in the for-loop, and set all options according to data that you derive from "player." Else, it would just set the same scoreboard for everyone online.
     
  3. Offline

    chasechocolate

    I would add a Player parameter to that method, and then loop through online players and call that method.
     
  4. Offline

    Drkmaster83

    A parameter is the thing in the parentheses. You provide it when calling a method. I'm assuming chasechocolate meant to:
    Code:
    for(Player p : Bukkit.getOnlinePlayers)
    {
      updateScoreboard(p);
    }
    
    After making modifications to the method.
     
  5. Drkmaster83
    I am confused, sorry, very new to scoreboards. I update the scoreboard every 100 ticks. So this is my new setup:
    Every 100 ticks I do this(repeating task):
    Code:java
    1. for (Player player : Bukkit.getOnlinePlayers()) {
    2. updateScoreboard(player);
    3. }

    Then this is updateScoreboard:
    Code:java
    1. public void updateScoreboard(Player player) {
    2. ScoreboardManager manager = Bukkit.getScoreboardManager();
    3. Scoreboard board = manager.getNewScoreboard();
    4. Objective objective = board.registerNewObjective("stats", "dummy");
    5. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    6.  
    7. objective.setDisplayName("" + ChatColor.BOLD + ChatColor.BLACK + "["
    8. + ChatColor.DARK_RED + "SurvivorZ" + ChatColor.BOLD
    9. + ChatColor.BLACK + "]");
    10.  
    11. Score pKills = objective.getScore(Bukkit.getOfflinePlayer(""
    12. + ChatColor.GREEN + "Player Kills"));
    13.  
    14. Score zKills = objective.getScore(Bukkit.getOfflinePlayer(""
    15. + ChatColor.GREEN + "Zombie Kills"));
    16.  
    17. Score deaths = objective.getScore(Bukkit.getOfflinePlayer(""
    18. + ChatColor.GREEN + "Deaths"));
    19. Score money = objective.getScore(Bukkit.getOfflinePlayer(""
    20. + ChatColor.YELLOW + "[Unused] Money"));
    21. // TODO Use BitCoins to show money
    22. pKills.setScore(getIcConfig().getInt(
    23. "Players." + player.getName() + ".playerKills"));
    24. zKills.setScore(getIcConfig().getInt(
    25. "Players." + player.getName() + ".zombieKills"));
    26. deaths.setScore(getIcConfig().getInt(
    27. "Players." + player.getName() + ".deaths"));
    28. money.setScore(0);
    29. player.setScoreboard(board);
    30. }

    Is that right?
     
  6. chasechocolate Drkmaster83
    Is that right? Right now it only shows my scoreboard(First scoreboard to be made) and other players scoreboards are blank with no numbers just the names(deaths, Playerkills, Zombiekills ect.)
     
  7. Offline

    Drkmaster83

    I'm not sure, it seems like it should be working... Could it have to do with the fact that you're getting Bukkit.getOfflinePlayer(""?
     
  8. Drkmaster83 chasechocolate
    I got it to work. For some reason one player was just having trouble seeing the numbers.
    Thanks for everything! :)
     
  9. Offline

    fish_boss

    Could you paste the working code so that others can learn from it :)
     
    Snipey likes this.
Thread Status:
Not open for further replies.

Share This Page