Search in sources :

Example 1 with ResidentList

use of com.palmergames.bukkit.towny.object.ResidentList in project Towny by ElgarL.

the class TownyCommand method getMostResidents.

public List<String> getMostResidents(List<ResidentList> list, int maxListing) {
    List<String> output = new ArrayList<String>();
    KeyValueTable<ResidentList, Integer> kvTable = new KeyValueTable<ResidentList, Integer>();
    for (ResidentList obj : list) kvTable.put(obj, obj.getResidents().size());
    kvTable.sortByValue();
    kvTable.revese();
    int n = 0;
    for (KeyValue<ResidentList, Integer> kv : kvTable.getKeyValues()) {
        n++;
        if (maxListing != -1 && n > maxListing)
            break;
        ResidentList residentList = (ResidentList) kv.key;
        output.add(String.format(Colors.Blue + "%30s " + Colors.Gold + "|" + Colors.LightGray + " %10d", TownyFormatter.getFormattedName((TownyObject) residentList), (Integer) kv.value));
    }
    return output;
}
Also used : KeyValueTable(com.palmergames.util.KeyValueTable) ArrayList(java.util.ArrayList) ResidentList(com.palmergames.bukkit.towny.object.ResidentList)

Aggregations

ResidentList (com.palmergames.bukkit.towny.object.ResidentList)1 KeyValueTable (com.palmergames.util.KeyValueTable)1 ArrayList (java.util.ArrayList)1