mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-03 03:32:42 +02:00
Add more options to /balancetop and fix access to getPlayer() on offline user
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import static net.ess3.I18n._;
|
import static net.ess3.I18n._;
|
||||||
import net.ess3.api.IUser;
|
import net.ess3.api.IUser;
|
||||||
|
import net.ess3.permissions.Permissions;
|
||||||
import net.ess3.utils.FormatUtil;
|
import net.ess3.utils.FormatUtil;
|
||||||
import net.ess3.utils.textreader.ArrayListInput;
|
import net.ess3.utils.textreader.ArrayListInput;
|
||||||
import net.ess3.utils.textreader.TextPager;
|
import net.ess3.utils.textreader.TextPager;
|
||||||
@@ -33,7 +34,34 @@ public class Commandbalancetop extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("force") && sender.isOp())
|
if (args[0].equalsIgnoreCase("hide"))
|
||||||
|
{
|
||||||
|
if (args.length == 1 && isUser(sender) && Permissions.BALANCETOP_HIDE.isAuthorized(sender))
|
||||||
|
{
|
||||||
|
IUser user = getUser(sender);
|
||||||
|
user.getData().setBalancetopHide(!user.getData().isBalancetopHide());
|
||||||
|
user.queueSave();
|
||||||
|
sender.sendMessage(
|
||||||
|
user.getData().isBalancetopHide()
|
||||||
|
? "You are now hidden from /balancetop"
|
||||||
|
: "You are now shown in /balancetop"); //TODO:I18n
|
||||||
|
}
|
||||||
|
else if (args.length == 2 && Permissions.BALANCETOP_HIDE_OTHERS.isAuthorized(sender))
|
||||||
|
{
|
||||||
|
IUser user = ess.getUserMap().matchUser(args[1], true);
|
||||||
|
user.getData().setBalancetopHide(!user.getData().isBalancetopHide());
|
||||||
|
user.queueSave();
|
||||||
|
sender.sendMessage(
|
||||||
|
user.getData().isBalancetopHide()
|
||||||
|
? user.getName() + " is now hidden from /balancetop"
|
||||||
|
: user.getName() + " is now shown in /balancetop"); //TODO:I18n
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotEnoughArgumentsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("force") && Permissions.BALANCETOP_FORCE.isAuthorized(sender))
|
||||||
{
|
{
|
||||||
force = true;
|
force = true;
|
||||||
}
|
}
|
||||||
@@ -100,7 +128,7 @@ public class Commandbalancetop extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
if (force || cacheage <= System.currentTimeMillis() - CACHETIME)
|
if (force || cacheage <= System.currentTimeMillis() - CACHETIME)
|
||||||
{
|
{
|
||||||
cache.getLines().clear();
|
cache.getLines().clear();
|
||||||
final Map<String, Double> balances = new HashMap<String, Double>();
|
final Map<String, Double> balances = new HashMap<String, Double>();
|
||||||
double totalMoney = 0d;
|
double totalMoney = 0d;
|
||||||
for (String u : ess.getUserMap().getAllUniqueUsers())
|
for (String u : ess.getUserMap().getAllUniqueUsers())
|
||||||
@@ -110,8 +138,11 @@ public class Commandbalancetop extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
final double userMoney = user.getMoney();
|
final double userMoney = user.getMoney();
|
||||||
user.updateMoneyCache(userMoney);
|
user.updateMoneyCache(userMoney);
|
||||||
totalMoney += userMoney;
|
if (!user.getData().isBalancetopHide())
|
||||||
balances.put(user.getPlayer().getDisplayName(), userMoney);
|
{
|
||||||
|
totalMoney += userMoney;
|
||||||
|
balances.put(user.getName(), userMoney);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +155,7 @@ public class Commandbalancetop extends EssentialsCommand
|
|||||||
return -entry1.getValue().compareTo(entry2.getValue());
|
return -entry1.getValue().compareTo(entry2.getValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cache.getLines().add(_("serverTotal", FormatUtil.displayCurrency(totalMoney, ess)));
|
cache.getLines().add(_("serverTotal", FormatUtil.displayCurrency(totalMoney, ess)));
|
||||||
int pos = 1;
|
int pos = 1;
|
||||||
for (Map.Entry<String, Double> entry : sortedEntries)
|
for (Map.Entry<String, Double> entry : sortedEntries)
|
||||||
|
@@ -14,6 +14,9 @@ public enum Permissions implements IPermission
|
|||||||
AFK_OTHERS,
|
AFK_OTHERS,
|
||||||
BACK_ONDEATH,
|
BACK_ONDEATH,
|
||||||
BALANCE_OTHERS,
|
BALANCE_OTHERS,
|
||||||
|
BALANCETOP_FORCE,
|
||||||
|
BALANCETOP_HIDE,
|
||||||
|
BALANCETOP_HIDE_OTHERS,
|
||||||
BAN_EXEMPT,
|
BAN_EXEMPT,
|
||||||
BAN_NOTIFY,
|
BAN_NOTIFY,
|
||||||
BAN_OFFLINE,
|
BAN_OFFLINE,
|
||||||
|
@@ -104,6 +104,7 @@ public class UserData implements StorageObject
|
|||||||
private boolean socialspy;
|
private boolean socialspy;
|
||||||
private boolean npc;
|
private boolean npc;
|
||||||
private boolean powerToolsEnabled;
|
private boolean powerToolsEnabled;
|
||||||
|
private boolean balancetopHide = false;
|
||||||
|
|
||||||
public UserData()
|
public UserData()
|
||||||
{
|
{
|
||||||
|
@@ -29,7 +29,7 @@ commands:
|
|||||||
aliases: [bal,money,emoney,ebalance,ebal]
|
aliases: [bal,money,emoney,ebalance,ebal]
|
||||||
balancetop:
|
balancetop:
|
||||||
description: Gets the top balance values.
|
description: Gets the top balance values.
|
||||||
usage: /<command> <page>
|
usage: /<command> [pagenumber|hide [player]|force]
|
||||||
aliases: [baltop,ebaltop,ebalancetop]
|
aliases: [baltop,ebaltop,ebalancetop]
|
||||||
ban:
|
ban:
|
||||||
description: Bans a player.
|
description: Bans a player.
|
||||||
|
Reference in New Issue
Block a user