diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 96c6505dd..c251f5bb9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,16 +1,16 @@ package com.earth2me.essentials.commands; +import java.util.Map.Entry; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; +import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandbalancetop extends EssentialsCommand @@ -38,20 +38,29 @@ public class Commandbalancetop extends EssentialsCommand //catch it because they tried to enter a string not number. } } - Map balances = new TreeMap(Collections.reverseOrder()); - for (Map.Entry u : ess.getAllUsers().entrySet()) + final Map balances = new HashMap(); + for (User u : ess.getAllUsers().values()) { - balances.put(u.getValue().getMoney(), u.getValue()); + balances.put(u, u.getMoney()); } + + final List> sortedEntries = new ArrayList>(balances.entrySet()); + Collections.sort(sortedEntries, new Comparator>() + { + public int compare(final Entry entry1, final Entry entry2) + { + return -entry1.getValue().compareTo(entry2.getValue()); + } + }); int count = 0; sender.sendMessage(Util.format("balanceTop", max)); - for (Map.Entry ba : balances.entrySet()) + for (Map.Entry entry : sortedEntries) { if (count == max) { break; } - sender.sendMessage(ba.getValue().getDisplayName() + ", " + Util.formatCurrency(ba.getKey())); + sender.sendMessage(entry.getKey().getDisplayName() + ", " + Util.formatCurrency(entry.getValue())); count++; } }