From 5f83766dc169a48f7c2cb9c58cab77d2b0b583b0 Mon Sep 17 00:00:00 2001 From: Ali Moghnieh Date: Sun, 25 Dec 2016 18:08:16 +0000 Subject: [PATCH] Implement player based toggle for pay confirmation prompts. Fixes #1032 This commit adds a new `/payconfirmtoggle` command with `/payconfirmon` and `/payconfirmoff` as well. --- .../src/com/earth2me/essentials/IUser.java | 4 +++ .../src/com/earth2me/essentials/UserData.java | 17 ++++++++++ .../essentials/commands/Commandpay.java | 2 +- .../commands/Commandpayconfirmtoggle.java | 32 +++++++++++++++++++ Essentials/src/messages.properties | 2 ++ Essentials/src/plugin.yml | 4 +++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index d66957cd6..9e786da79 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -174,6 +174,10 @@ public interface IUser { boolean isAcceptingPay(); void setAcceptingPay(boolean acceptingPay); + + boolean isPromptingPayConfirm(); + + void setPromptingPayConfirm(boolean prompt); Map getConfirmingPayments(); } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 4f1ffeb5f..d06c7145d 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -90,6 +90,7 @@ public abstract class UserData extends PlayerExtension implements IConf { lastAccountName = _getLastAccountName(); commandCooldowns = _getCommandCooldowns(); acceptingPay = _getAcceptingPay(); + confirmPay = _getConfirmPay(); } private BigDecimal money; @@ -896,6 +897,22 @@ public abstract class UserData extends PlayerExtension implements IConf { save(); } + private boolean confirmPay = true; // players accept pay by default + + public boolean _getConfirmPay() { + return config.getBoolean("confirm-pay", true); + } + + public boolean isPromptingPayConfirm() { + return confirmPay; + } + + public void setPromptingPayConfirm(boolean prompt) { + this.confirmPay = prompt; + config.setProperty("confirm-pay", prompt); + save(); + } + public UUID getConfigUUID() { return config.uuid; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java index d1f6933ca..3feefb82d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java @@ -59,7 +59,7 @@ public class Commandpay extends EssentialsLoopCommand { sender.sendMessage(tl("notAcceptingPay", player.getDisplayName())); return; } - if (!amount.equals(user.getConfirmingPayments().get(player))) { // checks if exists and if command needs to be repeated. + if (user.isPromptingPayConfirm() && !amount.equals(user.getConfirmingPayments().get(player))) { // checks if exists and if command needs to be repeated. // Used to reset confirmations and inform to confirm when a new pay command has been inserted. if (!informToConfirm) { // User hasnt been asked to confirm payment to this player, reset all confirmed payments and ask to confirm again. diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java new file mode 100644 index 000000000..3da30cccc --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java @@ -0,0 +1,32 @@ +package com.earth2me.essentials.commands; + +import static com.earth2me.essentials.I18n.tl; + +import com.earth2me.essentials.User; + +import org.bukkit.Server; + +public class Commandpayconfirmtoggle extends EssentialsCommand { + + public Commandpayconfirmtoggle() { + super("payconfirmtoggle"); + } + + @Override + public void run(Server server, User user, String commandLabel, String[] args) throws Exception { + boolean confirmingPay = !user.isPromptingPayConfirm(); + if (commandLabel.contains("payconfirmon")) { + confirmingPay = true; + } else if (commandLabel.contains("payconfirmoff")) { + confirmingPay = false; + } + user.setPromptingPayConfirm(confirmingPay); + if (confirmingPay) { + user.sendMessage(tl("payConfirmToggleOn")); + } else { + user.sendMessage(tl("payConfirmToggleOff")); + } + user.getConfirmingPayments().clear(); // Clear any outstanding confirmations. + } +} + diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index ee03ffc69..83da908b9 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -310,6 +310,8 @@ onlyPlayers=\u00a74Only in-game players can use \u00a7c{0}\u00a74. onlySunStorm=\u00a74/weather only supports sun/storm. orderBalances=\u00a76Ordering balances of\u00a7c {0} \u00a76users, please wait... oversizedTempban=\u00a74You may not ban a player for this period of time. +payConfirmToggleOn=\u00a76You will now be prompted to confirm payments. +payConfirmToggleOff=\u00a76You will no longer be prompted to confirm payments. payToggleOn=\u00a76You are now accepting payments. payToggleOff=\u00a76You are no longer accepting payments. payMustBePositive=\u00a74Amount to pay must be positive. diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 3827bf639..aa7340728 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -283,6 +283,10 @@ commands: description: Toggles whether you are accepting payments. usage: / aliases: [epaytoggle, payoff, epayoff, payon, epayon] + payconfirmtoggle: + description: Toggles whether you are prompted to confirm payments. + usage: / + aliases: [epayconfirmtoggle, payconfirmoff, epayconfirmoff, payconfirmon, epayconfirmon, payconfirm, epayconfirm] ping: description: Pong! usage: /