Solved Tab list sorting using scoreboard Teams

Discussion in 'Spigot Plugin Development' started by Maxx_Qc, Mar 18, 2020.

Thread Status:
Not open for further replies.
  1. Hey guys I'm having trouble sorting the tab list.

    upload_2020-3-18_2-51-35.png

    Of course, I would like the hero player to be underneath the owner player, and basic underneath the hero player. I've read a lot of things about scoreboard team alphabetical sorting but it doesn't seem to work. Here's my code:
    Code (Java):
    constructor() ->

    char[] alphabet = "ZYXWVUTSRQPONMLKJIHGFEDCBA".toCharArray();
            if (plugin.getServerScoreboard().getTeam(alphabet[permissionLevel] + name) == null)
            {
                this.team = plugin.getServerScoreboard().registerNewTeam(alphabet[permissionLevel]  + name);
                team.setAllowFriendlyFire(true);
                team.setDisplayName(getPrefix());
                team.setPrefix(getPrefix());
                team.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
                team.setCanSeeFriendlyInvisibles(permissionLevel >= 21);
            }
            else
                this.team = plugin.getServerScoreboard().getTeam(alphabet[permissionLevel]  + name);

    Code (Java):
    onEnable() ->
    this.serverScoreboard = Bukkit.getScoreboardManager().getNewScoreboard();

    onJoin() ->
    event.getPlayer().setScoreboard(PLUGIN.getServerScoreboard());
    setup(user.get(event.getPlayer()));

    setup() ->
    getRank().getTeam().addEntry(getName());
                getPlayerBase().updateCommands();
                getPlayerBase().setPlayerListName(getRank().getPrefix() + " §7" + getPlayerBase().getName() + (getSuffix() == null ? "" : " " + getSuffix()));
    Thanks in advance :)
     
    #1 Maxx_Qc, Mar 18, 2020
    Last edited: Mar 18, 2020
  2. I tried with displayname but it doesn't work either... it seems to be sorted in order that the players join
    In spectator mode, are the team ordered by how they are ordered in the tab?
     
    #2 Maxx_Qc, Mar 18, 2020
    Last edited: Mar 18, 2020
  3. Make teams start with numbers like 0000 as admin and moderator as 0001 and so on
     
  4. Tried that too. Works on reload but whenever someone joins they are on top if they have the basic rank
     
  5. That whats worked for me...
    I just called the functions onJoin and onEnable if a loop for all online players

    Code (Java):
    private static Scoreboard sb;

        public static void setScoreboard() {
           
            sb = Bukkit.getScoreboardManager().getNewScoreboard();
           
            sb.registerNewTeam("0000Owner");
            sb.registerNewTeam("0001Admin");
            sb.registerNewTeam("0002Developer");
            sb.registerNewTeam("0003Moderator");
            sb.registerNewTeam("0004Supporter");
            sb.registerNewTeam("0005Builder");
            sb.registerNewTeam("0006Supreme");
            sb.registerNewTeam("0007Premium");
            sb.registerNewTeam("0008Player");
           
            sb.getTeam("0000Owner").setPrefix("§4Inhaber §8┃ §4");
            sb.getTeam("0001Admin").setPrefix("§4Admin §8┃ §4");
            sb.getTeam("0002Developer").setPrefix("§bDev §8┃ §b");
            sb.getTeam("0003Moderator").setPrefix("§cMod §8┃ §c");
            sb.getTeam("0004Supporter").setPrefix("§9Sup §8┃ §9");
            sb.getTeam("0005Builder").setPrefix("§2Builder §8┃ §2");
            sb.getTeam("0006Supreme").setPrefix("§dSupreme §8┃ §d");
            sb.getTeam("0007Premium").setPrefix("§6Premium §8┃ §6");
            sb.getTeam("0008Player").setPrefix("§a");
           
            for(Player all : Bukkit.getOnlinePlayers()) {
                setTeams(all);
            }
           
        }
       
        @SuppressWarnings("deprecation")
        private static void setTeams(Player p) {
            String team = "";
            if(p.hasPermission("jslno.owner")) {
                team = "0000Owner";
            } else if(p.hasPermission("jslno.admin")) {
                team = "0001Admin";
            } else if(p.hasPermission("jslno.developer")) {
                team = "0002Developer";
            } else if(p.hasPermission("jslno.moderator")) {
                team = "0003Moderator";
            } else if(p.hasPermission("jslno.supporter")) {
                team = "0004Supporter";
            } else if(p.hasPermission("jslno.builder")) {
                team = "0005Builder";
            } else if(p.hasPermission("jslno.supreme")) {
                team = "0006Supreme";
            } else if(p.hasPermission("jslno.premium")) {
                team = "0007Premium";
            } else {
                team = "0008Player";
            }
           
            sb.getTeam(team).addPlayer(p);
            p.setScoreboard(sb);
           
        }
     
  6. You should not do that.
    And you should use the ChatColor enum.
     
  7. Its the same thing as me
     
  8. Fixed. Actually somehow my setup() method wasn't working onJoin but was working properly on reload... So yeah, everything is good :) Thanks
     
Thread Status:
Not open for further replies.