mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-04 04:51:41 +00:00
Implement confirmation dialogue for /pay
. (#1002)
This commit is contained in:
parent
6231a25413
commit
dadc6b2d3a
27 changed files with 53 additions and 0 deletions
|
@ -5,6 +5,7 @@ import com.earth2me.essentials.CommandSource;
|
|||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import org.bukkit.Server;
|
||||
|
@ -16,6 +17,7 @@ import static com.earth2me.essentials.I18n.tl;
|
|||
|
||||
public class Commandpay extends EssentialsLoopCommand {
|
||||
BigDecimal amount;
|
||||
boolean informToConfirm;
|
||||
|
||||
public Commandpay() {
|
||||
super("pay");
|
||||
|
@ -23,6 +25,7 @@ public class Commandpay extends EssentialsLoopCommand {
|
|||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
informToConfirm = false;
|
||||
if (args.length < 2) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
@ -42,6 +45,10 @@ public class Commandpay extends EssentialsLoopCommand {
|
|||
throw new Exception(tl("minimumPayAmount", NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess)));
|
||||
}
|
||||
loopOnlinePlayers(server, user.getSource(), false, user.isAuthorized("essentials.pay.multiple"), args[0], args);
|
||||
if (informToConfirm) {
|
||||
String cmd = "/" + commandLabel + " " + StringUtil.joinList(" ", (Object[]) args);
|
||||
user.sendMessage(tl("confirmPayment", NumberUtil.displayCurrency(amount, ess), cmd));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +59,19 @@ 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.
|
||||
// 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.
|
||||
// Clear previous confirmations to ensure that a new confirmation message is brought up.
|
||||
user.getConfirmingPayments().clear();
|
||||
this.informToConfirm = true;
|
||||
}
|
||||
user.getConfirmingPayments().put(player, amount);
|
||||
return;
|
||||
}
|
||||
user.payUser(player, amount);
|
||||
user.getConfirmingPayments().remove(player);
|
||||
Trade.log("Command", "Pay", "Player", user.getName(), new Trade(amount, ess), player.getName(), new Trade(amount, ess), user.getLocation(), ess);
|
||||
} catch (MaxMoneyException ex) {
|
||||
sender.sendMessage(tl("maxMoney"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue