index out of bounds with CUSTOM_PAYLOAD in 5.2.0
Qiu-Ling-T opened this issue ยท 1 comments
Make sure you're doing the following
- [ x ] You're using the latest build for your server version
- [ x ] This isn't an issue caused by another plugin
- [ x ] You've checked for duplicate issues
- [ x ] You didn't use
/reload
Describe the question
I face index out of bounds question in writing a packet.I create a PacketContainer with CUSTOM_PAYLOAD,when I start to write something in it, the error happend.The code are follow:
`PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.CUSTOM_PAYLOAD);
plugin.getLogger().info("Sending dialog packet to player: " + player.getName());
plugin.getLogger().info(String.valueOf(packet.getStrings().size()));
packet.getStrings().write(0, "qiuling:dialog_packet");
plugin.getLogger().info("Sending dialog packet to player: " + player.getName());`
and the error logger like this:
com.comphenix.protocol.reflect.FieldAccessException: Field index 0 is out of bounds for length 0 at com.comphenix.protocol.reflect.FieldAccessException.fromFormat(FieldAccessException.java:49) ~[ProtocolLib.jar:?] at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:315) ~[ProtocolLib.jar:?]
I print the packet.getStrings().size(), and its result is 0.I don't know why.And I want to know how to write a correctly code.
What Minecraft version are you running? This error could be caused by an outdated version of ProtocolLib.
Try downloading the latest build: here