Solved Sorting tablist by players group.

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

Thread Status:
Not open for further replies.
  1. I'm trying to sort the tablist by the groups the players are in... EX: Owner first, Admin second.. etc..
    I am able to add/remove players from the tablist and create fake players on the tablist..
    (I am using vault to check groups)

    Code (Text):
    public static void runEvent(){
            Bukkit.getScheduler().scheduleSyncRepeatingTask(TablistSorter.plugin, new Runnable(){
                @Override
                public void run(){
                    for(Player players : Bukkit.getOnlinePlayers()){
                        TabManager.removeTablistPlayer(players);
                        if(TablistSorter.chat.getPrimaryGroup(players).equalsIgnoreCase("Owner")){
                            TabManager.addTablistPlayer(players);
                        }
                        if(TablistSorter.chat.getPrimaryGroup(players).equalsIgnoreCase("Admin")){
                            TabManager.addTablistPlayer(players);
                        }
                    }
                }
            }, 20, 20);
        }
    Code (Text):
    public static void addTablistPlayer(Player player) {
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
            GameProfile gameProfile = new GameProfile(player.getUniqueId(), player.getName());
            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));
        }
       
        public static void removeTablistPlayer(Player player){
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
            GameProfile gameProfile = new GameProfile(player.getUniqueId(), player.getName());
            EntityPlayer npc = new EntityPlayer(server, world, gameProfile, new PlayerInteractManager(world));
            PlayerConnection c = ((CraftPlayer) player).getHandle().playerConnection;
            c.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, npc));
        }
    The issue is that it doesn't actually put them the way im adding them.. It's still sorting them via alphabetical order.
     
  2. Try using scoreboard teams. Players of the same team are put together in the tablist. The order of the teams depends on the name of the teams.
    If you want to create a team called "Owner" that is at the top of the tablist, you have to create a scoreboard team named something like "00owner". Then, all players you add to this team will be at the top of the tablist. If you want to create another group, simply increase the number at the beginning of the team's name (e.g. "01admin").
     
    • Like Like x 1
    • Agree Agree x 1
  3. Alright, That'ts what people have been telling me to try and do. So It must be the best way to do it for now. I appreciate it thanks!
     
Thread Status:
Not open for further replies.