Solved Sort players in Tab-List using teams

Discussion in 'Spigot Plugin Development' started by matgsan, Jun 27, 2016.

  1. Hey,
    I am trying to sort players in the TAB List
    I registered these teams
    0-CEO-team
    1-DIR-team
    2-COORD-team
    3-ADM-team
    4-MOD-team
    5-HELPER-team
    6-DEV-team
    7-BUILDER-team
    8-YT-team
    9-VIP3-team
    10-VIP2-team
    11-VIP1-team
    12-MEMBRO-team

    i set the prefix one color, and the suffix the number that is in the name of the team, but for a unknown reason the tablist is showing like this

    [​IMG]

    I want to show like
    Matgsan
    DamonVampirinho
    Teste

    Anyone?
     
    #1 matgsan, Jun 27, 2016
    Last edited: Jun 27, 2016
  2. Is there a way to sort through abc order on tab?
     
  3. You can sort Array (Player[]) or collection (Collection<Player>, including List<Player> and Set<Player>).
    For sorting arrays, like Player[], you need to use Arrays.sort(...) and for collections, like Collection<Player> or List<Player> or Set<Player>, you need to use Collections.sort(...)

    If you want insta-help, use google, there is lot of topics about how to sort collections and arrays. Or, just ask there, I can give you example code, if you give up.
     
  4. This answer my question? If yes, i didnt get it
     
  5. its for @VentureForo that is necroposting it might be a solution for you a little but I still don't get what're you trying to do exactly.
     
  6. i set the prefix one color, and the suffix ^^, if you want this output in the tab then don't change the suffix.
     
  7. he wants to have his tab list be sorted by teams

    By what the picture shows, and what he says, he wants it organized like this:

    DEVs
    BUILDERs
    MODs
     
  8. well I don't get it but something like this ?

    // tab
    Code (Java):
      Devs           Mods
    player1        player3
    player2        player4
     
  9. It's like how normal servers have it ordered by ABC down the list, he wants it ordered by the teams

    DEV on top
    BUILDER below dev
    MOD below builder
    etc etc etc
     
  10. The GOLD Color Player is the CEO Team (0-CEO-team)
    The DARK RED Color Player is the ADM Team (3-ADM-team)
    The GRAY Color Player is the Member Team (12-MEMBRO-team)

    it should show in that order
    First the GOLD, second the DARK RED, and third the GRAY.
    But for a unknown reason the GRAY is in second and DARK RED in third
     
  11. well ?
    Code (Java):
    if(the player is mod) {
       player set color prefix gold
       return;
       }
       if(the player is admin) {
       player set color to another one
       return;
       }
    // or use switch case.
     
  12. Wait what?
    This is not going to order in the way i want, it just will add color into the player name...
    Look into my first post in this thread:
    0-CEO-team
    1-DIR-team
    2-COORD-team
    3-ADM-team
    4-MOD-team
    5-HELPER-team
    6-DEV-team
    7-BUILDER-team
    8-YT-team
    9-VIP3-team
    10-VIP2-team
    11-VIP1-team
    12-MEMBRO-team

    I want to players with in the first registered teams on top for example
    players in the 0-CEO-team in top of the rest, players int the3-ADM-team under 0-CEO-team, 1-DIR-team, 2-COORD-team but in top of the rest, players int the 12-MEMBRO-team should be under everyone, In the picture the Matgsan player is in the CEO team, the Teste player in the MEMBRO team, and the DamomVampirinho in the ADM team, but the DamomVampirinho is under Teste and should be in top of Teste

    Sorry for my bad english did u get it?
     
  13. Good, you gave an ID for each team.

    Sort the teams by the ID's natural ordering (Integer), which is lowest to greatest. (i.e -1, 0, 1)
     
  14. I thought doing this the TAB will sort automatically, how can i do this ?
     
  15. Code (Java):
    HashMap<Player, Integer> id = new HashMap<>();
     
  16. I still think you dont understand what i want to do.
    Tell me what did you understand?
     
  17. I understand are you the one who didn't ?
    you replied to this statement and said how to do that ?

    vv I replied use HashMap for that.

    HashMap<Team, Integer> id; or HashMap<Player, Integer> id;
     
  18. if you look in the top of the thread i already have the Teams sorted by id
    if i do
    Code (Text):
    for(Team t : scoreboard.getTeams()){
    System.out.println(t.getName())
    }
    the output is
    0-CEO-team
    1-DIR-team
    2-COORD-team
    3-ADM-team
    4-MOD-team
    5-HELPER-team
    6-DEV-team
    7-BUILDER-team
    8-YT-team
    9-VIP3-team
    10-VIP2-team
    11-VIP1-team
    12-MEMBRO-team

    so its sorted, but in the tab is not showing in these teams order
     
  19. Firestar311

    Supporter

    I have found out that you must use Packets to sort the tablist as the sorting is handled client-side and not server side.