Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Bed Packet causes FieldAccessException #86

Closed
fynntimes opened this issue Apr 9, 2015 · 2 comments
Closed

Use Bed Packet causes FieldAccessException #86

fynntimes opened this issue Apr 9, 2015 · 2 comments

Comments

@fynntimes
Copy link

Here is my code for sending a PacketType.Play.Server.BED packet:

private static void playSleepAnimation(Player p) {
        PacketContainer container = manager.createPacket(PacketType.Play.Server.BED);
        int x = (int) p.getLocation().getX();
        int y = (int) p.getLocation().getY();
        int z = (int) p.getLocation().getZ();
        container.getIntegers()
                .write(0, p.getEntityId());
        container.getBlockPositionModifier().write(1, new BlockPosition(x, y, z));
        sendToAll(container);
    }

For some reason, I get this error in console:

[20:02:25 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'corpse' in plugin Apocalypse v1.0-SNAPSHOT
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1133) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_40]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_40]
    at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-dbe012b-61ef214]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]
**Caused by: com.comphenix.protocol.reflect.FieldAccessException: Field index out of bounds. (Index: 1, Size: 1)**
    at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:336) ~[?:?]
    at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:312) ~[?:?]
    at com.theapocalypsemc.apocalypse.entities.CorpseUtil.playSleepAnimation(CorpseUtil.java:46) ~[?:?]
    at com.theapocalypsemc.apocalypse.entities.CorpseUtil.createCorpse(CorpseUtil.java:29) ~[?:?]
    at com.theapocalypsemc.apocalypse.Apocalypse.onCommand(Apocalypse.java:51) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot_server.jar:git-Spigot-dbe012b-61ef214]
    ... 15 more

I get a FieldAccessException, saying my field index is out of bounds. However, I checked the server code and according to that, field index 0 is an integer, and field index 1 is a BlockPosition. Currently using 3.6.3-SNAPSHOT on Spigot v1.8.3-R0.1-SNAPSHOT.

@dmulloy2
Copy link
Collaborator

dmulloy2 commented Apr 9, 2015

The index is relative to the type, so you should use the index 0 instead of 1.

@fynntimes
Copy link
Author

That fixed it. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants