Scoreboard Issues

Discussion in 'Plugin Development' started by ImpaTheImpaler, Aug 7, 2019.

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

    ImpaTheImpaler

    I am trying to create a scoreboard under a player's name which was display two variables - their health, and a bounty which is a custom feature on the server. The two issues I have at the moment - the scoreboard for some reason just has a 0 in front of the text under the name. (https://prnt.sc/opj2r0). Another issue is that instead of the scoreboard showing the player's data under their own name, it shows their data on everyone else's scoreboard. So if Player A has 58 health, it doesn't show 58 health under his name, but for him it shows 58 health under everyone else's name.

    Here is my code - and if anyone knows a really indepth video about scoreboards please link me as I have always struggled to get my head around it, it never seems to work for me. There is no error log as the code apparently runs but I have made a mistake somewhere in displaying the actual information.

    Code:
        public static void updatePlayerProfiles() {
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.instance, new Runnable() {
                public void run() {
                    for (Player pl : Bukkit.getOnlinePlayers()) {
                        if (!PlayerMechanics.player_profile.containsKey(pl)) {
                            ScoreboardManager manager = Bukkit.getScoreboardManager();
                            Scoreboard board = manager.getNewScoreboard();
                            Objective objective = board.registerNewObjective("board", "board");
                            objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
                            objective.setDisplayName(ChatColor.WHITE + "" + (int) pl.getHealth() + ChatColor.RED.toString() + "❤" + ChatColor.GRAY + " | " + ChatColor.GOLD + BountyFunctions.getBountyAmount(pl.getName()) +
                                    ChatColor.GOLD.toString() + " \u2694");
    
                            PlayerMechanics.player_profile.put(pl, board);
                            pl.setScoreboard(PlayerMechanics.player_profile.get(pl));
                        } else {
                            Scoreboard board = PlayerMechanics.player_profile.get(pl);
                            board.getObjective("board").setDisplayName(ChatColor.WHITE + "" + (int) pl.getHealth() + ChatColor.RED.toString() + "❤" + ChatColor.GRAY + " | " + ChatColor.GOLD + BountyFunctions.getBountyAmount(pl.getName()) +
                                    ChatColor.GOLD.toString() + " \u2694");
                            pl.setScoreboard(PlayerMechanics.player_profile.get(pl));
                            PlayerMechanics.player_profile.put(pl, board);
                        }
                    }
                }
            }, 1L, 1L);
        }
    Thanks.
     
  2. Offline

    ImpaTheImpaler

  3. Okay I would say the '0' is the scoreboard score but I neither know if the below_name really has a score nor how to remove it. But if it is the score you could set the score to the health and just add the heart at first place in the scoreboard displayname.

    And 2.: you have to loop over each player for each player, in other words you need 2 loops. The outer loop specifies who gets the scoreboard displayed an th inner loop selects the player whose health is going to be displayed.
     
Thread Status:
Not open for further replies.

Share This Page