ProtocolLib

3M Downloads

getStatisticMaps().read(0) Error

4wincode opened this issue ยท 1 comments

commented

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
This is my first time using ProtocolLib and I've read a bit of documentation. I created a plugin that registers a PacketType.Play.Server.STATISTIC packet listener and reads the statistic map from it to test out that packet as I was going to use it for a plugin later. I was going to dump the contents of the map to the log but when I was testing it in-game to see if it worked at alI and I opened the statistics menu then it output this error:

[02:42:01 ERROR]: [PlayerStatisticsViewer] Unhandled exception occurred in onPacketSending(PacketEvent) for PlayerStatisticsViewer
java.lang.NullPointerException: Cannot invoke "com.comphenix.protocol.reflect.accessors.FieldAccessor.get(Object)" because "com.comphenix.protocol.wrappers.WrappedStatistic.GET_NAME" is null
	at com.comphenix.protocol.wrappers.WrappedStatistic.<init>(WrappedStatistic.java:43) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.wrappers.WrappedStatistic.fromHandle(WrappedStatistic.java:52) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.wrappers.Converters$3.getSpecific(Converters.java:96) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.wrappers.Converters$1.getSpecific(Converters.java:43) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.wrappers.BukkitConverters$1.getSpecific(BukkitConverters.java:243) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.wrappers.BukkitConverters$1.getSpecific(BukkitConverters.java:230) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.reflect.StructureModifier.readInternal(StructureModifier.java:274) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.reflect.StructureModifier.read(StructureModifier.java:224) ~[ProtocolLib (12).jar:?]
	at us.mcnex.playerstatisticsviewer.PlayerStatisticsViewer$1.onPacketSending(PlayerStatisticsViewer.java:32) ~[PlayerStatisticsViewer-1.0-SNAPSHOT.jar:?]
	at com.comphenix.protocol.injector.SortedPacketListenerList.invokeSendingListener(SortedPacketListenerList.java:195) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:149) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.injector.PacketFilterManager.postPacketToListeners(PacketFilterManager.java:547) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.injector.PacketFilterManager.invokePacketSending(PacketFilterManager.java:521) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector.onPacketSending(NetworkManagerInjector.java:99) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.injector.netty.channel.NettyChannelInjector.processOutbound(NettyChannelInjector.java:570) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.injector.netty.channel.NettyChannelInjector$2.proxyRunnable(NettyChannelInjector.java:473) ~[ProtocolLib (12).jar:?]
	at com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.execute(NettyEventLoopProxy.java:220) ~[ProtocolLib (12).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:2163) ~[?:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.send(ServerGamePacketListenerImpl.java:2149) ~[?:?]
	at net.minecraft.stats.ServerStatsCounter.sendStats(ServerStatsCounter.java:251) ~[?:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handleClientCommand(ServerGamePacketListenerImpl.java:3055) ~[?:?]
	at net.minecraft.network.protocol.game.ServerboundClientCommandPacket.handle(ServerboundClientCommandPacket.java:24) ~[?:?]
	at net.minecraft.network.protocol.game.ServerboundClientCommandPacket.a(ServerboundClientCommandPacket.java:10) ~[?:?]
	at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:51) ~[?:?]
	at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.19.2.jar:git-Paper-138]
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1361) ~[paper-1.19.2.jar:git-Paper-138]
	at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:185) ~[paper-1.19.2.jar:git-Paper-138]
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1338) ~[paper-1.19.2.jar:git-Paper-138]
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1331) ~[paper-1.19.2.jar:git-Paper-138]
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1309) ~[paper-1.19.2.jar:git-Paper-138]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1197) ~[paper-1.19.2.jar:git-Paper-138]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305) ~[paper-1.19.2.jar:git-Paper-138]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]
[02:42:01 ERROR]: Parameters: 
  net.minecraft.network.protocol.game.PacketPlayOutStatistic@54bdf52[
    a={Stat{name=minecraft.custom:minecraft.jump, formatter=net.minecraft.stats.Counter$$Lambda$2811/0x00000008012ec6b0@4f4f6f12}=>9, Stat{name=minecraft.custom:minecraft.time_since_rest, formatter=net.minecraft.stats.Counter$$Lambda$2814/0x00000008012ecd00@38ba3b80}=>62997, Stat{name=minecraft.custom:minecraft.sprint_one_cm, formatter=net.minecraft.stats.Counter$$Lambda$2813/0x00000008012ecae8@4de8a4c3}=>1266, Stat{name=minecraft.custom:minecraft.leave_game, formatter=net.minecraft.stats.Counter$$Lambda$2811/0x00000008012ec6b0@4f4f6f12}=>3, Stat{name=minecraft.custom:minecraft.play_time, formatter=net.minecraft.stats.Counter$$Lambda$2814/0x00000008012ecd00@38ba3b80}=>62997, Stat{name=minecraft.custom:minecraft.time_since_death, formatter=net.minecraft.stats.Counter$$Lambda$2814/0x00000008012ecd00@38ba3b80}=>62997, Stat{name=minecraft.custom:minecraft.damage_taken, formatter=net.minecraft.stats.Counter$$Lambda$2812/0x00000008012ec8d0@67583e3b}=>20, Stat{name=minecraft.custom:minecraft.walk_one_cm, formatter=net.minecraft.stats.Counter$$Lambda$2813/0x00000008012ecae8@4de8a4c3}=>115, Stat{name=minecraft.custom:minecraft.climb_one_cm, formatter=net.minecraft.stats.Counter$$Lambda$2813/0x00000008012ecae8@4de8a4c3}=>24, Stat{name=minecraft.custom:minecraft.total_world_time, formatter=net.minecraft.stats.Counter$$Lambda$2814/0x00000008012ecd00@38ba3b80}=>62997, Stat{name=minecraft.custom:minecraft.fall_one_cm, formatter=net.minecraft.stats.Counter$$Lambda$2813/0x00000008012ecae8@4de8a4c3}=>482, Stat{name=minecraft.custom:minecraft.fly_one_cm, formatter=net.minecraft.stats.Counter$$Lambda$2813/0x00000008012ecae8@4de8a4c3}=>8455}
  ]

Am I missing something? I haven't found any real examples of that packet being used online and I'm assuming the VarInt for array length is handled automatically. If not, how do I get/set it?

API method(s) used
event.getPacket().getStatisticMaps().read(0);

Expected behavior
For the method to return the Map and not error.

Code

    @Override
    public void onEnable() {
        protocolManager = ProtocolLibrary.getProtocolManager();
        protocolManager.addPacketListener(new PacketAdapter(
                this,
                ListenerPriority.NORMAL,
                PacketType.Play.Server.STATISTIC
        ) {
            @Override
            public void onPacketSending(PacketEvent event) {
                event.getPacket().getStatisticMaps().read(0);
            }
        });
    }

Version Info
This is my /protocol dump: https://pastebin.com/0xeipBu7
I'm using 5.0.0-SNAPSHOT as the maven dependency and the latest dev build on the server for 1.19.

commented

This issue still isn't resolved.