TagAPI

59 - Scoreboard bellow name

I dont know where i can write this so i wrote it here.

Some peoples have problem with scoreboard bellow name. I solved this problem :D Here is my code:

Listener:

@EventHandler
public void onName(PlayerReceiveNameTagEvent event){
    event.setTag(MainClass.getTag(event.getPlayer(), event.getNamedPlayer()));
}

Scoreboard setter:

Scoreboard sb = player.getScoreboard();
if(sb == null)
	sb = Bukkit.getScoreboardManager().getNewScoreboard();
Objective o1 = sb.getObjective("health");
if(o1 == null){
	o1 = sb.registerNewObjective("health", "dummy");
	o1.setDisplaySlot(DisplaySlot.BELOW_NAME);	
	o1.setDisplayName("hp");
}
			
for(Player online : Bukkit.getOnlinePlayers()){
    String name = online.getName();
        if(Bukkit.getPluginManager().isPluginEnabled("TagAPI")){
	    char[] prename = MainClass.getTag(player, online).toCharArray();
	    name = "";	
	    for(int i=0;i<Math.min(16, prename.length); i++){ // when we send longer name client will disconnect
	        name = name + prename[i];
	    }
	}
    o1.getScore(Bukkit.getOfflinePlayer(name)).setScore(online.getHealth()); // set your score :D
}

MainClass:

public static String getTag(Player player, Player namedplayer){
    return ChatColor.RED + namedplayer.getName(); // I only change players' color
}

It works very good but ther is one problem - only dummy criteria works :/ When you want to show health you have to use: o1.getScore(Bukkit.getOfflinePlayer(name)).setScore(online.getHealth());


@mbaxter
please add this to your tag tutorial

Sorry for my English.

User When Change
mbaxter Jul 27, 2013 at 01:00 UTC
kamcio96 Jul 19, 2013 at 13:23 UTC Create

You must login to post a comment. Don't have an account? Register to get one!

  • 1 comment
  • Avatar of mbaxter mbaxter Jul 27, 2013 at 01:01 UTC - 0 likes

    This is a hacky fix that breaks plugins relying on the scoreboard for various information.

    www.joe.to Gaming Community - Over a decade of fun!

    Four Minecraft servers, four TF2 servers, CSS and Garry's Mod.

    http://forums.joe.to

  • 1 comment

Facts

Last updated
Jul 27, 2013
Reported
Jul 19, 2013
Status
Declined - We decided not to take action on this ticket.
Type
Other - Some other kind of issue
Priority
Medium - Normal priority.
Votes
0

Reported by

Possible assignees