How could I sort a List by a ChatColor?

Discussion in 'Plugin Development' started by elementalgodz11, Apr 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    elementalgodz11

    So I have been struggled with this for a while, sorting a list by colour:

    Here's what I have done currently, in the assumption it would be correctly sorted:
    Code:java
    1. public void addToList(String Perm) {
    2.  
    3. for (Player players : Bukkit.getOnlinePlayers()) {
    4.  
    5. if (players.hasPermission(Perm)) {
    6.  
    7. if (!inList.contains(players.getName())) {
    8.  
    9. inList.add(players.getDisplayName());
    10.  
    11. }
    12.  
    13. }
    14.  
    15. }
    16.  
    17. }
    18.  
    19. public void putInList() {
    20.  
    21. addToList(".owner");
    22. addToList(prefix + ".admin");
    23. addToList(prefix + ".moderator");
    24. addToList(prefix + ".pro");
    25. addToList(prefix + ".mvp");
    26. addToList(prefix + ".vip");
    27. addToList(prefix + ".default");
    28.  
    29. }
    30.  
    31. Text text = new Text("(" + getActualPlayerCount(p) + "/" + maxPlayers + "): ["); //FancyText - Basically same as StringBuilder
    32.  
    33. String prefix = "";
    34.  
    35. for (String playerList : inList) {
    36.  
    37. text.append(prefix);
    38. prefix = ChatColor.WHITE + ", ";
    39. text.append(playerList);
    40.  
    41. }
    42.  
    43. text.append(ChatColor.WHITE + "]");
    44.  
    45. text.send(p);


    But even the default's are shown before the owner in this, how would I be able to sort the list so the String is shown in this order, Owners, Admins, Moderators, Admins, etc. From highest to lowest. Thanks.
     
  2. Offline

    xXSniperzzXx_SD

    elementalgodz11
    I believe the chat color enum has something that lets you get the actual number for the chatcolor, you could probably sort it using that number
     
Thread Status:
Not open for further replies.

Share This Page