Implement player based toggle for pay confirmation prompts. Fixes #1032

This commit adds a new `/payconfirmtoggle` command with `/payconfirmon` and `/payconfirmoff` as well.
This commit is contained in:
Ali Moghnieh 2016-12-25 18:08:16 +00:00
parent 442d97a1b1
commit 5f83766dc1
No known key found for this signature in database
GPG Key ID: F09D3A1BAF2E6D70
6 changed files with 60 additions and 1 deletions

View File

@ -174,6 +174,10 @@ public interface IUser {
boolean isAcceptingPay();
void setAcceptingPay(boolean acceptingPay);
boolean isPromptingPayConfirm();
void setPromptingPayConfirm(boolean prompt);
Map<User, BigDecimal> getConfirmingPayments();
}

View File

@ -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;
}

View File

@ -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.

View File

@ -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.
}
}

View File

@ -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.

View File

@ -283,6 +283,10 @@ commands:
description: Toggles whether you are accepting payments.
usage: /<command>
aliases: [epaytoggle, payoff, epayoff, payon, epayon]
payconfirmtoggle:
description: Toggles whether you are prompted to confirm payments.
usage: /<command>
aliases: [epayconfirmtoggle, payconfirmoff, epayconfirmoff, payconfirmon, epayconfirmon, payconfirm, epayconfirm]
ping:
description: Pong!
usage: /<command>