ProtocolLib

3M Downloads

FieldAccessException when trying to read getPlayerInfoAction (1.19.3)

ajgeiss0702 opened this issue ยท 2 comments

commented
  • This issue is not solved in a development build

Describe the bug
I'm attempting to intercept certain player info updates in order to modify their content.

The following code worked fine on 1.18.2, however today when I updated my test server to 1.19.3 (and of course updated PrococolLib), this issue started happening.

When I attempt to read the update type using packet.getPlayerInfoAction().read(0), I get: com.comphenix.protocol.reflect.FieldAccessException: Field index 0 is out of bounds for length 0 (more code and full error below)

To Reproduce

The code used:

public PlayerInfoPacketListener() {
    // https://wiki.vg/Protocol#Player_Info
    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) {
        @Override
        public void onPacketSending(PacketEvent event) {
            packetSend(event);
        }
    });
}


public void packetSend(PacketEvent event) {
    // I don't care about things that happen before a bukkit player is available
    if(event.isPlayerTemporary()) return;

    Player player = event.getPlayer();
    PacketContainer packet = event.getPacket();
        
    // some checks here that 

    EnumWrappers.PlayerInfoAction type = packet.getPlayerInfoAction().read(0); // this is line 50, the error happens here
    StructureModifier<List<PlayerInfoData>> playerInfoData =  packet.getPlayerInfoDataLists();
    List<PlayerInfoData> playerInfoList = playerInfoData.read(0);

    // check the update type and do stuff with the packet. This code doesnt get run though due to the error above
}

The error recieved: (some non-crucial info has been redacted and replaced with "thing")

[18:52:50 ERROR]: [ajThing] Unhandled exception occurred in onPacketSending(PacketEvent) for ajThing
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.read(StructureModifier.java:218) ~[ProtocolLib(1).jar:?]
        at us.ajg0702.thing.listeners.packet.PlayerInfoPacketListener.packetSend(PlayerInfoPacketListener.java:50) ~[ajThing-1.0.0.jar:?]
        at us.ajg0702.thing.listeners.packet.PlayerInfoPacketListener$1.onPacketSending(PlayerInfoPacketListener.java:27) ~[ajThing-1.0.0.jar:?]
        at com.comphenix.protocol.injector.SortedPacketListenerList.invokeSendingListener(SortedPacketListenerList.java:195) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:149) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.PacketFilterManager.postPacketToListeners(PacketFilterManager.java:547) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.PacketFilterManager.invokePacketSending(PacketFilterManager.java:521) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector.onPacketSending(NetworkManagerInjector.java:99) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.netty.channel.NettyChannelInjector.processOutbound(NettyChannelInjector.java:571) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.netty.channel.NettyChannelInjector$2.doProxyRunnable(NettyChannelInjector.java:472) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.proxyRunnable(NettyEventLoopProxy.java:43) ~[ProtocolLib(1).jar:?]
        at com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.execute(NettyEventLoopProxy.java:252) ~[ProtocolLib(1).jar:?]
        at net.minecraft.network.Connection.sendPacket(Connection.java:432) ~[?:?]
        at net.minecraft.network.Connection.send(Connection.java:379) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.send(ServerGamePacketListenerImpl.java:2248) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.send(ServerGamePacketListenerImpl.java:2234) ~[?:?]
        at net.minecraft.server.players.PlayerList.broadcastAll(PlayerList.java:1009) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at net.minecraft.server.level.ServerPlayerGameMode.changeGameModeForPlayer(ServerPlayerGameMode.java:96) ~[?:?]
        at net.minecraft.server.level.ServerPlayer.setGameMode(ServerPlayer.java:1941) ~[?:?]
        at org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer.setGameMode(CraftPlayer.java:1576) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at us.ajg0702.thing.utils.InventorySaverImpl.lambda$saveInventory$0(InventorySaverImpl.java:52) ~[ajThing-1.0.0.jar:?]
        at org.bukkit.craftbukkit.v1_19_R2.scheduler.CraftTask.run(CraftTask.java:101) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at org.bukkit.craftbukkit.v1_19_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1500) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:482) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1424) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1194) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:321) ~[purpur-1.19.3.jar:git-Purpur-1890]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
[18:52:50 ERROR]: Parameters: 
  net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket@38435707[
    a=[UPDATE_GAME_MODE]
    b=[b[profileId=4b8881a9-ea3c-31f6-ad69-7707f5f749ef, profile=com.mojang.authlib.GameProfile@46f02ad9[id=4b8881a9-ea3c-31f6-ad69-7707f5f749ef,name=ajgeiss0702,properties={},legacy=false], listed=true, latency=0, gameMode=ADVENTURE, displayName=null, chatSession=null]]
  ]

Expected behavior
No error to be throws, and me be able to read what kind of player update it is. Note that the same code worked on 1.18.2, however a server update (and protocollib update) broke it.

Version Info
(again, some non-crucial info has been redacted and replaced with "thing")
https://pastebin.com/raw/0huajMCM

Additional context
As I said above, the code worked fine on 1.18.2, and as far as I can tell there doesnt appear to be a breaking change to protocol (according to looking at wiki.vg)

commented

The player info packet was changed in 1.19 a bit, to read it properly, try this:

Set<EnumWrappers.PlayerInfoAction> types = packet.getPlayerInfoActions().read(0);

List<PlayerInfoData> playerInfoList = packet.getPlayerInfoDataLists().read(1);

For the error you have posted, you have to read all the actions contained in the packet, and for the second error that I ran into as well, you have to read fieldIndex 1 instead of 0.

commented

Ah, thank you. Apparently I didn't look closely enough