Change Tag-Name of Player

Discussion in 'Plugin Development' started by ferdedelino, Jun 1, 2023.

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

    ferdedelino

    Hey!

    I'm currently trying to modify the NameTag of players. Or to be more specific the text that is shown above a players avatar.
    My problem is, that the nametag is very restricting. It only allows the 15 base colors (no rgb) and is single-color.

    My Idea to solve this problem was to set the Name itself to an invisible String ("§1§2" for example). And use the suffix to display a custom Name without the restrictions of the name itself.

    This Idea works fine, but i can't get the PlayerName to display an empty String (i'm using a mod, that displays my own nametag): https://imgur.com/a/I8omnXb

    Code:
               
                Player sender = [...];
                Scoreboard scoreboard = sender.getScoreboard();
                Team team = scoreboard.getPlayerTeam(sender);
                if (team != null) {
                    sender.sendMessage("Found team for " + sender.getName() + ": " + team.getName());
                    team.unregister();
                }
                Team team1 = scoreboard.registerNewTeam("registerTest");
                team1.addPlayer(sender);
                team1.setDisplayName("§3§4§5");
                team1.setPrefix(TagUtil.getRankPrefixString(19));
                team1.setSuffix(TagUtil.getColoredPlayerTagName(sender));

    One more Idea i had was to modify all outgoing ClientboundSetPlayerTeamPacket and ClientboundPlayerInfoUpdatePacket packets. And change the playernames directly in the packets to a unique String of color codes.
    This actually works. Other players now only see the suffix, and no longer the actual name. Unfortunately this does not work with your own nametag, since your client already knows your username.

    PS: I'm on 1.19.4, Paper
     
Thread Status:
Not open for further replies.

Share This Page