Last active
January 4, 2022 22:16
-
-
Save zkingboos/0badd6f20183ff9e5e5edc6b2d2637b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Tag { | |
private final Scoreboard scoreboard = new Scoreboard(); //you can use one for the nametag, no need to create other | |
public ScoreboardTeam getOrCreateNewTeam(String name) { | |
final ScoreboardTeam team = scoreboard.getTeam(name); | |
return team != null | |
? team | |
: scoreboard.createTeam(name); | |
} | |
public void updateNmsPlayerTag(Player player) { | |
String name = player.getName(); | |
name = name.length() > 15 | |
? name.substring(0, 15) | |
: name; | |
final ScoreboardTeam scoreboardTeam = getOrCreateNewTeam( | |
String.format("%s%s", | |
"a", //the priority on the tablist, "a" = 0, "b" = 1 bla bla bla | |
name | |
) | |
); | |
scoreboardTeam.setPrefix(getSafetyName("Tag do time")); | |
scoreboardTeam.setSuffix(getSafetyName("suffix do time")); | |
final Collection<String> playerNameSet = scoreboardTeam.getPlayerNameSet(); | |
if(!playerNameSet.contains(player.getName())) { | |
playerNameSet.add(player.getName()); //ADD PLAYER TO SCOREBOARD TEAM | |
} | |
PacketAccessor.sendToAllPacket( | |
new PacketPlayOutScoreboardTeam(scoreboardTeam, 1), //REMOVE EXISTS TEAM | |
new PacketPlayOutScoreboardTeam(scoreboardTeam, 0) //CREATE NEW TEAM | |
); | |
} | |
public String getSafetyName(String name) { | |
return name.length() > 16 | |
? name.substring(0, 16) | |
: name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
all classes come from net.minecraft.server package, be carefull with imports!