From c85e179718944d3482a223c6f459b7149cab9b83 Mon Sep 17 00:00:00 2001 From: pop4959 Date: Sun, 7 Apr 2024 18:22:31 -0700 Subject: [PATCH] Make ChargeException translatable (#5736) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../com/earth2me/essentials/ChargeException.java | 10 ++++------ .../main/java/com/earth2me/essentials/Trade.java | 16 ++++++++-------- .../main/java/com/earth2me/essentials/User.java | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ChargeException.java b/Essentials/src/main/java/com/earth2me/essentials/ChargeException.java index adba3669d25..a8bde32eccc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ChargeException.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ChargeException.java @@ -1,11 +1,9 @@ package com.earth2me.essentials; -public class ChargeException extends Exception { - public ChargeException(final String message) { - super(message); - } +import net.ess3.api.TranslatableException; - public ChargeException(final String message, final Throwable throwable) { - super(message, throwable); +public class ChargeException extends TranslatableException { + public ChargeException(String tlKey, Object... args) { + super(tlKey, args); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Trade.java b/Essentials/src/main/java/com/earth2me/essentials/Trade.java index c1add6d9461..8cfebc433f2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Trade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Trade.java @@ -191,23 +191,23 @@ public void isAffordableFor(final IUser user, final CompletableFuture f } if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) { - future.completeExceptionally(new ChargeException(user.playerTl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess)))); + future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); return; } if (getItemStack() != null && !Inventories.containsAtLeast(user.getBase(), itemStack, itemStack.getAmount())) { - future.completeExceptionally(new ChargeException(user.playerTl("missingItems", getItemStack().getAmount(), ess.getItemDb().name(getItemStack())))); + future.completeExceptionally(new ChargeException("missingItems", getItemStack().getAmount(), ess.getItemDb().name(getItemStack()))); return; } final BigDecimal money; if (command != null && !command.isEmpty() && (money = getCommandCost(user)).signum() > 0 && !user.canAfford(money)) { - future.completeExceptionally(new ChargeException(user.playerTl("notEnoughMoney", NumberUtil.displayCurrency(money, ess)))); + future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(money, ess))); return; } if (exp != null && exp > 0 && SetExpFix.getTotalExperience(user.getBase()) < exp) { - future.completeExceptionally(new ChargeException(user.playerTl("notEnoughExperience"))); + future.completeExceptionally(new ChargeException("notEnoughExperience")); } } @@ -285,7 +285,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(user.playerTl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess)))); + future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); return; } user.takeMoney(getMoney()); @@ -295,7 +295,7 @@ public void charge(final IUser user, final CompletableFuture future) { ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); } if (!Inventories.containsAtLeast(user.getBase(), getItemStack(), getItemStack().getAmount())) { - future.completeExceptionally(new ChargeException(user.playerTl("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")))); + future.completeExceptionally(new ChargeException("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " "))); return; } Inventories.removeItemAmount(user.getBase(), getItemStack(), getItemStack().getAmount()); @@ -304,7 +304,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(user.playerTl("notEnoughMoney", NumberUtil.displayCurrency(cost, ess)))); + future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(cost, ess))); return; } user.takeMoney(cost); @@ -315,7 +315,7 @@ public void charge(final IUser user, final CompletableFuture future) { } final int experience = SetExpFix.getTotalExperience(user.getBase()); if (experience < getExperience() && getExperience() > 0) { - future.completeExceptionally(new ChargeException(user.playerTl("notEnoughExperience"))); + future.completeExceptionally(new ChargeException("notEnoughExperience")); return; } SetExpFix.setTotalExperience(user.getBase(), experience - getExperience()); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 16cabcf3ffb..c928cba85b9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -271,7 +271,7 @@ public void payUser(final User reciever, final BigDecimal value, final UserBalan final TransactionEvent transactionEvent = new TransactionEvent(this.getSource(), reciever, value); ess.getServer().getPluginManager().callEvent(transactionEvent); } else { - throw new ChargeException(tlLocale(playerLocale, "notEnoughMoney", NumberUtil.displayCurrency(value, ess))); + throw new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(value, ess)); } }