Refreshing Scoreboard Under Name

Discussion in 'Plugin Development' started by MineStein, Jul 31, 2014.

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

    MineStein

    Hey guys! I was playing around with scoreboards underneath the player's name. Now, all I need to do is refresh the scoreboard every time the player gets hit. How would I go about refreshing it?

    Here is an example of my problem:
    [​IMG]

    This scoreboard is meant to display the player's health below their name. It only updates after a reload.

    I was following the tutorial by chasechocolate, here is my code:

    Code:java
    1. ScoreboardManager manager = Bukkit.getScoreboardManager();
    2. Scoreboard board = manager.getNewScoreboard();
    3.  
    4. Objective objective = board.registerNewObjective("health", "dummy");
    5. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    6. objective.setDisplayName("§7/ §r20");
    7.  
    8. for(Player online : Bukkit.getOnlinePlayers()){
    9. Score score = objective.getScore(online);
    10. score.setScore((int) online.getHealth()); //Example
    11. }
    12.  
    13. for(Player online : Bukkit.getOnlinePlayers()){
    14. online.setScoreboard(board);
    15. }
     
  2. Offline

    mazentheamazin

    MineStein
    Well, since you're using it as a dummy we have to listen for when a player gets damaged by using EntityDamageEvent; create a new listener for said event. You should then do this:
     
  3. Offline

    MineStein

    mazentheamazin Ok thanks, I will try it out.

    mazentheamazin I need to access it from a separate class. The objective can't be static. Sorry, I am kind of new to the scoreboard.

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

    xTigerRebornx

  5. Offline

    MineStein

    xTigerRebornx I am so sorry, I am lost. I'll read the documentation.
     
  6. Offline

    mazentheamazin

Thread Status:
Not open for further replies.

Share This Page