Field index 0 is out of bounds for length 0
wzard27 opened this issue ยท 2 comments
- [ x] This issue is not solved in a development build
Describe the bug
I try to spawn fake Entitys in Spigot 1.20.1, kinda doesnt work and i dont get why.
Version Info
LATEST ProtocolLib
if(this.type.isAlive()) {
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);
System.out.println("packet.getIntegers().size();" + packet.getIntegers().size());
packet.getIntegers().write(0, this.getEntityId());
packet.getIntegers().write(1, (int) this.type.getTypeId()); //Id
packet.getIntegers().write(2, (int) Math.floor(this.loc.getX() * 32D)); //X
packet.getIntegers().write(3, (int) Math.floor((this.loc.getY() + 0.001D) * 32D)); //Y
packet.getIntegers().write(4, (int) Math.floor(this.loc.getZ() * 32D)); //Z
packet.getBytes().write(0, (byte)(int)(this.loc.getYaw() * 256.0F / 360.0F)); //Yaw
packet.getBytes().write(1, (byte)(int)(this.loc.getPitch() * 256.0F / 360.0F)); //Pitch
packet.getBytes().write(2, (byte)(int)(this.loc.getYaw() * 256.0F / 360.0F)); //Head
packet.getDataWatcherModifier().write(0, this.dataWatcher);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} catch (Exception e) {
FakeMobsPlugin.getInstance().getLogger().log(Level.SEVERE, "Can''t send spawn packet to {0} from mob #{1}", new Object[]{player.getName(), this.getId()});
e.printStackTrace();
return;
}
THE ERROR:
[12:52:56 INFO]: [HomeServer] [STDOUT] packet.getIntegers().size();5
[12:52:56 WARN]: Nag author(s): '[Faited]' of 'HomeServer v0.1' about their usage of System.out/err.print. Please use your plugin's logger instead (JavaPlugin#getLogger).
[12:52:56 ERROR]: Error occurred while enabling HomeServer v0.1 (Is it up to date?)
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 (2).jar:?]
at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:315) ~[ProtocolLib (2).jar:?]
at de.howaner.FakeMobs.util.FakeMob.sendEntitySpawnPacket(FakeMob.java:494) ~[HomeServer-0.1.jar:?]
at de.howaner.FakeMobs.util.FakeMob.sendSpawnPacket(FakeMob.java:381) ~[HomeServer-0.1.jar:?]
at de.howaner.FakeMobs.util.FakeMob.loadPlayer(FakeMob.java:123) ~[HomeServer-0.1.jar:?]
at de.howaner.FakeMobs.FakeMobsPlugin.spawnMob(FakeMobsPlugin.java:130) ~[HomeServer-0.1.jar:?]
at de.howaner.FakeMobs.FakeMobsPlugin.spawnMob(FakeMobsPlugin.java:116) ~[HomeServer-0.1.jar:?]
at de.faited.pvp.fakeentity.FakeEntity.setVisible(FakeEntity.java:178) ~[HomeServer-0.1.jar:?]
at de.faited.pvp.fakeentity.FakeEntity.loadData(FakeEntity.java:69) ~[HomeServer-0.1.jar:?]
at de.faited.pvp.fakeentity.FakeEntity.(FakeEntity.java:38) ~[HomeServer-0.1.jar:?]
at de.faited.pvp.managers.FakeEntityManager.loadAllCustomEntities(FakeEntityManager.java:82) ~[HomeServer-0.1.jar:?]
at de.faited.pvp.managers.FakeEntityManager.postInit(FakeEntityManager.java:35) ~[HomeServer-0.1.jar:?]
at de.faited.pvp.Main.registerAll(Main.java:163) ~[HomeServer-0.1.jar:?]
at de.faited.pvp.Main.onEnable(Main.java:85) ~[HomeServer-0.1.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189) ~[paper-1.20.1.jar:git-Paper-196]
at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugin(CraftServer.java:642) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugins(CraftServer.java:553) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.reload(CraftServer.java:1097) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.Bukkit.reload(Bukkit.java:993) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:54) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchCommand(CraftServer.java:987) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchServerCommand(CraftServer.java:972) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:500) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:447) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1393) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1170) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.20.1.jar:git-Paper-196]
at java.lang.Thread.run(Thread.java:1583) ~[?:?]
i got same problem for playerwarps plugin, the author of the plugin also say it is a protocolib problem
[16:42:26 WARN]: FieldAccessException: Field index 0 is out of bounds for length 0
[16:42:26 WARN]: at ProtocolLib#689.jar//com.comphenix.protocol.reflect.FieldAccessException.fromFormat(FieldAccessException.java:49)
[16:42:26 WARN]: at ProtocolLib#689.jar//com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:315)
[16:42:26 WARN]: at PlayerWarps 7.4.0.jar//com.olziedev.playerwarps.k.d$_b.b(ProtocolLibExpansion.java:134)
[16:42:26 WARN]: at PlayerWarps 7.4.0.jar//com.olziedev.playerwarps.k.d.b(ProtocolLibExpansion.java:97)
[16:42:26 WARN]: at PlayerWarps 7.4.0.jar//com.olziedev.playerwarps.j.c.b(SearchMenu.java:92)
[16:42:26 WARN]: at PlayerWarps 7.4.0.jar//com.olziedev.playerwarps.e.c.c(PluginFoliaScheduler.java:63)
[16:42:26 WARN]: at io.papermc.paper.threadedregions.scheduler.FoliaAsyncScheduler$AsyncScheduledTask.run(FoliaAsyncScheduler.java:217)
[16:42:26 WARN]: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[16:42:26 WARN]: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[16:42:26 WARN]: at java.base/java.lang.Thread.run(Thread.java:1583)
Hello, I am in the process of updating my NPC plugin. I also make Fake players appear on my map. Before I used NAMED_ENTITY_SPAWN and apparently I have to use SPAWN_ENTITY from now on.
By following the documentation that you can find here: https://wiki.vg/Protocol#Spawn_Entity it seems that index 2 is now a VarInt corresponding to https://wiki.vg/Entity_metadata#Player.
So I wrote the code below:
public static PacketContainer createPacketNES(UUID uuid, int entityID, Location location) {
PacketContainer nesPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
nesPacket.getModifier().writeDefaults();
var spawnPacketModifier = nesPacket.getModifier();
spawnPacketModifier.write(0, entityID);
spawnPacketModifier.write(1, uuid);
spawnPacketModifier.write(2, 122); // ID for player
spawnPacketModifier.write(3, location.getX());
spawnPacketModifier.write(4, location.getY());
spawnPacketModifier.write(5, location.getZ());
spawnPacketModifier.write(6, getCompressedAngle(location.getYaw()));
spawnPacketModifier.write(7, getCompressedAngle(location.getPitch()));
return nesPacket;
}
However, here is the error I have:
[16:40:17 WARN]: [GaspeziaNPCs] Plugin GaspeziaNPCs v1.9.0 generated an exception while executing task 882
java.lang.IllegalStateException: Unable to set value of field private final net.minecraft.world.entity.EntityTypes net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity.e
at com.comphenix.protocol.reflect.accessors.DefaultFieldAccessor.set(DefaultFieldAccessor.java:44) ~[ProtocolLib.jar:?]
at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:358) ~[ProtocolLib.jar:?]
at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:321) ~[ProtocolLib.jar:?]
at fr.hotmail.regisgaia.gnpcs.packets.NPCsPC.createPacketNES(NPCsPC.java:101) ~[GNPCs-1.9.0.jar:?]
at fr.hotmail.regisgaia.gnpcs.packets.SenderPacketsPlayer.sendSpawnPackets(SenderPacketsPlayer.java:75) ~[GNPCs-1.9.0.jar:?]
at fr.hotmail.regisgaia.gnpcs.entities.FakePlayerData.spawn(FakePlayerData.java:73) ~[GNPCs-1.9.0.jar:?]
at fr.hotmail.regisgaia.gnpcs.entities.NPCsManager.spawnNPCforPlayer(NPCsManager.java:189) ~[GNPCs-1.9.0.jar:?]
at fr.hotmail.regisgaia.gnpcs.entities.NPCsManager.spawnNPCs(NPCsManager.java:160) ~[GNPCs-1.9.0.jar:?]
at fr.hotmail.regisgaia.gnpcs.player.PlayerManager.lambda$sendNPCs$0(PlayerManager.java:37) ~[GNPCs-1.9.0.jar:?]
at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.20.4.jar:git-Paper-454]
at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[paper-1.20.4.jar:git-Paper-454]
at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[paper-1.20.4.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.ClassCastException: Cannot cast java.lang.Integer to net.minecraft.world.entity.EntityTypes
at java.lang.Class.cast(Class.java:3889) ~[?:?]
at com.comphenix.protocol.reflect.accessors.DefaultFieldAccessor.set(DefaultFieldAccessor.java:41) ~[ProtocolLib.jar:?]
... 14 more
It seems that the expected type is not a VarInt but in EntityTypes. I didn't manage to go any further.
If anyone could help me I would be very grateful.
I use the Paper version git-Paper-454 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: 99a6416) with the last build of Protocolibs 5.2.0-SNAPSHOT-679.
PS: my old function :
public static PacketContainer createPacketNES(UUID uuid, int entityID, Location location) {
PacketContainer nesPacket = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
nesPacket.getModifier().writeDefaults();
var spawnPacketModifier = nesPacket.getModifier();
spawnPacketModifier.write(0, entityID);
spawnPacketModifier.write(1, uuid);
spawnPacketModifier.write(2, location.getX());
spawnPacketModifier.write(3, location.getY());
spawnPacketModifier.write(4, location.getZ());
spawnPacketModifier.write(5, getCompressedAngle(location.getYaw()));
spawnPacketModifier.write(6, getCompressedAngle(location.getPitch()));
return nesPacket;
}