Scoreboard

Discussion in 'Plugin Development' started by Jalau, Jan 4, 2014.

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

    Jalau

    Hello guys i have a problem with a scoreboard, i want every player to have a hp score under their name and the players that are in a party to have a sidebar scoreboard, but the hp scoreboard seems to bug, it shows 0 HP and sometimes it works but as soon as i open a party everyone has 0 again and the hp seems to jump to the real and back to 0....
    My Code (calling it on every damage):
    Code:
        public static void updateScore() {
            for(final Player onlines : Bukkit.getOnlinePlayers()) {
                final Scoreboard board = manager.getNewScoreboard();
            //Party
            if(PartyManager.getManager().hasParty(onlines)) {
                Objective objectives = board.registerNewObjective("Debug", "dummy"); 
                objectives.setDisplaySlot(DisplaySlot.SIDEBAR);
                  objectives.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Party");;
                  Party party = PartyManager.getManager().getParty(onlines);
                  for(Player member : party.getPlayers()) {
                      String name = member.getName();
                      if(name.length() > 13) {
                          name = name.substring(0, 12);
                      }
                      Score spacer = objectives.getScore(Bukkit.getOfflinePlayer("§5" + name));   
                      if(party.getOwner().getName().equalsIgnoreCase(member.getName()))
                          spacer = objectives.getScore(Bukkit.getOfflinePlayer("§5§l" + name));   
               
                  spacer.setScore((int) member.getHealth());
                  }
            }
              plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
              {
                public void run() {
                    //Health
                    Objective objective = board.registerNewObjective("Leben", "dummy");
                    objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
                    objective.setDisplayName(ChatColor.RED + "\u2764");
                    onlines.setScoreboard(board);
                    onlines.setHealth(onlines.getHealth());
                   
                    }
                  }, 5L);
            }
               
              plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
              {
                public void run() {
                    for(Player player : Bukkit.getOnlinePlayers())
                        player.setHealth(player.getHealth());
                   
                    }
                  }, 5L);
                }
     
  2. When you set the criteria of an objective to "dummy" you have to manage the score or value by yourself, it won't get assigned automatically. In your case you should set the criteria to "health" so it will always display the health of the player.
     
  3. Offline

    PhilipsNostrum

    Why do you set their health to hm, their health? I'm confused
    Code:
    onlines.setHealth(onlines.getHealth());
    And you don't need to run the health score stuff in a task, and I'm pretty sure the task with the for loop that does player.setHealth(player.getHealth()); is useless.

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

    Jalau

    It says that in the thread to update the health of the players...
    https://forums.bukkit.org/threads/tutorial-scoreboards-teams-with-the-bukkit-api.139655/

    kumpelblase2
    Also already tried that same result....

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

Share This Page