summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorementalo <suror@gmx.co.uk>2011-07-15 15:43:39 +0100
committerementalo <suror@gmx.co.uk>2011-07-15 15:43:39 +0100
commitfb8f89e6dc677e340954805a0efe7392c622cafa (patch)
tree23fb51f8aa9e163983fb68d0ba995dc26d6873d2
parent1b0b0b1b571b6e5cf015dbad819da76ec291ab3a (diff)
downloadEssentials-fb8f89e6dc677e340954805a0efe7392c622cafa.tar
Essentials-fb8f89e6dc677e340954805a0efe7392c622cafa.tar.gz
Essentials-fb8f89e6dc677e340954805a0efe7392c622cafa.tar.lz
Essentials-fb8f89e6dc677e340954805a0efe7392c622cafa.tar.xz
Essentials-fb8f89e6dc677e340954805a0efe7392c622cafa.zip
Test #383 added balance top. Hardlimit max of 10 users at the moment. /balancetop retrieves all 10 /balancetop <1-10> retrieves the top number you specify
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java15
-rw-r--r--Essentials/src/com/earth2me/essentials/IEssentials.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java26
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java54
-rw-r--r--Essentials/src/plugin.yml4
5 files changed, 97 insertions, 5 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index 4674c3a31..e9fc12c38 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -192,17 +192,17 @@ public class Essentials extends JavaPlugin implements IEssentials
//pm.registerEvent(Type.SIGN_CHANGE, blockListener, Priority.Low, this);
//pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Lowest, this);
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Lowest, this);
-
+
final SignBlockListener signBlockListener = new SignBlockListener(this);
pm.registerEvent(Type.SIGN_CHANGE, signBlockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_PLACE, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BREAK, signBlockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_IGNITE, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BURN, signBlockListener, Priority.Low, this);
-
+
final SignPlayerListener signPlayerListener = new SignPlayerListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, signPlayerListener, Priority.Low, this);
-
+
final SignEntityListener signEntityListener = new SignEntityListener(this);
pm.registerEvent(Type.ENTITY_EXPLODE, signEntityListener, Priority.Low, this);
@@ -378,7 +378,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix)
- {
+ {
// Allow plugins to override the command via onCommand
if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
{
@@ -414,7 +414,7 @@ public class Essentials extends JavaPlugin implements IEssentials
if (sender instanceof Player)
{
user = getUser(sender);
- logger.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel , EssentialsCommand.getFinalArg(args, 0)));
+ logger.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
}
// New mail notification
@@ -670,6 +670,11 @@ public class Essentials extends JavaPlugin implements IEssentials
return u;
}
+ public Map<String, User> getAllUsers()
+ {
+ return users;
+ }
+
public User getOfflineUser(String name)
{
File userFolder = new File(getDataFolder(), "userdata");
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java
index cf6e62e71..34eac733e 100644
--- a/Essentials/src/com/earth2me/essentials/IEssentials.java
+++ b/Essentials/src/com/earth2me/essentials/IEssentials.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials;
import com.earth2me.essentials.register.payment.Methods;
import java.io.File;
import java.util.List;
+import java.util.Map;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -75,4 +76,6 @@ public interface IEssentials
IPermissionsHandler getPermissionsHandler();
void showError(final CommandSender sender, final Throwable exception, final String commandLabel);
+
+ Map<String, User> getAllUsers();
}
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index 442150fa3..2427af9f5 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -11,10 +11,15 @@ import java.net.URL;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Enumeration;
import java.util.GregorianCalendar;
+import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Level;
@@ -446,4 +451,25 @@ public class Util
logger.log(Level.WARNING, String.format("Translation file %s does not contain all translation keys.", currentLocale.toString()));
}
}
+
+ public static List sortMapByValueDesc(final Map m) {
+ List keys = new ArrayList();
+ keys.addAll(m.keySet());
+ Collections.sort(keys, Collections.reverseOrder(new Comparator() {
+ public int compare(Object o1, Object o2) {
+ Object v1 = m.get(o1);
+ Object v2 = m.get(o2);
+ if (v1 == null) {
+ return (v2 == null) ? 0 : 1;
+ }
+ else if (v1 instanceof Comparable) {
+ return ((Comparable) v1).compareTo(v2);
+ }
+ else {
+ return 0;
+ }
+ }
+ }));
+ return keys;
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
new file mode 100644
index 000000000..99e91ddca
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
@@ -0,0 +1,54 @@
+package com.earth2me.essentials.commands;
+
+import org.bukkit.Server;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.Util;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.bukkit.command.CommandSender;
+
+
+public class Commandbalancetop extends EssentialsCommand
+{
+ public Commandbalancetop()
+ {
+ super("balancetop");
+ }
+
+ @Override
+ protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
+ {
+ int max = 10;
+ if (args.length > 0)
+ {
+ try
+ {
+ if (Integer.parseInt(args[0]) < 10)
+ {
+ max = Integer.parseInt(args[0]);
+ }
+ }
+ catch (NumberFormatException ex)
+ {
+ //catch it because they tried to enter a string not number.
+ }
+ }
+ HashMap<User, Double> balances = new HashMap<User, Double>();
+ for (Map.Entry<String, User> u : ess.getAllUsers().entrySet())
+ {
+ balances.put(u.getValue(), u.getValue().getMoney());
+ }
+ int count = 0;
+ for (Iterator i = Util.sortMapByValueDesc(balances).iterator(); i.hasNext();)
+ {
+ if (count == max)
+ {
+ break;
+ }
+ User key = (User)i.next();
+ sender.sendMessage(key.getDisplayName() + ", " + Util.formatCurrency(balances.get(key)));
+ count++;
+ }
+ }
+}
diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml
index a2e4a6266..cea6c6e30 100644
--- a/Essentials/src/plugin.yml
+++ b/Essentials/src/plugin.yml
@@ -27,6 +27,10 @@ commands:
description: States the current balance of a player.
usage: /<command> <player>
aliases: [bal,emoney,ebalance,ebal]
+ balancetop:
+ description: Gets the top x balance values. (max 10)
+ usage: /<command> <max>
+ aliases:
ban:
description: Bans a player.
usage: /<command> [player] <reason>