Change players nametag (name above head), without affecting teams
Nuckerr opened this issue ยท 1 comments
I am currently using teams to group players, with custom name set, as well as teams (using nms) to set a glow and colour for that glow. Right now, if you can see the glow, it sets their nametag to that glow color, removing all formatting from the initial team.
To fix this, I am using protocol lib to set the players nametag, for which I have this class:
class Nametag(player: Player) {
companion object {
private val GSON = GsonComponentSerializer.gson()
}
private val packet: PacketContainer = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_TEAM)
private val structure: InternalStructure
init {
val name = UUID.randomUUID().toString().replace("-", "").substring(0, 12)
packet.integers.write(0, 0)
packet.strings.write(0, name)
packet.getSpecificModifier(Collection::class.java).write(0, listOf(player.name))
structure = packet.optionalStructures.readSafely(0).get()
}
fun setPrefix(prefix: Component): Nametag {
structure.chatComponents.write(1, WrappedChatComponent.fromJson(GSON.serialize(prefix)))
return this
}
fun color(color: NamedTextColor): Nametag {
structure.getEnumModifier(ChatColor::class.java, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, color.toChatColor())
return this
}
fun setSuffix(suffix: Component): Nametag {
structure.chatComponents.write(2, WrappedChatComponent.fromJson(GSON.serialize(suffix)))
return this
}
fun build(players: Collection<Player>) {
structure.integers.write(0, 3)
packet.optionalStructures.write(0, Optional.of(structure))
players.forEach {
runCatching {
ProtocolLibrary.getProtocolManager().sendServerPacket(it,packet)
}.onFailure {
throw RuntimeException("Could not send packet $packet", it)
}
}
}
fun build() {
build(Bukkit.getOnlinePlayers())
}
}
However, setting the nametag color will set the glow color as well as the nametag color, and I want a white nametag with a coloured glow. How can I avoid/fix this
Unfortunately, I am having some trouble to understand what you trying to do.
If I understood you correctly, you want that players have a white name tag but a glow effect in the color of your choice. Is this correct?
If so, there is currently no way to achieve this. You can control the color of the glow effect by setting the color of you team. However, this will also affect the color of the name (regardless of the color of the prefix I think). It is simply not supported by the Minecraft client AFAIK.