Sleeping Animation throws a FieldAccessException (ProtocolLib)?

Discussion in 'Plugin Development' started by Blockhead7360, Jul 17, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Blockhead7360

    Hello!

    Every time I run this code, I geta FieldAccessException. Does anyone know why?

    Code:
    private void playSleepAnimation(Player asleep) {
    final PacketContainer bedPacket = manager.createPacket(PacketType.Play.Server.BED);
    final Location loc = asleep.getLocation();
    // http://wiki.vg/Protocol#Use_Bed
    bedPacket.getIntegers().write(0, asleep.getEntityId());
    
        bedPacket.getBlockPositionModifier().
        write(1, new BlockPosition(loc.getBlockX(), loc.getBlockY() + 1, loc.getBlockZ()));
    
    
        this.broadcastNearby(asleep, bedPacket);
    }
    Thanks!
     
  2. FieldAccessException is thrown when you don't have access to a certain field, IE it's private or protected (assuming you aren't extending the class)

    Can you show us your stacktrace? It's quite hard to help you without it.
     
  3. Offline

    Blockhead7360

    @AlvinB here you go:

    Code:
    [11:50:05 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin PlayerRevival v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[bukkit.jar:git-Spigot-c3e4052-1953f52]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[bukkit.jar:git-Spigot-c3e4052-1953f52]
        at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1351) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1186) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_77]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_77]
        at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:733) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:672) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:571) [bukkit.jar:git-Spigot-c3e4052-1953f52]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
    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:352) ~[?:?]
        at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:328) ~[?:?]
        at me.blockhead7360.playerrevival.PlayerRevival.playSleepAnimation(PlayerRevival.java:163) ~[?:?]
        at me.blockhead7360.playerrevival.PlayerRevival.onCommand(PlayerRevival.java:150) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[bukkit.jar:git-Spigot-c3e4052-1953f52]
        ... 15 more
    Line 163 is the one with "write(1, new BlockPosition...", so I'm guessing I can't access the field "1"? I tried changing both the #write things to 0 and it doesn't work or produce an error.
     
  4. I'm not an expert on ProtocolLib, but it seems like a problem with its code. Try contacting their author for help.
     
  5. @Blockhead7360 Probably because you are adding 1 to the Y, beds don't go upwards.
     
  6. Offline

    Blockhead7360

    @bwfcwalshy I removed the +1 to the Y, and the same error occurred.
     
  7. Offline

    mine-care

    Well I see a FieldAccessException due to Our Of Bounds index because you try to set field 1 and it only has 1 fiend but remember, it's 0 oriented so you should put 0 instead ;)
     
  8. Offline

    Blockhead7360

    @mine-care I tried that, but it doesn't do anything. No errors either.
     
  9. Offline

    mine-care

    @Blockhead7360 the fact that there is no error means they the out of bounds was caused because of that. (Logical isn't it?) now you need to debug and try getting the value of field 0 after setting it in the code and printing it out to visually inspect and verify it is the same as the one you set it to
     
  10. Offline

    Blockhead7360

    @mine-care This is what I changed the code to for debugging:

    Code:
    private void playSleepAnimation(Player asleep) {
            final PacketContainer bedPacket = manager.createPacket(PacketType.Play.Server.BED);
            final Location loc = asleep.getLocation();
            bedPacket.getEntityModifier(asleep.getWorld())
            .write(0, asleep);
    
            bedPacket.getBlockPositionModifier().
            write(0, new BlockPosition(loc.getBlockX(), loc.getBlockY() + 1, loc.getBlockZ()));
    
    
            this.broadcastNearby(asleep, bedPacket);
            asleep.sendMessage(bedPacket.getBlockPositionModifier().read(0).toString());
            asleep.sendMessage(bedPacket.getEntityModifier(asleep.getWorld()).read(0).toString());
    
        }
    I did get the messages and they were set to what I wanted them to be. However, nothing happens.
     
Thread Status:
Not open for further replies.

Share This Page