Skip to content

Make ChargeException translatable #5736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
16 changes: 8 additions & 8 deletions Essentials/src/main/java/com/earth2me/essentials/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ public void isAffordableFor(final IUser user, final CompletableFuture<Boolean> 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"));
}
}

Expand Down Expand Up @@ -285,7 +285,7 @@ public void charge(final IUser user, final CompletableFuture<Boolean> 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());
Expand All @@ -295,7 +295,7 @@ public void charge(final IUser user, final CompletableFuture<Boolean> 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());
Expand All @@ -304,7 +304,7 @@ public void charge(final IUser user, final CompletableFuture<Boolean> 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);
Expand All @@ -315,7 +315,7 @@ public void charge(final IUser user, final CompletableFuture<Boolean> 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());
Expand Down
2 changes: 1 addition & 1 deletion Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down