ProtocolLib

3M Downloads

I can't add a player to the tablist 1.19.4

SuggarHidden opened this issue · 5 comments

commented

Server version: git-Paper-550 (MC: 1.19.4)
ProtocolLib Version: 5.0.0

Describe the question
The truth is that I do not know what is wrong, I understand that in 1.19.3 this changed a little but I understand that my code should work the same, I looked for information and I think it may be because of the EnumWrappers but I'm not sure.

Code

            WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(UUID.randomUUID(), args[1]);
            PlayerInfoData playerInfoData = new PlayerInfoData(wrappedGameProfile, 0, EnumWrappers.NativeGameMode.SURVIVAL,
                    WrappedChatComponent.fromText(args[1]));
            List<Player> players = new LinkedList<>(Bukkit.getServer().getOnlinePlayers());
            List<PlayerInfoData> currentPlayerData = new LinkedList<>();
            currentPlayerData.add(playerInfoData);

            for (Player player : players)
                currentPlayerData.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 0, null, null));

            PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
            packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
            packet.getPlayerInfoDataLists().write(0, currentPlayerData);
            ProxyTabList.getProtocolManager().broadcastServerPacket(packet);

Additional context
Error:

[09:55:59 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'ptl' in plugin ProxyTabList v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchCommand(CraftServer.java:929) ~[paper-1.19.4.jar:git-Paper-550]
        at org.bukkit.craftbukkit.v1_19_R3.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:64) ~[paper-1.19.4.jar:git-Paper-550]
        at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:264) ~[paper-1.19.4.jar:?]
        at net.minecraft.commands.Commands.performCommand(Commands.java:322) ~[?:?]
        at net.minecraft.commands.Commands.performCommand(Commands.java:306) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.performChatCommand(ServerGamePacketListenerImpl.java:2297) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$20(ServerGamePacketListenerImpl.java:2257) ~[?:?]
        at net.minecraft.util.thread.BlockableEventLoop.lambda$submitAsync$0(BlockableEventLoop.java:59) ~[?:?]
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
        at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.19.4.jar:git-Paper-550]
        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:1342) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:197) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
        at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1319) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1312) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
        at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1290) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1178) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[paper-1.19.4.jar:git-Paper-550]
        at java.lang.Thread.run(Thread.java:1589) ~[?:?]
Caused by: 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.jar:?]
        at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:316) ~[ProtocolLib.jar:?]
        at me.suggarhidden.proxytablist.cmd.onCommand(cmd.java:51) ~[ProxyTabList-0.1.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        ... 23 more

The error line is this:

packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);

And in the main(ProxyTabList) class I have this:

    private static ProtocolManager protocolManager;
    @Override
    public void onEnable() {
    //messages an other stuff
    protocolManager = ProtocolLibrary.getProtocolManager();
    //Listeners and cmds
    }
    public static ProtocolManager getProtocolManager() {
         return protocolManager;
    }

I don't know what to do anymore, I changed this code more than 10 times and I think my brain is going to explode, any help is appreciated. ಥ_ಥ

commented

for the actions I use the following:
packet.getPlayerInfoActions().write(0, EnumSet.of(PlayerInfoAction.ADD_PLAYER));

commented

for the actions I use the following: packet.getPlayerInfoActions().write(0, EnumSet.of(PlayerInfoAction.ADD_PLAYER));

Yes, I tried with that one and it works but it doesn't show me the player in the tablist only in the chat using the tab there, that's why I tried with the other one because according to what I understood searching in forums and reading it was with that method to show it in the tablist.

commented

As the underlying packet changed in Minecraft 1.19.3, packet.getPlayerInfoAction() can no longer be used.
Instead, you should be using packet.getPlayerInfoActions().write(0, EnumSet.of(PlayerInfoAction.ADD_PLAYER)); as @Brokkonaut already said. However, you probably need to add other actions from PlayerInfoAction to the set as well. The actions now determine which fields of the entry are sent to the client.

In addition, you need to change the index from 0 to 1 now: packet.getPlayerInfoDataLists().write(1, currentPlayerData);

commented

Thank you very much for the help, I have already informed myself a little more, the truth is that I was very frustrated for not finding the solution in time, if anyone else wants to know how, you can do it with this: (Thank you chatgpt for giving me an idea)

PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
packet.getPlayerInfoActions().write(0, EnumSet.of(
        EnumWrappers.PlayerInfoAction.ADD_PLAYER,
        EnumWrappers.PlayerInfoAction.UPDATE_LISTED
));
packet.getPlayerInfoDataLists().write(1, Collections.singletonList(playerInfoData));
ProxyTabList.getProtocolManager().broadcastServerPacket(packet);
commented

I'm glad you found a solution but do not do it this way. Just send one packet with both actions rather than two seperate packets