mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-26 01:51:42 +01:00
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
This commit is contained in:
parent
1b0b0b1b57
commit
fb8f89e6dc
@ -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");
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user