Field index 0 is out of bounds for length 0 | Sending sound packet in 1.19.3 pls help :)
Crowraw opened this issue ยท 13 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
- You've checked for duplicate issues
- You didn't use
/reload
Describe the question
Hello, I wanted to ask why exactly my code isn't working.
I'm trying to send sound packets to players, but it looks like it isn't working, since it does throw exceptions.
ProtocolLib is installed correctly.
Version 1.19.3
I
API method(s) used
Expected behavior
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 (1).jar:?] at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:289) ~[ProtocolLib (1).jar:?] at de.crowraw.airdrops.util.PacketSenderHelper.sendSoundPacket(PacketSenderHelper.java:48) ~[AirDropRebornNew.jar:?] at v1_19.entitiy.AirDrop$1.run(AirDrop.java:75) ~[AirDropRebornNew.jar:?] at org.bukkit.craftbukkit.v1_19_R2.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.19.3.jar:git-Paper-345] at org.bukkit.craftbukkit.v1_19_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) ~[paper-1.19.3.jar:git-Paper-345] at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1473) ~[paper-1.19.3.jar:git-Paper-345] at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:440) ~[paper-1.19.3.jar:git-Paper-345] at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1397) ~[paper-1.19.3.jar:git-Paper-345] at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1173) ~[paper-1.19.3.jar:git-Paper-345] at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:316) ~[paper-1.19.3.jar:git-Paper-345] at java.lang.Thread.run(Thread.java:833) ~[?:?]
Code
` public static void sendSoundPacket(
Sound sound, EnumWrappers.SoundCategory category, Location location, AirDrops plugin) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.NAMED_SOUND_EFFECT);
packet.getModifier().writeDefaults();
packet.getSoundEffects().write(0,sound); //error is thrown here, and I don't understand why
packet.getSoundCategories().write(0, category);
packet
.getIntegers()
.write(0, location.getBlockX() * 8)
.write(1, location.getBlockY() * 8)
.write(2, location.getBlockZ() * 8);
packet.getFloat().write(0, 1.0f);
sendPacketToEveryBody(packet, plugin);
}`
Additional context
I also checked how the Packet class looks like, seems like I have done everything correctly?
make a pr and solve this.
Interesting. Looks like Mojang added a Holder class to wrap sound effects. Will look into supporting this
It is not just for sound packets. Happens with other ones too
Feel free to make new issues for those. I also added a modifier for holders in the meantime