From 1ef1cd98db572ad4dcaee973c4ef169591c69a0e Mon Sep 17 00:00:00 2001 From: Ali Moghnieh Date: Sun, 28 Jan 2018 16:47:17 +0000 Subject: [PATCH] Add default toggle for confirm commands in config.yml. --- .../com/earth2me/essentials/ISettings.java | 6 ++++- .../src/com/earth2me/essentials/Settings.java | 23 ++++++++++++++++++- .../src/com/earth2me/essentials/UserData.java | 16 ++++++------- Essentials/src/config.yml | 6 +++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 9557960e9..98a28d179 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -302,4 +302,8 @@ public interface ISettings extends IConf { int getMotdDelay(); boolean isDirectHatAllowed(); -} \ No newline at end of file + + List getDefaultDisabledConfirmCommands(); + + boolean isConfirmCommandEnabledByDefault(String commandName); +} diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index b85aab2aa..d94385d3f 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -532,6 +532,7 @@ public class Settings implements net.ess3.api.ISettings { npcsInBalanceRanking = _isNpcsInBalanceRanking(); currencyFormat = _getCurrencyFormat(); unprotectedSigns = _getUnprotectedSign(); + defaultDisabledConfirmCommands = _getDefaultDisabledConfirmCommands(); } private List itemSpawnBl = new ArrayList(); @@ -1418,4 +1419,24 @@ public class Settings implements net.ess3.api.ISettings { public boolean isDirectHatAllowed() { return config.getBoolean("allow-direct-hat", true); } -} \ No newline at end of file + + private List defaultDisabledConfirmCommands; + + private List _getDefaultDisabledConfirmCommands() { + List commands = config.getStringList("default-disabled-confirm-commands"); + for (int i = 0; i < commands.size(); i++) { + commands.set(i, commands.get(i).toLowerCase()); + } + return commands; + } + + @Override + public List getDefaultDisabledConfirmCommands() { + return defaultDisabledConfirmCommands; + } + + @Override + public boolean isConfirmCommandEnabledByDefault(String commandName) { + return !getDefaultDisabledConfirmCommands().contains(commandName.toLowerCase()); + } +} diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index d38b3ef19..1fe8f5581 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -898,14 +898,14 @@ public abstract class UserData extends PlayerExtension implements IConf { save(); } - private boolean confirmPay = false; // players deny pay confirmation by default + private Boolean confirmPay; - public boolean _getConfirmPay() { - return config.getBoolean("confirm-pay", false); + private Boolean _getConfirmPay() { + return (Boolean) config.get("confirm-pay"); } public boolean isPromptingPayConfirm() { - return confirmPay; + return confirmPay != null ? confirmPay : ess.getSettings().isConfirmCommandEnabledByDefault("pay"); } public void setPromptingPayConfirm(boolean prompt) { @@ -914,14 +914,14 @@ public abstract class UserData extends PlayerExtension implements IConf { save(); } - private boolean confirmClear = false; // players deny clear confirmation by default + private Boolean confirmClear; - public boolean _getConfirmClear() { - return config.getBoolean("confirm-clear", false); + private Boolean _getConfirmClear() { + return (Boolean) config.get("confirm-clear"); } public boolean isPromptingClearConfirm() { - return confirmClear; + return confirmClear != null ? confirmClear : ess.getSettings().isConfirmCommandEnabledByDefault("clearinventory"); } public void setPromptingClearConfirm(boolean prompt) { diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 22914bc32..4053edc5a 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -516,6 +516,12 @@ allow-bulk-buy-sell: true # This has no effect if the MOTD command or permission are disabled. delay-motd: 0 +# A list of commands that should have their complementary confirm commands disabled by default. +# This is empty by default, for the latest list of valid commands see the latest source config.yml. +default-disabled-confirm-commands: +#- pay +#- clearinventory + ############################################################ # +------------------------------------------------------+ # # | EssentialsHome | #