How?!
molor opened this issue ยท 5 comments
How to create a listener for PacketType.Play.Server.CUSTOM_PAYLOAD, I know.
But how do I change the data in this packet that the server sends to player?
getStrings()
- No field with type java.lang.String exists in class PacketPlayOutCustomPayload.
getStringArray()
? getByteArrays()
? Same problem..
I spent about five hours on it, and I never figured out how to get the name of the channel and data. For example, if a channel is named minecraft:test
and contains "foo" in data, how do I change this data to "bar"? Help :c
Warning! (Reply from a guy who just started ProtocolLib. Open to all corrections)
Listening for packets and sending a packet are two separate things. You have to make your listener run the code required to send the packet you want (or modify an existing packet that is to be sent) after your plugin detects the packet.
From my knowledge you can use the ProtocolManager static object (Gotten from ProtocolLibrary) to either create a Packet through .createPacket([params]) or create a packet constructor (Which I have not properly tried yet)
In 1.13 mojang changed channel names to identifiers, so you need to use getMinecraftKeys()
instead of getStrings()
. The data for the packet is contained in a byte buffer, which can be obtained with getModifier().withType(ByteBuf.class)
@dmulloy2, thank you! But how to change data? Rather, how to correctly create a ByteBuf before writing it to getModifier()?
However, write Unpooled.createBuffer() with new data still does not work without any problems..
java.lang.IllegalArgumentException: Can not set net.minecraft.server.v1_13_R1.PacketDataSerializer field net.minecraft.server.v1_13_R1.PacketPlayOutCustomPayload.j to io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeNoCleanerDirectByteBuf