Name is always black in PacketType.Play.Server.SCOREBOARD_TEAM packet
Zorioux opened this issue ยท 1 comments
question description:
when using PacketType.Play.Server.SCOREBOARD_TEAM, whatever I do prefix and suffix always get colored, but not the name, the name is ALWAYS black and I couldn't find any solution for it
Expected behavior:
Adding a color behind the name anywhere in packet value 0 won't give it a color and name is always black
code:
`public class Nametag {
private final Clans plugin;
private final Player player;
PacketContainer packet;
public Nametag(Clans plugin, Player player) {
this.player = player;
this.plugin = plugin;
this.packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_TEAM);
String name = UUID.randomUUID().toString().replace("-", "").substring(0, 12);
this.packet.getIntegers().write(1, 0);
this.packet.getStrings().write(0, name);
this.packet.getChatComponents().write(0, WrappedChatComponent.fromText(player.getName()));
this.packet.getSpecificModifier(Collection.class).write(0, Collections.singletonList(player.getName()));
}
public Nametag setPrefix(String prefix) {
this.packet.getChatComponents().write(1, WrappedChatComponent.fromText(ChatColor.translateAlternateColorCodes('&', prefix) + " "));
return this;
}
public Nametag setSuffix(String suffix) {
this.packet.getChatComponents().write(2, WrappedChatComponent.fromText(" " + ChatColor.translateAlternateColorCodes('&', suffix)));
return this;
}
public void build() {
plugin.getClansManager().getPacketsMap().put(player, packet);
for (Player p : Bukkit.getOnlinePlayers()) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send packet " + packet, e);
}
}
for (Player a: plugin.getClansManager().getPacketsMap().keySet()) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, plugin.getClansManager().getPacketsMap().get(a));
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send packet " + packet, e);
}
}
}
}`
I added color for each of these individually and together won't give the name a colour
this.packet.getStrings().write(0, name); this.packet.getChatComponents().write(0, WrappedChatComponent.fromText(player.getName())); this.packet.getSpecificModifier(Collection.class).write(0, Collections.singletonList(player.getName()));