mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-04-29 17:58:25 +00:00
[CHANGE] Rewrite eco command with better logic :: the command will now attempt to do exactly what it is told, with respect to the minimum balance :: fix missing messages
This commit is contained in:
parent
3396cf6e02
commit
02df03a4b1
15 changed files with 73 additions and 57 deletions
|
@ -19,27 +19,26 @@ public class Commandeco extends EssentialsCommand
|
||||||
@Override
|
@Override
|
||||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
Double broadcast = null;
|
|
||||||
Double broadcastAll = null;
|
|
||||||
final double startingBalance = (double)ess.getSettings().getStartingBalance();
|
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
EcoCommands cmd;
|
Commandeco.EcoCommands cmd;
|
||||||
|
double startingBalance = (double)ess.getSettings().getStartingBalance();
|
||||||
double amount;
|
double amount;
|
||||||
|
Double broadcast = null;
|
||||||
|
Double broadcastAll = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cmd = EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
||||||
amount = Double.parseDouble(args[2].replaceAll("[^0-9\\.]", ""));
|
amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : Double.parseDouble(args[2].replaceAll("[^0-9\\.]", ""));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException(ex);
|
throw new NotEnoughArgumentsException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
final double minBalance = ess.getSettings().getMinMoney();
|
|
||||||
|
|
||||||
if (args[1].contentEquals("**"))
|
if (args[1].contentEquals("**"))
|
||||||
{
|
{
|
||||||
for (String sUser : ess.getUserMap().getAllUniqueUsers())
|
for (String sUser : ess.getUserMap().getAllUniqueUsers())
|
||||||
|
@ -52,28 +51,13 @@ public class Commandeco extends EssentialsCommand
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TAKE:
|
case TAKE:
|
||||||
if (player.canAfford(amount, false))
|
take(amount, player, null);
|
||||||
{
|
|
||||||
player.takeMoney(amount);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (player.getMoney() > 0)
|
|
||||||
{
|
|
||||||
player.setMoney(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESET:
|
case RESET:
|
||||||
player.setMoney(startingBalance);
|
|
||||||
broadcastAll = startingBalance;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SET:
|
case SET:
|
||||||
boolean underMinimum = (player.getMoney() - amount) < minBalance;
|
set(amount, player, null);
|
||||||
player.setMoney(underMinimum ? minBalance : amount);
|
broadcastAll = amount;
|
||||||
broadcastAll = underMinimum ? minBalance : amount;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,28 +74,13 @@ public class Commandeco extends EssentialsCommand
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TAKE:
|
case TAKE:
|
||||||
if (player.canAfford(amount))
|
take(amount, player, null);
|
||||||
{
|
|
||||||
player.takeMoney(amount);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (player.getMoney() > 0)
|
|
||||||
{
|
|
||||||
player.setMoney(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESET:
|
case RESET:
|
||||||
player.setMoney(startingBalance);
|
|
||||||
broadcast = startingBalance;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SET:
|
case SET:
|
||||||
boolean underMinimum = (player.getMoney() - amount) < minBalance;
|
set(amount, player, null);
|
||||||
player.setMoney(underMinimum ? minBalance : amount);
|
broadcast = amount;
|
||||||
broadcast = underMinimum ? minBalance : amount;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,21 +95,12 @@ public class Commandeco extends EssentialsCommand
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TAKE:
|
case TAKE:
|
||||||
if (!player.canAfford(amount))
|
take(amount, player, sender);
|
||||||
{
|
|
||||||
throw new Exception(_("notEnoughMoney"));
|
|
||||||
|
|
||||||
}
|
|
||||||
player.takeMoney(amount, sender);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESET:
|
case RESET:
|
||||||
player.setMoney(startingBalance);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SET:
|
case SET:
|
||||||
boolean underMinimum = (player.getMoney() - amount) < minBalance;
|
set(amount, player, sender);
|
||||||
player.setMoney(underMinimum ? minBalance : amount);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,9 +115,37 @@ public class Commandeco extends EssentialsCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void take(double amount, final User player, final CommandSender sender)
|
||||||
|
{
|
||||||
|
double money = player.getMoney();
|
||||||
|
double minBalance = ess.getSettings().getMinMoney();
|
||||||
|
if (money - amount > minBalance)
|
||||||
|
{
|
||||||
|
player.takeMoney(amount, sender);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.sendMessage(_("takenFromAccount", Util.displayCurrency(money - minBalance, ess)));
|
||||||
|
sender.sendMessage(_("takenFromOthersAccount", Util.displayCurrency(money - minBalance, ess), player.getDisplayName(), Util.displayCurrency(player.getMoney(), ess)));
|
||||||
|
player.setMoney(minBalance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void set(double amount, final User player, final CommandSender sender)
|
||||||
|
{
|
||||||
|
double minBalance = ess.getSettings().getMinMoney();
|
||||||
|
boolean underMinimum = amount < minBalance;
|
||||||
|
player.setMoney(underMinimum ? minBalance : amount);
|
||||||
|
player.sendMessage(_("setBal", Util.displayCurrency(player.getMoney(), ess)));
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
sender.sendMessage(_("setBalOthers", player.getDisplayName(), Util.displayCurrency(player.getMoney(), ess)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private enum EcoCommands
|
private enum EcoCommands
|
||||||
{
|
{
|
||||||
GIVE, TAKE, RESET, SET
|
GIVE, TAKE, SET, RESET
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs.
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs.
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -538,3 +538,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs.
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs.
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Niepoprawny typ pogody
|
||||||
cannotStackMob=\u00a74Nie masz uprawnien by stackowac wiele mobow
|
cannotStackMob=\u00a74Nie masz uprawnien by stackowac wiele mobow
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
|
@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||||
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
cannotStackMob=\u00a74You do not have permission to stack multiple mobs
|
||||||
kitNotFound=\u00a74That kit does not exist.
|
kitNotFound=\u00a74That kit does not exist.
|
||||||
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
socialSpy=\u00a76SocialSpy for {0}\u00a76: {1}
|
||||||
|
setBal=\u00a7aYour balance was set to {0}.
|
||||||
|
setBalOthers=\u00a7aYou set {0}''s balance to {1}.
|
||||||
|
|
Loading…
Reference in a new issue