1.12.2 ProtocolLib - Custom Name in DataWatcher does not work
klochk opened this issue ยท 1 comments
Make sure you're doing the following
- You're using the latest build for your server version
- This isn't an issue caused by another plugin (i have only my plugin and ProtocolLib on my test server)
- You've checked for duplicate issues (no issues with same version)
- You didn't use
/reload
Describe the question
I'm trying to create a NPC using protocollib and packetwrapper with 1.12.2 version of PaperMC (latest build) and want to set a custom name (and visibility) for NPC. I have no errors and issues in console and client logs. But NPC still have default name (not custom name).
API method(s) used
WrappedDataWatcher
WrappedDataWatcher.Serializer
WrappedDataWatcher.Registry
ProtocolManager (for packet broadcasting)
EnumWrapper
and more wrappers...
Expected behavior
NPC must have a custom name, described in my method in Watcher object.
Code
class ProtocolNPC {
var entityId: Int = (0..99999).random()
var entityUUID: UUID = UUID.randomUUID()
fun spawn (player: Player) {
var spawn: PacketContainer = PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN)
var preSpawn: PacketContainer = PacketContainer(PacketType.Play.Server.PLAYER_INFO)
var body: WrapperPlayServerNamedEntitySpawn = WrapperPlayServerNamedEntitySpawn(spawn)
body.entityID = this.entityId
body.playerUUID = this.entityUUID
body.pitch = player.location.pitch
body.x = player.location.x
body.y = player.location.y
body.z = player.location.z
val preP: WrapperPlayServerPlayerInfo = WrapperPlayServerPlayerInfo(preSpawn)
preP.action = EnumWrappers.PlayerInfoAction.ADD_PLAYER
val data: PlayerInfoData = PlayerInfoData(
WrappedGameProfile(entityUUID, "witwar"),
10,
EnumWrappers.NativeGameMode.CREATIVE,
null
)
val pls: ArrayList<PlayerInfoData> = ArrayList<PlayerInfoData>()
pls.add(data)
preP.data = pls
val toInt: WrappedDataWatcher.Serializer = WrappedDataWatcher.Registry.get(Int::class.javaObjectType)
val toFloat: WrappedDataWatcher.Serializer = WrappedDataWatcher.Registry.get(Float::class.javaObjectType)
val toByte: WrappedDataWatcher.Serializer = WrappedDataWatcher.Registry.get(Byte::class.javaObjectType)
val toBoolean: WrappedDataWatcher.Serializer = WrappedDataWatcher.Registry.get(Boolean::class.javaObjectType)
val toString: WrappedDataWatcher.Serializer = WrappedDataWatcher.Registry.get(String::class.javaObjectType)
val watcher: WrappedDataWatcher = WrappedDataWatcher()
watcher.setObject(WrappedDataWatcher.WrappedDataWatcherObject(2, toString), "witwar")
watcher.setObject(WrappedDataWatcher.WrappedDataWatcherObject(3, toBoolean), true)
body.metadata = watcher
HLobby.instance.protoLib.broadcastServerPacket(preSpawn)
HLobby.instance.protoLib.broadcastServerPacket(spawn)
}
}
Additional context
This is Kotlin.
See the entity metadata spec: https://wiki.vg/Entity_metadata#Entity_Metadata_Format
My guess is that it needs to be a chat component (also potentially wrapped in an optional)