Search in sources :

Example 1 with KeyValueTable

use of com.palmergames.util.KeyValueTable in project Towny by ElgarL.

the class TownyCommand method getTopBankBalance.

public List<String> getTopBankBalance(List<TownyEconomyObject> list, int maxListing) throws EconomyException {
    List<String> output = new ArrayList<String>();
    KeyValueTable<TownyEconomyObject, Double> kvTable = new KeyValueTable<TownyEconomyObject, Double>();
    for (TownyEconomyObject obj : list) {
        kvTable.put(obj, obj.getHoldingBalance());
    }
    kvTable.sortByValue();
    kvTable.revese();
    int n = 0;
    for (KeyValue<TownyEconomyObject, Double> kv : kvTable.getKeyValues()) {
        n++;
        if (maxListing != -1 && n > maxListing)
            break;
        TownyEconomyObject town = (TownyEconomyObject) kv.key;
        output.add(String.format(Colors.LightGray + "%-20s " + Colors.Gold + "|" + Colors.Blue + " %s", TownyFormatter.getFormattedName(town), TownyEconomyHandler.getFormattedBalance((Double) kv.value)));
    }
    return output;
}
Also used : KeyValueTable(com.palmergames.util.KeyValueTable) ArrayList(java.util.ArrayList) TownyEconomyObject(com.palmergames.bukkit.towny.object.TownyEconomyObject)

Example 2 with KeyValueTable

use of com.palmergames.util.KeyValueTable in project Towny by ElgarL.

the class TownyCommand method getMostLand.

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

Example 3 with KeyValueTable

use of com.palmergames.util.KeyValueTable 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)

Example 4 with KeyValueTable

use of com.palmergames.util.KeyValueTable in project Towny by ElgarL.

the class War method getScores.

/**
 * @param maxListing Maximum lines to return. Value of -1 return all.
 * @return A list of the current scores per town sorted in descending order.
 */
public List<String> getScores(int maxListing) {
    List<String> output = new ArrayList<String>();
    output.add(ChatTools.formatTitle("War - Top Scores"));
    KeyValueTable<Town, Integer> kvTable = new KeyValueTable<Town, Integer>(townScores);
    kvTable.sortByValue();
    kvTable.revese();
    int n = 0;
    for (KeyValue<Town, Integer> kv : kvTable.getKeyValues()) {
        n++;
        if (maxListing != -1 && n > maxListing)
            break;
        Town town = (Town) kv.key;
        output.add(String.format(Colors.Blue + "%40s " + Colors.Gold + "|" + Colors.LightGray + " %4d", TownyFormatter.getFormattedName(town), (Integer) kv.value));
    }
    return output;
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) KeyValueTable(com.palmergames.util.KeyValueTable) ArrayList(java.util.ArrayList)

Example 5 with KeyValueTable

use of com.palmergames.util.KeyValueTable in project Towny by ElgarL.

the class War method getWinningTownScore.

public KeyValue<Town, Integer> getWinningTownScore() throws TownyException {
    KeyValueTable<Town, Integer> kvTable = new KeyValueTable<Town, Integer>(townScores);
    kvTable.sortByValue();
    kvTable.revese();
    if (kvTable.getKeyValues().size() > 0)
        return kvTable.getKeyValues().get(0);
    else
        throw new TownyException();
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) KeyValueTable(com.palmergames.util.KeyValueTable) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

KeyValueTable (com.palmergames.util.KeyValueTable)5 ArrayList (java.util.ArrayList)4 Town (com.palmergames.bukkit.towny.object.Town)2 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 ResidentList (com.palmergames.bukkit.towny.object.ResidentList)1 TownBlockOwner (com.palmergames.bukkit.towny.object.TownBlockOwner)1 TownyEconomyObject (com.palmergames.bukkit.towny.object.TownyEconomyObject)1