ProtocolLib

3M Downloads

NullPointerException when sending PlayerInfo Packet

junebug12851 opened this issue ยท 1 comments

commented

Describe the bug
When sending a Player Info Packet after I do a command, it crashes to a NullPointerException and the client also crashes to the same error.

To Reproduce

Issuing a command to run this code below

        ProtocolManager manager = ProtocolLibrary.getProtocolManager();

        Player p = (Player) sender;

        PacketContainer playerInfoPacket = manager.createPacket(PacketType.Play.Server.PLAYER_INFO);

        // New Player
        playerInfoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);

        // 1 Entry
        //playerInfoPacket.getIntegers().write(1, 1);

        // Create Sample Player
        OfflinePlayer samplePlayer = Bukkit.getOfflinePlayer(UUID.fromString("f84c6a79-0a4e-45e0-879b-cd49ebd4c4e2"));
        PlayerInfoData samplePlayerData = new PlayerInfoData(
                WrappedGameProfile.fromOfflinePlayer(samplePlayer),
                1500,
                EnumWrappers.NativeGameMode.ADVENTURE,
                WrappedChatComponent.fromJson("{\"text\":\"Steve\"}"));

        // Add to list to send to player
        ArrayList<PlayerInfoData> playerInfoData = new ArrayList<>();
        playerInfoData.add(samplePlayerData);

        // Add list to packet
        playerInfoPacket.getPlayerInfoDataLists().write(0, playerInfoData);

        // Send packet to player
        try {
            manager.sendServerPacket(p, playerInfoPacket);
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

Running that in-game causes it to crash as soon as it gets to the last line

manager.sendServerPacket(p, playerInfoPacket);
[21:11:36 ERROR]: java.lang.NullPointerException
[21:11:36 WARN]: java.lang.NullPointerException
[21:11:36 WARN]:        at net.minecraft.server.v1_15_R1.PacketDataSerializer.a(PacketDataSerializer.java:328)
[21:11:36 WARN]:        at net.minecraft.server.v1_15_R1.PacketDataSerializer.a(PacketDataSerializer.java:324)
[21:11:36 WARN]:        at net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo.b(SourceFile:104)
[21:11:36 WARN]:        at net.minecraft.server.v1_15_R1.PacketEncoder.encode(PacketEncoder.java:42)
[21:11:36 WARN]:        at net.minecraft.server.v1_15_R1.PacketEncoder.encode(PacketEncoder.java:12)
[21:11:36 WARN]:        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
[21:11:36 WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[21:11:36 WARN]:        at java.lang.reflect.Method.invoke(Method.java:498)
[21:11:36 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector.encode(ChannelInjector.java:473)
[21:11:36 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector.access$100(ChannelInjector.java:64)
[21:11:36 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector$1.encode(ChannelInjector.java:243)
[21:11:36 WARN]:        at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
[21:11:36 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector$1.write(ChannelInjector.java:249)
[21:11:36 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717)
[21:11:36 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764)
[21:11:36 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790)
[21:11:36 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758)
[21:11:36 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:808)
[21:11:36 WARN]:        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025)
[21:11:36 WARN]:        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:294)
[21:11:36 WARN]:        at com.comphenix.protocol.injector.netty.ChannelProxy.writeAndFlush(ChannelProxy.java:327)
[21:11:36 WARN]:        at net.minecraft.server.v1_15_R1.NetworkManager.lambda$b$6(NetworkManager.java:300)
[21:11:36 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector$3.lambda$onMessageScheduled$1(ChannelInjector.java:321)
[21:11:36 WARN]:        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
[21:11:36 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
[21:11:36 WARN]:        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:384)
[21:11:36 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
[21:11:36 WARN]:        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[21:11:36 WARN]:        at java.lang.Thread.run(Thread.java:748)
[21:11:36 INFO]: junebug12851 lost connection: Internal Exception: io.netty.handler.codec.EncoderException: java.lang.NullPointerException
[21:11:36 INFO]: junebug12851 left the game

image

Version Info
https://pastebin.com/kPtkcHGT

Additional context
This is a simple scratch server, there's only 2 plugins installed, ProtocolLib and my plugin that uses ProtocolLib. The Server is Paper 1.15.2 and I'm using ProtocolLib 4.5.1 as instructed to do so on the Spigot home page for my version number.

I have several listeners and stuff that modify more simple packets and are doing very well without any errors so I don't know what I'm doing wrong here for this one although PlayerInfo is a bit more complex.

commented

Any help on this?