diff options
author | Iaccidentally <coryhuckaby@gmail.com> | 2013-04-27 23:44:23 -0400 |
---|---|---|
committer | Iaccidentally <coryhuckaby@gmail.com> | 2013-04-27 23:44:23 -0400 |
commit | 081b81d081cd22def582f00f8069038184eb657b (patch) | |
tree | eb65f0726f63db7ce5dab3e3aede0bdb24396ec6 | |
parent | 0e8e6178fcc3ff16074b3bf479fbac219327bbe6 (diff) | |
download | Essentials-081b81d081cd22def582f00f8069038184eb657b.tar Essentials-081b81d081cd22def582f00f8069038184eb657b.tar.gz Essentials-081b81d081cd22def582f00f8069038184eb657b.tar.lz Essentials-081b81d081cd22def582f00f8069038184eb657b.tar.xz Essentials-081b81d081cd22def582f00f8069038184eb657b.zip |
[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
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandeco.java | 102 | ||||
-rw-r--r-- | Essentials/src/messages.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_cs.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_da.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_de.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_en.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_es.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_fi.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_fr.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_it.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_nl.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_pl.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_pt.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_ro.properties | 2 | ||||
-rw-r--r-- | Essentials/src/messages_se.properties | 2 |
15 files changed, 73 insertions, 57 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index 20ec02644..16cbdbcc3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -19,27 +19,26 @@ public class Commandeco extends EssentialsCommand @Override 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) { throw new NotEnoughArgumentsException(); } - EcoCommands cmd; + Commandeco.EcoCommands cmd; + double startingBalance = (double)ess.getSettings().getStartingBalance(); double amount; + Double broadcast = null; + Double broadcastAll = null; try { - cmd = EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH)); - amount = Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")); + cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH)); + amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")); } catch (Exception ex) { throw new NotEnoughArgumentsException(ex); } - final double minBalance = ess.getSettings().getMinMoney(); - if (args[1].contentEquals("**")) { for (String sUser : ess.getUserMap().getAllUniqueUsers()) @@ -52,28 +51,13 @@ public class Commandeco extends EssentialsCommand break; case TAKE: - if (player.canAfford(amount, false)) - { - player.takeMoney(amount); - } - else - { - if (player.getMoney() > 0) - { - player.setMoney(0); - } - } + take(amount, player, null); break; case RESET: - player.setMoney(startingBalance); - broadcastAll = startingBalance; - break; - case SET: - boolean underMinimum = (player.getMoney() - amount) < minBalance; - player.setMoney(underMinimum ? minBalance : amount); - broadcastAll = underMinimum ? minBalance : amount; + set(amount, player, null); + broadcastAll = amount; break; } } @@ -90,28 +74,13 @@ public class Commandeco extends EssentialsCommand break; case TAKE: - if (player.canAfford(amount)) - { - player.takeMoney(amount); - } - else - { - if (player.getMoney() > 0) - { - player.setMoney(0); - } - } + take(amount, player, null); break; case RESET: - player.setMoney(startingBalance); - broadcast = startingBalance; - break; - case SET: - boolean underMinimum = (player.getMoney() - amount) < minBalance; - player.setMoney(underMinimum ? minBalance : amount); - broadcast = underMinimum ? minBalance : amount; + set(amount, player, null); + broadcast = amount; break; } } @@ -126,21 +95,12 @@ public class Commandeco extends EssentialsCommand break; case TAKE: - if (!player.canAfford(amount)) - { - throw new Exception(_("notEnoughMoney")); - - } - player.takeMoney(amount, sender); + take(amount, player, sender); break; case RESET: - player.setMoney(startingBalance); - break; - case SET: - boolean underMinimum = (player.getMoney() - amount) < minBalance; - player.setMoney(underMinimum ? minBalance : amount); + set(amount, player, sender); 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 { - GIVE, TAKE, RESET, SET + GIVE, TAKE, SET, RESET } -} +}
\ No newline at end of file diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index d0165fa6b..8676ba6da 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs. kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index 0bb449ca6..cc833c9ff 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -538,3 +538,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index b103b23fc..9707dc6a9 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}.
\ No newline at end of file diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 8c4cdd10e..9e4d5f63b 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index d0165fa6b..8676ba6da 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs. kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index fccd18329..13ec76e11 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index 246809d82..d59b7ecb3 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 2c6efe7cd..ab71a4ac5 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index ba415179f..245f1c0de 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index d349d5a80..c8a30dbac 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 8dc5095cf..69fcd2ecf 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Niepoprawny typ pogody cannotStackMob=\u00a74Nie masz uprawnien by stackowac wiele mobow kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index a3af47fcf..1682b521c 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_ro.properties b/Essentials/src/messages_ro.properties index 2f525eeec..e6017bc7c 100644 --- a/Essentials/src/messages_ro.properties +++ b/Essentials/src/messages_ro.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_se.properties b/Essentials/src/messages_se.properties index e41278abd..eae144c40 100644 --- a/Essentials/src/messages_se.properties +++ b/Essentials/src/messages_se.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. |