summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-07-15 19:29:06 +0200
committersnowleo <schneeleo@gmail.com>2011-07-15 19:29:06 +0200
commitf4ef5a2094b7b812f8121d3061fdc7b571cd2ca6 (patch)
tree1b4ed3b6aa096f5f9c4b2d76c078a64c6dd16e12
parentaf364b4bb40df4190cdab31b12bdeb301841f7be (diff)
downloadEssentials-f4ef5a2094b7b812f8121d3061fdc7b571cd2ca6.tar
Essentials-f4ef5a2094b7b812f8121d3061fdc7b571cd2ca6.tar.gz
Essentials-f4ef5a2094b7b812f8121d3061fdc7b571cd2ca6.tar.lz
Essentials-f4ef5a2094b7b812f8121d3061fdc7b571cd2ca6.tar.xz
Essentials-f4ef5a2094b7b812f8121d3061fdc7b571cd2ca6.zip
Correct sorting
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java27
1 files changed, 18 insertions, 9 deletions
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<Double, User> balances = new TreeMap<Double, User>(Collections.reverseOrder());
- for (Map.Entry<String, User> u : ess.getAllUsers().entrySet())
+ final Map<User, Double> balances = new HashMap<User, Double>();
+ for (User u : ess.getAllUsers().values())
{
- balances.put(u.getValue().getMoney(), u.getValue());
+ balances.put(u, u.getMoney());
}
+
+ final List<Map.Entry<User, Double>> sortedEntries = new ArrayList<Map.Entry<User, Double>>(balances.entrySet());
+ Collections.sort(sortedEntries, new Comparator<Map.Entry<User, Double>>()
+ {
+ public int compare(final Entry<User, Double> entry1, final Entry<User, Double> entry2)
+ {
+ return -entry1.getValue().compareTo(entry2.getValue());
+ }
+ });
int count = 0;
sender.sendMessage(Util.format("balanceTop", max));
- for (Map.Entry<Double, User> ba : balances.entrySet())
+ for (Map.Entry<User, Double> 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++;
}
}