Implement confirmation dialogue for `/pay`. (#1002)

This commit is contained in:
Ali 'SupaHam' M 2016-12-18 15:03:03 +00:00 committed by GitHub
parent 6231a25413
commit dadc6b2d3a
27 changed files with 53 additions and 0 deletions

View File

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

View File

@ -28,7 +28,9 @@ import org.bukkit.potion.PotionEffectType;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -57,6 +59,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
private boolean ignoreMsg = false;
private String afkMessage;
private long afkSince;
private Map<User, BigDecimal> confirmingPayments = new WeakHashMap<>();
public User(final Player base, final IEssentials ess) {
super(base, ess);
@ -836,6 +839,11 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
return afkSince;
}
@Override
public Map<User, BigDecimal> getConfirmingPayments() {
return confirmingPayments;
}
/**
* Returns the {@link ItemStack} in the main hand or off-hand. If the main hand is empty then the offhand item is returned - also nullable.
*/

View File

@ -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"));

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Command {0} is improperly loaded.
compassBearing=\u00a76Bearing\: {0} ({1} degrees).
configFileMoveError=Failed to move config.yml to backup location.
configFileRenameError=Failed to rename temp file to config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Connected players\u00a7r
connectionFailed=Failed to open connection.
cooldownWithMessage=\u00a74Cooldown\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a7cPrikaz {0} je nespravne nacteny.
compassBearing=\u00a77Zmena orientace\: {0} ({1} stupnu).
configFileMoveError=Chyba pri presouvani config.yml do slozky se zalohou.
configFileRenameError=Chyba pri pokusu o prejmenovani docasneho souboru na config.yml
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=Pripojeni hraci\:
connectionFailed=Pokus o otevreni spojeni selhal.
cooldownWithMessage=\u00a7cOdpocet\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Kommandoen {0} er indl\u00e6st forkert.
compassBearing=\u00a76Pejling\: {0} ({1} grader).
configFileMoveError=Kunne ikke flytte config.yml til backup-lokation.
configFileRenameError=Kunne ikke omd\u00f8be midlertidig fil til config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Tilsluttede spillere\u00a7r
connectionFailed=Kunne ikke \u00e5bne forbindelse.
cooldownWithMessage=\u00a74Cooldown\: {0}

View File

@ -59,6 +59,7 @@ commandNotLoaded=\u00a74Befehl {0} ist nicht richtig geladen.
compassBearing=\u00a76Peilung\: {0} ({1} Grad).
configFileMoveError=Fehler beim Verschieben der config.yml in das Backupverzeichnis.
configFileRenameError=Verschieben einer tempor\u00e4ren Datei nach config.yml gescheitert.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Verbundene Spieler\u00a7r
connectionFailed=Fehler beim Verbindungsaufbau.
cooldownWithMessage=\u00a74Abklingzeit\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Command {0} is improperly loaded.
compassBearing=\u00a76Bearing\: {0} ({1} degrees).
configFileMoveError=Failed to move config.yml to backup location.
configFileRenameError=Failed to rename temp file to config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Connected players\u00a7r
connectionFailed=Failed to open connection.
cooldownWithMessage=\u00a74Cooldown\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74El comando {0} no est\u00e1 cargado correctamente.
compassBearing=\u00a76Transporte\: {0} ({1} grados).
configFileMoveError=Error al mover config.yml a la carpeta de la copia de seguridad.
configFileRenameError=Error al renombrar archivo temp a config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Jugadores conectados\u00a7r
connectionFailed=No se ha podido abrir la conexion.
cooldownWithMessage=\u00a74Tiempo restante\:\u00a76 {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74K\u00e4sk {0} on ebakoheselt laetud.
compassBearing=\u00a76Suund\: {0} ({1} kraadi).
configFileMoveError=Viga liigutades config.yml backup asukohta.
configFileRenameError=Viga temp faili \u00fcmber nimetamisega config.yml-ks.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76\u00dchendatud m\u00e4ngijad\u00a7r
connectionFailed=\u00dchenduse avamine eba\u00f5nnestus.
cooldownWithMessage=\u00a74Maha jahtumine\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a7cKomento {0} on v\u00e4\u00e4rin ladattu.
compassBearing=\u00a77Osoittaa\: {0} ({1} astetta).
configFileMoveError=Virhe siirrett\u00e4ess\u00e4 tiedostoa config.yml varmuuskopio sijaintiin.
configFileRenameError=Virhe nimett\u00e4ess\u00e4 tiedostoa temp tiedostoon config.yml
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a77Liittyneet pelaajat\u00a77r
connectionFailed=Virhe avattaessa yhteytt\u00e4.
cooldownWithMessage=\u00a7cJ\u00e4\u00e4htyminen\: {0}

View File

@ -59,6 +59,7 @@ commandNotLoaded=\u00a7cLa commande {0} a \u00e9t\u00e9 mal charg\u00e9e.
compassBearing=\u00a77Orientation \: {0} ({1} degr\u00e9s).
configFileMoveError=\u00c9chec du d\u00e9placement de config.yml vers l''emplacement de sauvegarde.
configFileRenameError=Impossible de renommer le fichier temporaire en config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a77Joueurs connect\u00e9s\u00a7r
connectionFailed=\u00c9chec de la connexion.
cooldownWithMessage=\u00a7cR\u00e9utilisation \: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Parancs {0} nincs bet\u00f6ltve.
compassBearing=\u00a76Ir\u00e1ny\: {0} ({1} fok).
configFileMoveError=Failed to move config.yml to backup location.
configFileRenameError=Failed to rename temp file to config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Csatlakozott j\u00e1t\u00e9kosok\u00a7r
connectionFailed=Failed to open connection.
cooldownWithMessage=\u00a74Cooldown\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Il comando {0} non e'' stato caricato correttamente.
compassBearing=\u00a76Bussola\: {0} ({1} gradi).
configFileMoveError=Impossibile spostare config.yml nel backup.
configFileRenameError=Impossibile rinominare il file temporaneo config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Giocatori connessi\u00a7r
connectionFailed=Connessione fallita.
cooldownWithMessage=\u00a7cTempo di ricarica\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a7c \uba85\ub839\uc5b4 {0}\ub97c \uc798\ubabb \ubd88\ub7ec\
compassBearing=\u00a77\uc88c\ud45c\: {0} (\ubc29\ud5a5\: {1})
configFileMoveError=config.yml\ub97c \ubc31\uc5c5 \uc704\uce58\ub85c \uc774\ub3d9\ud558\uc9c0 \ubabb\ud588\uc2b5\ub2c8\ub2e4.
configFileRenameError=\uc784\uc2dc \ud30c\uc77c\uc758 \uc774\ub984\uc744 Config.yml\ub85c \ubcc0\uacbd\ud558\uc9c0 \ubabb\ud588\uc2b5\ub2c8\ub2e4.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76\uc811\uc18d \uc911\uc778 \ud50c\ub808\uc774\uc5b4\u00a7r
connectionFailed=\uc5f0\uacb0\uc5d0 \uc2e4\ud328\ud558\uc600\uc2b5\ub2c8\ub2e4.
cooldownWithMessage=\u00a7c\uc7ac\uc0ac\uc6a9 \ub300\uae30\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Command {0} is improperly loaded.
compassBearing=\u00a76Bearing\: {0} ({1} degrees).
configFileMoveError=Failed to move config.yml to backup location.
configFileRenameError=Nepavyko pervadinti laikino failo \u012f config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Prisijung\u0119 \u017eaid\u0117jai\u00a7r
connectionFailed=Failed to open connection.
cooldownWithMessage=\u00a74Cooldown\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a7cOpdracht {0} is fout geladen.
compassBearing=\u00a77Ligging\: {0} ({1} graden).
configFileMoveError=Het verplaatsen van config.yml naar de backup locatie is mislukt.
configFileRenameError=Fout bij het hernoemen van de tijdelijke map naar config.yml
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Spelers online\u00a7r
connectionFailed=Fout bij het verbinden.
cooldownWithMessage=\u00a7cAfkoeltijd\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Komenda {0} nie jest zaladowana\!
compassBearing=\u00a77Lozko\: {0} ({1} stopni).
configFileMoveError=Nie udalo sie przeniesc config.yml do lokalizacji backupa.
configFileRenameError=Nie udalo sie zmienic nazwy tymczasowego pliku na config.yml
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a77Aktywni gracze\u00a7r
connectionFailed=Blad podczas otwierania polaczenia.
cooldownWithMessage=Odczekaj\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00A74Comando {0} est\u00E1 carregado incorretamente.
compassBearing=\u00A76Apontado para: {0} ({1} graus).
configFileMoveError=Falha ao mover a config.yml para o local do backup.
configFileRenameError=Falha ao alterar o nome do arquivo tempor\u00E1rio para config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00A76Jogadores conectados\u00A7r
connectionFailed=Falha ao conectar.
cooldownWithMessage=\u00A74Tempo restante: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00A74Comando {0} est\u00E1 carregado incorretamente.
compassBearing=\u00A76Apontado para\: {0} ({1} graus).
configFileMoveError=Falha ao mover a config.yml para o local do backup.
configFileRenameError=Falha ao renomear o arquivo tempor\u00E1rio para config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00A76Jogadores conectados\u00A7r
connectionFailed=Falha ao conectar.
cooldownWithMessage=\u00A74Tempo restante\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Comanda {0} este partial incarcata.
compassBearing=\u00a76Directie\: {0} ({1} grade).
configFileMoveError=Eroare mut\u00e2nd fi\u0219ierul config.yml in loca\u021bia Backup.
configFileRenameError=Eroare redenumind fi\u0219ierul config.yml.
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Juc\u0103tori conecta\u021bi\: \u00a7r
connectionFailed=Deschiderea conexiunii a e\u0219uat.
cooldownWithMessage=\u00a74Timp r\u0103mas\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74\u041a\u043e\u043c\u0430\u043d\u0434\u0430 {0} \u043d\u0
compassBearing=\u00a76\u0410\u0437\u0438\u043c\u0443\u0442\: {0} ({1} \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432).
configFileMoveError=\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c config.yml \u0432 \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e.
configFileRenameError=\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 config.yml
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76\u0418\u0433\u0440\u043e\u043a\u043e\u0432 \u043e\u043d\u043b\u0430\u0439\u043d\u00a7r
connectionFailed=\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.
cooldownWithMessage=\u00a74\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a7cKommando {0} \u00e4r felaktigt laddat.
compassBearing=\u00a77B\u00e4ring\: {0} ({1} grader).
configFileMoveError=Kunde inte flytta config.yml till backup-platsen.
configFileRenameError=Kunde inte byta namn p\u00e5 temp-filen till config.yml
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a77Anslutna spelare\u00a7r
connectionFailed=Kunde inte \u00f6ppna anslutning.
cooldownWithMessage=\u00a7cNedkylning\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74Komut Yuklenemedi\!
compassBearing=\u00a76Pusula\: {0} ({1}).
configFileMoveError=config.yml dosyasini yedekleme bolgesine tasima isleminde basarisiz oldu.
configFileRenameError=Ayarlar Yuklenirken Hata Olustu\!
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76Bagli Oyuncular\u00a7r
connectionFailed=Baglanti Kurulurken Hata Olustu\!
cooldownWithMessage=\u00a74Aralik\: {0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74 \u547d\u4ee4{0}\u52a0\u8f7d\u5931\u8d25
compassBearing=\u00a76\u65b9\u5411\:{0}\uff08{1}\u5ea6\uff09
configFileMoveError=\u79fb\u52a8config.yml\u6587\u4ef6\u5230\u5907\u4efd\u4f4d\u7f6e\u5931\u8d25
configFileRenameError=\u91cd\u547d\u540d\u7f13\u5b58\u6587\u4ef6\u4e3aconfig.yml\u5931\u8d25
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76\u76ee\u524d\u5728\u7ebf\: \u00a7r
connectionFailed=\u8fde\u63a5\u5931\u8d25.
cooldownWithMessage=\u00a74\u51b7\u5374\u65f6\u95f4\:{0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74 {0} \u547d\u4ee4\u52a0\u8f09\u5931\u6557
compassBearing=\u00a76\u65b9\u5411\:{0}\uff08{1}\u5ea6\uff09
configFileMoveError=\u79fb\u52d5config.yml\u6587\u4ef6\u5230\u5099\u4efd\u4f4d\u7f6e\u5931\u6557
configFileRenameError=\u91cd\u547d\u540d\u7de9\u5b58\u6587\u4ef6\u70baconfig.yml\u5931\u6557
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76\u76ee\u524d\u5728\u7dda\: \u00a7r
connectionFailed=\u9023\u63a5\u5931\u6557.
cooldownWithMessage=\u00a74\u51b7\u537b\u6642\u9593\:{0}

View File

@ -58,6 +58,7 @@ commandNotLoaded=\u00a74 {0} \u6307\u4ee4\u8f09\u5165\u5931\u6557
compassBearing=\u00a76\u65b9\u5411\:{0}\uff08{1}\u5ea6\uff09
configFileMoveError=\u79fb\u52d5config.yml\u6587\u4ef6\u5230\u5099\u4efd\u4f4d\u7f6e\u5931\u6557
configFileRenameError=\u91cd\u547d\u540d\u7de9\u5b58\u6587\u4ef6\u70baconfig.yml\u5931\u6557
confirmPayment=\u00a77To \u00a7lCONFIRM\u00a77 payment of \u00a76{0}\u00a77, please repeat command: \u00a76{1}
connectedPlayers=\u00a76\u76ee\u524d\u5728\u7dda\: \u00a7r
connectionFailed=\u9023\u63a5\u5931\u6557.
cooldownWithMessage=\u00a74\u51b7\u537b\u6642\u9593\:{0}