From 0a876c33a757bf4e8e5a89ab51b33715c84070a8 Mon Sep 17 00:00:00 2001 From: Ali Moghnieh Date: Sat, 7 Nov 2015 17:23:40 +0000 Subject: [PATCH] Add minimum-pay-amount setting to limit how little you can /pay someone. Add 'minimumPayAmount' translatable message. Create NumberUtil#displayCurrencyExactly(BigDecimal, IEssentials). --- Essentials/src/com/earth2me/essentials/ISettings.java | 2 ++ Essentials/src/com/earth2me/essentials/Settings.java | 4 ++++ .../src/com/earth2me/essentials/commands/Commandpay.java | 5 +++++ Essentials/src/com/earth2me/essentials/utils/NumberUtil.java | 4 ++++ Essentials/src/config.yml | 3 +++ Essentials/src/messages.properties | 1 + 6 files changed, 19 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index bd5db2f4a..9470e09a3 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -229,4 +229,6 @@ public interface ISettings extends IConf { boolean isDropItemsIfFull(); boolean isLastMessageReplyRecipient(); + + BigDecimal getMinimumPayAmount(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index d31ffa552..6a3dad769 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -1121,4 +1121,8 @@ public class Settings implements net.ess3.api.ISettings { @Override public boolean isLastMessageReplyRecipient() { return config.getBoolean("last-message-reply-recipient", false); } + + @Override public BigDecimal getMinimumPayAmount() { + return new BigDecimal(config.getString("minimum-pay-amount", "0.001")); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java index 3702bfb75..77daf0ccc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java @@ -4,6 +4,8 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.NumberUtil; + import net.ess3.api.MaxMoneyException; import org.bukkit.Server; @@ -32,6 +34,9 @@ public class Commandpay extends EssentialsLoopCommand { } amount = new BigDecimal(stringAmount); + if (amount.compareTo(ess.getSettings().getMinimumPayAmount()) < 0) { // Check if amount is less than minimum-pay-amount + throw new Exception(tl("minimumPayAmount", NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess))); + } loopOnlinePlayers(server, user.getSource(), false, user.isAuthorized("essentials.pay.multiple"), args[0], args); } diff --git a/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java b/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java index dae7a3fcb..f11abdbd6 100644 --- a/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java @@ -37,6 +37,10 @@ public class NumberUtil { return tl("currency", ess.getSettings().getCurrencySymbol(), formatAsCurrency(value)); } + public static String displayCurrencyExactly(final BigDecimal value, final IEssentials ess) { + return tl("currency", ess.getSettings().getCurrencySymbol(), value.toPlainString()); + } + public static boolean isInt(final String sInt) { try { Integer.parseInt(sInt); diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 12a2498f6..e3c98972b 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -536,6 +536,9 @@ economy-log-enabled: false # Default is false. use-bukkit-permissions: false +# Minimum acceptable amount to be used in /pay. +minimum-pay-amount: 0.001 + ############################################################ # +------------------------------------------------------+ # # | EssentialsHelp | # diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index d792aeef4..4f9ec6307 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -570,3 +570,4 @@ msgDisabledFor=\u00a76Receiving messages \u00a7cdisabled \u00a76for \u00a7c{0}\u msgEnabled=\u00a76Receiving messages \u00a7cenabled\u00a76. msgEnabledFor=\u00a76Receiving messages \u00a7cenabled \u00a76for \u00a7c{0}\u00a76. msgIgnore=\u00a7c{0} \u00a74has messages disabled. +minimumPayAmount=\u00a7cThe minimum amount you can pay is {0}.