From bea43e8798c535964090b5ec3efca465fa7ddf53 Mon Sep 17 00:00:00 2001 From: Charles DeLancey <46200123+Evidentsinger14@users.noreply.github.com> Date: Sun, 24 Nov 2024 21:11:41 -0500 Subject: [PATCH] Fix mini message parsing in NumberUtil#displayCurrency (#5921) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../java/com/earth2me/essentials/Trade.java | 9 ++++---- .../java/com/earth2me/essentials/User.java | 14 +++++------ .../essentials/commands/Commandbalance.java | 7 +++--- .../commands/Commandbalancetop.java | 4 ++-- .../essentials/commands/Commandeco.java | 7 +++--- .../essentials/commands/Commandpay.java | 5 ++-- .../essentials/commands/Commandsell.java | 10 ++++---- .../essentials/commands/Commandwhois.java | 2 +- .../essentials/commands/Commandworth.java | 7 +++--- .../economy/vault/VaultEconomyProvider.java | 3 ++- .../essentials/signs/SignBalance.java | 3 ++- .../textreader/KeywordReplacer.java | 3 ++- .../earth2me/essentials/utils/NumberUtil.java | 23 ++++++++++--------- 13 files changed, 53 insertions(+), 44 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Trade.java b/Essentials/src/main/java/com/earth2me/essentials/Trade.java index 8cfebc433f2..d0dceb11114 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Trade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Trade.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.craftbukkit.Inventories; import com.earth2me.essentials.craftbukkit.SetExpFix; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; @@ -191,7 +192,7 @@ public void isAffordableFor(final IUser user, final CompletableFuture f } if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) { - future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); + future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess)))); return; } @@ -202,7 +203,7 @@ public void isAffordableFor(final IUser user, final CompletableFuture f final BigDecimal money; if (command != null && !command.isEmpty() && (money = getCommandCost(user)).signum() > 0 && !user.canAfford(money)) { - future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(money, ess))); + future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(money, ess)))); return; } @@ -285,7 +286,7 @@ public void charge(final IUser user, final CompletableFuture future) { ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); } if (!user.canAfford(getMoney()) && getMoney().signum() > 0) { - future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); + future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess)))); return; } user.takeMoney(getMoney()); @@ -304,7 +305,7 @@ public void charge(final IUser user, final CompletableFuture future) { if (command != null) { final BigDecimal cost = getCommandCost(user); if (!user.canAfford(cost) && cost.signum() > 0) { - future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(cost, ess))); + future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(cost, ess)))); return; } user.takeMoney(cost); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index c928cba85b9..595c659f63e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -247,9 +247,9 @@ public void giveMoney(final BigDecimal value, final CommandSource initiator, fin return; } setMoney(getMoney().add(value), cause); - sendTl("addedToAccount", NumberUtil.displayCurrency(value, ess)); + sendTl("addedToAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess))); if (initiator != null) { - initiator.sendTl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)); + initiator.sendTl("addedToOthersAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess))); } } @@ -266,12 +266,12 @@ public void payUser(final User reciever, final BigDecimal value, final UserBalan if (canAfford(value)) { setMoney(getMoney().subtract(value), cause); reciever.setMoney(reciever.getMoney().add(value), cause); - sendTl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName()); - reciever.sendTl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName()); + sendTl("moneySentTo", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), reciever.getDisplayName()); + reciever.sendTl("moneyRecievedFrom", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName()); final TransactionEvent transactionEvent = new TransactionEvent(this.getSource(), reciever, value); ess.getServer().getPluginManager().callEvent(transactionEvent); } else { - throw new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(value, ess)); + throw new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess))); } } @@ -294,9 +294,9 @@ public void takeMoney(final BigDecimal value, final CommandSource initiator, fin } catch (final MaxMoneyException ex) { ess.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex); } - sendTl("takenFromAccount", NumberUtil.displayCurrency(value, ess)); + sendTl("takenFromAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess))); if (initiator != null) { - initiator.sendTl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)); + initiator.sendTl("takenFromOthersAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess))); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalance.java index 67a8db25e8e..4e94a735afd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalance.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.NumberUtil; import org.bukkit.Server; @@ -20,16 +21,16 @@ protected void run(final Server server, final CommandSource sender, final String } final User target = getPlayer(server, args, 0, false, true); - sender.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess)); + sender.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(target.getMoney(), ess))); } @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length == 1 && user.isAuthorized("essentials.balance.others")) { final User target = getPlayer(server, args, 0, true, true); - user.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess)); + user.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(target.getMoney(), ess))); } else if (args.length < 2) { - user.sendTl("balance", NumberUtil.displayCurrency(user.getMoney(), ess)); + user.sendTl("balance", AdventureUtil.parsed(NumberUtil.displayCurrency(user.getMoney(), ess))); } else { throw new NotEnoughArgumentsException(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index 79599a98f18..2135163afc9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -110,11 +110,11 @@ public void run() { future.thenRun(() -> { if (fresh) { final SimpleTextInput newCache = new SimpleTextInput(); - newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("serverTotal", NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess)))); + newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("serverTotal", AdventureUtil.parsed(NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess))))); int pos = 1; for (final Map.Entry entry : ess.getBalanceTop().getBalanceTopCache().entrySet()) { if (ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) { - newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess)))); + newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(entry.getValue().getBalance(), ess))))); } pos++; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeco.java index 88770333959..d8576a475dd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeco.java @@ -3,6 +3,7 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.NumberUtil; import com.google.common.collect.Lists; import net.ess3.api.MaxMoneyException; @@ -53,7 +54,7 @@ public void run(final Server server, final CommandSource sender, final String co if (player.getMoney().subtract(userAmount).compareTo(ess.getSettings().getMinMoney()) >= 0) { player.takeMoney(userAmount, sender, UserBalanceUpdateEvent.Cause.COMMAND_ECO); } else { - ess.showError(sender, new TranslatableException("minimumBalanceError", NumberUtil.displayCurrency(ess.getSettings().getMinMoney(), ess)), commandLabel); + ess.showError(sender, new TranslatableException("minimumBalanceError", AdventureUtil.parsed(NumberUtil.displayCurrency(ess.getSettings().getMinMoney(), ess))), commandLabel); } break; } @@ -64,8 +65,8 @@ public void run(final Server server, final CommandSource sender, final String co final boolean underMin = userAmount.compareTo(minBal) < 0; final boolean aboveMax = userAmount.compareTo(maxBal) > 0; player.setMoney(underMin ? minBal : aboveMax ? maxBal : userAmount, UserBalanceUpdateEvent.Cause.COMMAND_ECO); - player.sendTl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess)); - sender.sendTl("setBalOthers", player.getDisplayName(), NumberUtil.displayCurrency(player.getMoney(), ess)); + player.sendTl("setBal", AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess))); + sender.sendTl("setBalOthers", player.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess))); break; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java index 38778c2fa1a..acc4bbf1315 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java @@ -3,6 +3,7 @@ import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.StringUtil; import com.google.common.collect.Lists; @@ -70,7 +71,7 @@ public void run(final Server server, final User user, final String commandLabel, final BigDecimal amount = tempAmount; if (amount.compareTo(ess.getSettings().getMinimumPayAmount()) < 0) { // Check if amount is less than minimum-pay-amount - throw new TranslatableException("minimumPayAmount", NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess)); + throw new TranslatableException("minimumPayAmount", AdventureUtil.parsed(NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess))); } final AtomicBoolean informToConfirm = new AtomicBoolean(false); final boolean canPayOffline = user.isAuthorized("essentials.pay.offline"); @@ -117,7 +118,7 @@ public void run(final Server server, final User user, final String commandLabel, }); if (informToConfirm.get()) { final String cmd = "/" + commandLabel + " " + StringUtil.joinList(" ", args); - user.sendTl("confirmPayment", NumberUtil.displayCurrency(amount, ess), cmd); + user.sendTl("confirmPayment", AdventureUtil.parsed(NumberUtil.displayCurrency(amount, ess)), cmd); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java index 92ef2b3e247..4110de1024b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java @@ -82,7 +82,7 @@ public void run(final Server server, final User user, final String commandLabel, ess.showError(user.getSource(), new TranslatableException("cannotSellTheseNamedItems", String.join(ChatColor.RESET + ", ", names)), commandLabel); } if (count != 1) { - final String totalWorthStr = NumberUtil.displayCurrency(totalWorth, ess); + final AdventureUtil.ParsedPlaceholder totalWorthStr = AdventureUtil.parsed(NumberUtil.displayCurrency(totalWorth, ess)); if (args[0].equalsIgnoreCase("blocks")) { user.sendTl("totalWorthBlocks", totalWorthStr, totalWorthStr); } else { @@ -101,7 +101,7 @@ private BigDecimal sellItem(final User user, final ItemStack is, final String[] if (amount <= 0) { if (!isBulkSell) { - user.sendTl("itemSold", NumberUtil.displayCurrency(BigDecimal.ZERO, ess), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)); + user.sendTl("itemSold", AdventureUtil.parsed(NumberUtil.displayCurrency(BigDecimal.ZERO, ess)), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)); } return BigDecimal.ZERO; } @@ -120,9 +120,9 @@ private BigDecimal sellItem(final User user, final ItemStack is, final String[] Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), user.getMoney(), ess); user.giveMoney(result, null, UserBalanceUpdateEvent.Cause.COMMAND_SELL); final String typeName = is.getType().toString().toLowerCase(Locale.ENGLISH); - final String worthDisplay = NumberUtil.displayCurrency(worth, ess); - user.sendTl("itemSold", NumberUtil.displayCurrency(result, ess), amount, typeName, worthDisplay); - ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("itemSoldConsole", user.getName(), typeName, NumberUtil.displayCurrency(result, ess), amount, worthDisplay, user.getDisplayName()))); + final AdventureUtil.ParsedPlaceholder worthDisplay = AdventureUtil.parsed(NumberUtil.displayCurrency(worth, ess)); + user.sendTl("itemSold", AdventureUtil.parsed(NumberUtil.displayCurrency(result, ess)), amount, typeName, worthDisplay); + ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("itemSoldConsole", user.getName(), typeName, AdventureUtil.miniToLegacy(NumberUtil.displayCurrency(result, ess)), amount, AdventureUtil.miniToLegacy(worthDisplay.toString()), user.getDisplayName()))); return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandwhois.java index 4a82d9eab8a..b3eb0ca1877 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandwhois.java @@ -43,7 +43,7 @@ public void run(final Server server, final CommandSource sender, final String co final long playtimeMs = System.currentTimeMillis() - (user.getBase().getStatistic(PLAY_ONE_TICK) * 50L); sender.sendTl("whoisPlaytime", DateUtil.formatDateDiff(playtimeMs)); if (!ess.getSettings().isEcoDisabled()) { - sender.sendTl("whoisMoney", NumberUtil.displayCurrency(user.getMoney(), ess)); + sender.sendTl("whoisMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(user.getMoney(), ess))); } if (!sender.isPlayer() || ess.getUser(sender.getPlayer()).isAuthorized("essentials.whois.ip")) { sender.sendTl("whoisIPAddress", user.getBase().getAddress().getAddress().toString()); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java index 051f252127c..f9f982269b4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.MaterialUtil; import com.earth2me.essentials.utils.NumberUtil; import com.google.common.collect.Lists; @@ -45,7 +46,7 @@ public void run(final Server server, final User user, final String commandLabel, } } if (count > 1) { - final String totalWorthStr = NumberUtil.displayCurrency(totalWorth, ess); + final AdventureUtil.ParsedPlaceholder totalWorthStr = AdventureUtil.parsed(NumberUtil.displayCurrency(totalWorth, ess)); if (args.length > 0 && args[0].equalsIgnoreCase("blocks")) { user.sendTl("totalSellableBlocks", totalWorthStr, totalWorthStr); return; @@ -88,8 +89,8 @@ private BigDecimal itemWorth(final CommandSource sender, final User user, final final BigDecimal result = worth.multiply(BigDecimal.valueOf(amount)); final String typeName = is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - final String resultDisplay = NumberUtil.displayCurrency(result, ess); - final String worthDisplay = NumberUtil.displayCurrency(worth, ess); + final AdventureUtil.ParsedPlaceholder resultDisplay = AdventureUtil.parsed(NumberUtil.displayCurrency(result, ess)); + final AdventureUtil.ParsedPlaceholder worthDisplay = AdventureUtil.parsed(NumberUtil.displayCurrency(worth, ess)); if (MaterialUtil.getDamage(is) != 0) { sender.sendTl("worthMeta", typeName, MaterialUtil.getDamage(is), resultDisplay, amount, worthDisplay); } else { diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java index 18257fbbfe1..091c9a2f320 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; import com.earth2me.essentials.config.EssentialsUserConfiguration; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.StringUtil; import com.google.common.base.Charsets; @@ -61,7 +62,7 @@ public int fractionalDigits() { @Override public String format(double amount) { - return NumberUtil.displayCurrency(BigDecimal.valueOf(amount), ess); + return AdventureUtil.miniToLegacy(NumberUtil.displayCurrency(BigDecimal.valueOf(amount), ess)); } @Override diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBalance.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBalance.java index d27261d173d..aac87448fd4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBalance.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBalance.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.NumberUtil; import net.ess3.api.IEssentials; @@ -11,7 +12,7 @@ public SignBalance() { @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - player.sendTl("balance", NumberUtil.displayCurrency(player.getMoney(), ess)); + player.sendTl("balance", AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess))); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java index 2664a637ebe..e61c5ced543 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.ExecuteTimer; import com.earth2me.essentials.PlayerList; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.DescParseTickFormat; import com.earth2me.essentials.utils.EnumUtil; @@ -227,7 +228,7 @@ private String replaceLine(String line, final String fullMatch, final String[] m break; case BALANCE: if (user != null) { - replacer = NumberUtil.displayCurrency(user.getMoney(), ess); + replacer = AdventureUtil.miniToLegacy(NumberUtil.displayCurrency(user.getMoney(), ess)); } break; case MAILS: diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/NumberUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/NumberUtil.java index 9b253e2431a..cd1aef9d3c4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/NumberUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/NumberUtil.java @@ -65,21 +65,22 @@ public static String formatAsPrettyCurrency(final BigDecimal value) { return str; } + /** + * Note: this *can* return MiniMessage, make sure if this is sent to a player that it is wrapped in AdventureUtil#parsed. + */ public static String displayCurrency(final BigDecimal value, final IEssentials ess) { - String currency = formatAsPrettyCurrency(value); - String sign = ""; - if (value.signum() < 0) { - currency = currency.substring(1); - sign = "-"; - } - if (ess.getSettings().isCurrencySymbolSuffixed()) { - return sign + tlLiteral("currency", currency, ess.getSettings().getCurrencySymbol()); - } - return sign + tlLiteral("currency", ess.getSettings().getCurrencySymbol(), currency); + return displayCurrency(value, ess, false); } + /** + * Note: this *can* return MiniMessage, make sure if this is sent to a player that it is wrapped in AdventureUtil#parsed. + */ public static String displayCurrencyExactly(final BigDecimal value, final IEssentials ess) { - String currency = value.toPlainString(); + return displayCurrency(value, ess, true); + } + + private static String displayCurrency(final BigDecimal value, final IEssentials ess, final boolean exact) { + String currency = exact ? value.toPlainString() : formatAsPrettyCurrency(value); String sign = ""; if (value.signum() < 0) { currency = currency.substring(1);