Solved Sorting tablist by group name.

Discussion in 'Spigot Plugin Development' started by JacksonHogan, Jan 7, 2018.

Thread Status:
Not open for further replies.
  1. I'm trying to figure out how to sort the tablist by the players group names. I am not to familiar with packets. I figured the best way to accomplish this would be to remove the players from the tablist and add fake players to the tablist.
    I tried adding a player to the tablist...

    Code (Text):
        public void onPlayerJoin(PlayerJoinEvent e){
            Player player = e.getPlayer();
            PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
            PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
            try {
                Field a = packet.getClass().getDeclaredField("a");
                a.set(packet, EnumPlayerInfoAction.ADD_PLAYER);
                Field b = packet.getClass().getDeclaredField("b");
                List<PlayerInfoData> dataList = Lists.newArrayList();
                GameProfile gprofile = new GameProfile(UUID.randomUUID(), "TEST");
                dataList.add( PlayerInfoData(gprofile, 15, EnumGamemode.SURVIVAL, ChatSerializer.a("TEST")));
                b.set(packet, dataList);
            } catch (Exception e1) {
    I get no errors in console, and nothing happens.I have registered my events.. etc..
  2. it would probably be easier to use scoreboard teams than packets
    • Like Like x 1
    • Agree Agree x 1
  3. Alright, i will try using scoreboard teams and see how that goes, But I would still like to figure out what I did wrong with the packet code.
  4. This is probably your easiest bet. As for your code, you are making it a bit harder then you need to. Below is an example of code that adds a fake player named "test" to the tablist

    Code (Text):
    MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
            GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "test");
            EntityPlayer npc = new EntityPlayer(server, world, gameProfile, new PlayerInteractManager(world));
            PlayerConnection c = ((CraftPlayer) player).getHandle().playerConnection;
            c.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
  5. Awesome, I appreciate the help. I was able to sort the players.
    • Friendly Friendly x 1
Thread Status:
Not open for further replies.