Skip to content

Instantly share code, notes, and snippets.

@zkingboos
Last active January 4, 2022 22:16
Show Gist options
  • Save zkingboos/0badd6f20183ff9e5e5edc6b2d2637b3 to your computer and use it in GitHub Desktop.
Save zkingboos/0badd6f20183ff9e5e5edc6b2d2637b3 to your computer and use it in GitHub Desktop.
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;
}
}
@zkingboos
Copy link
Author

zkingboos commented Feb 12, 2021

all classes come from net.minecraft.server package, be carefull with imports!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment