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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations