2011-07-15 14:43:39 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-07-15 17:29:06 +00:00
|
|
|
import java.util.Map.Entry;
|
2011-07-15 14:43:39 +00:00
|
|
|
import org.bukkit.Server;
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import com.earth2me.essentials.Util;
|
2011-07-15 17:29:06 +00:00
|
|
|
import java.util.ArrayList;
|
2011-07-15 16:47:36 +00:00
|
|
|
import java.util.Collections;
|
2011-07-15 17:29:06 +00:00
|
|
|
import java.util.Comparator;
|
2011-07-15 14:43:39 +00:00
|
|
|
import java.util.HashMap;
|
2011-07-15 17:29:06 +00:00
|
|
|
import java.util.List;
|
2011-07-15 14:43:39 +00:00
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
2011-07-15 17:29:06 +00:00
|
|
|
final Map<User, Double> balances = new HashMap<User, Double>();
|
2011-08-08 12:40:30 +00:00
|
|
|
for (User u : ess.getUserMap().getAllUsers())
|
2011-07-15 14:43:39 +00:00
|
|
|
{
|
2011-07-15 17:29:06 +00:00
|
|
|
balances.put(u, u.getMoney());
|
2011-07-15 14:43:39 +00:00
|
|
|
}
|
2011-07-15 17:29:06 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
});
|
2011-07-15 14:43:39 +00:00
|
|
|
int count = 0;
|
2011-07-15 16:47:36 +00:00
|
|
|
sender.sendMessage(Util.format("balanceTop", max));
|
2011-07-15 17:29:06 +00:00
|
|
|
for (Map.Entry<User, Double> entry : sortedEntries)
|
2011-07-15 14:43:39 +00:00
|
|
|
{
|
|
|
|
if (count == max)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2011-07-15 23:33:22 +00:00
|
|
|
sender.sendMessage(entry.getKey().getDisplayName() + ", " + Util.formatCurrency(entry.getValue(), ess));
|
2011-07-15 14:43:39 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|