[HELP SCOREBOARD] Display a scoreboard only for one player

Discussion in 'Plugin Development' started by LordManegane, Jul 10, 2013.

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

    LordManegane

    Well, i just want to display separated scoreboards for each player, so only the player can see they score.

    Code:java
    1.  
    2. public class Core extends JavaPlugin implements Listener, CommandExecutor {
    3. public static Logger logger = Logger.getLogger("Minecraft");
    4. public final Accounts ac = new Accounts();
    5. ScoreboardManager manager = Bukkit.getScoreboardManager();
    6. Scoreboard board = manager.getNewScoreboard();
    7. Objective objective = board.registerNewObjective("points", "dummy");
    8. public static HashMap<String, Scoreboard> UsedScoreboard = new HashMap<String, Scoreboard>();
    9. public static HashMap<String, Score> puntosscore = new HashMap<String, Score>();
    10. Score puntos = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "POINTS" + ChatColor.GRAY + ":"));
    11.  
    12. public static List<UUID> spawnedMobs = new ArrayList();
    13.  
    14. @Override
    15. public void onDisable() {
    16.  
    17. PluginDescriptionFile pdfFile = this.getDescription();
    18. this.logger.info(pdfFile.getName() + " fue Deshabilidato!");
    19.  
    20. }
    21.  
    22. public void onEnable() {
    23.  
    24. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    25. objective.setDisplayName(ChatColor.DARK_RED+"POINTS");
    26. Score puntos = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Puntos" + ChatColor.GRAY + ":"));
    27. PluginManager pm = getServer().getPluginManager();
    28. PluginDescriptionFile pdf = this.getDescription();
    29. pm.registerEvents(this, this);
    30. getConfig().options().copyDefaults();
    31. saveConfig();}
    32.  
    33. public boolean onCommand(CommandSender sender, Command cmd,
    34. String commandLabel, String[] args) {
    35. Player player = (Player) sender;
    36. World mundo = player.getWorld();
    37. Location location = player.getLocation();
    38.  
    39.  
    40. return false;
    41.  
    42. }
    43. @EventHandler
    44. public void onJoin(PlayerJoinEvent e) {
    45. Player player = e.getPlayer();
    46. puntosscore.put(player.getName(), puntos);
    47. player.setScoreboard(board);
    48. UsedScoreboard.put(player.getName(), board);
    49. player.setScoreboard(UsedScoreboard.get(player.getName()));
    50. }
    51.  
    52. @EventHandler
    53. public void kill(EntityDeathEvent e){
    54. LivingEntity entity = e.getEntity();
    55. if(entity instanceof Zombie)
    56. if(!spawnedMobs.contains(e.getEntity().getUniqueId())){
    57. Player asesino = e.getEntity().getKiller();
    58. asesino.setScoreboard(manager.getNewScoreboard());
    59. asesino.setScoreboard(board);
    60. }else if(spawnedMobs.contains(e.getEntity().getUniqueId())){
    61. Player asesino = e.getEntity().getKiller();
    62.  
    63. Score score = objective.getScore(asesino);
    64. puntos.setScore(objective.getScore(asesino).getScore()-1);
    65. score.setScore(objective.getScore(asesino).getScore()-1);
    66.  
    67. asesino.setScoreboard(manager.getNewScoreboard());
    68. asesino.setScoreboard(board);
    69.  
    70. }
    71. }
    72.  
    73.  
    74.  
    75.  
    76. @EventHandler
    77. public void spawnEvent(CreatureSpawnEvent event) {
    78. if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) {
    79. spawnedMobs.add(event.getEntity().getUniqueId());
    80. }
    81. else if ((event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG)) {
    82.  
    83. spawnedMobs.add(event.getEntity().getUniqueId());
    84. } }
    85.  
    86.  
    87.  
    88. }
     
  2. Offline

    LinearLogic

    Code:java
    1. Scoreboard board1 = getServer().getScoreboardManager().getNewScoreboard(),
    2. board2 = getServer().getScoreboardManager().getNewScoreboard();
    3. player1.setScoreboard(board1);
    4. player2.setScoreboard(board2);

    Now you can register different Objectives and Scores with each board, and they will only display for the boards' respective players.
     
  3. Offline

    LordManegane

    LinearLogic I dont really know if you get it.

    I want something like this.
    PHOTO
    The same score but every player get diffrent values.
     
  4. Offline

    LinearLogic

    So you want one scoreboard, but players see only their own score values?
     
  5. Offline

    LordManegane

  6. Offline

    LinearLogic

    You won't be able to achieve that within the scope of the Bukkit API; scoreboards are global so you'll need one per player. Just map each player to a scoreboard with the "points" objective and "puntos" and "asesinados" scores you have above.
     
  7. Offline

    LordManegane

    LinearLogic I dont really know how to achive that, can you help me

    BUMP :p

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

    LinearLogic

    Just have a global HashMap<String, Scoreboard> that indexes scoreboards by player name. Have a method registerScoreboard(Player player) for generating a scoreboard for a player: the method gets a new scoreboard from the server's ScoreboardManager, adds an Objective and Score as you've done above, calls player.setScoreboard(...) and stores the player's name scoreboard as a key/value pair in the HashMap.
     
  9. Offline

    LordManegane

    LinearLogic Mmmmmmmmm i dont get it at all, can you give me an example?
     
Thread Status:
Not open for further replies.

Share This Page