From 33e086ff05e02fd253b7c9b91a0304fc7877293d Mon Sep 17 00:00:00 2001 From: JRoy <10731363+JRoy@users.noreply.github.com> Date: Sat, 13 Jul 2024 18:25:48 -0400 Subject: [PATCH] Fix notEnoughMoney message not being translated correctly Fixes #5759 --- .../com/earth2me/essentials/commands/Commandpay.java | 4 +++- .../essentials/commands/EssentialsLoopCommand.java | 11 ++++++----- .../com/earth2me/essentials/xmpp/Commandxmppspy.java | 7 ++----- 3 files changed, 11 insertions(+), 11 deletions(-) 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 734c90fc8..38778c2fa 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java @@ -109,8 +109,10 @@ public class Commandpay extends EssentialsLoopCommand { user.setMoney(user.getMoney().add(amount)); } catch (final MaxMoneyException ignored) { } + } catch (final TranslatableException e) { + throw e; } catch (final Exception e) { - user.sendMessage(e.getMessage()); + throw new TranslatableException("errorWithMessage", e.getMessage()); } }); if (informToConfirm.get()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsLoopCommand.java b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsLoopCommand.java index 4c48caa3e..18418c587 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsLoopCommand.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsLoopCommand.java @@ -6,6 +6,7 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.StringUtil; import net.ess3.api.MaxMoneyException; +import net.ess3.api.TranslatableException; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -18,11 +19,11 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand { super(command); } - protected void loopOfflinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final String[] commandArgs) throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException { + protected void loopOfflinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final String[] commandArgs) throws TranslatableException, NotEnoughArgumentsException { loopOfflinePlayersConsumer(server, sender, multipleStringMatches, matchWildcards, searchTerm, user -> updatePlayer(server, sender, user, commandArgs)); } - protected void loopOfflinePlayersConsumer(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final UserConsumer userConsumer) throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException { + protected void loopOfflinePlayersConsumer(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final UserConsumer userConsumer) throws TranslatableException, NotEnoughArgumentsException { if (searchTerm.isEmpty()) { throw new PlayerNotFoundException(); } @@ -68,11 +69,11 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand { } } - protected void loopOnlinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final String[] commandArgs) throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException { + protected void loopOnlinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final String[] commandArgs) throws TranslatableException, NotEnoughArgumentsException { loopOnlinePlayersConsumer(server, sender, multipleStringMatches, matchWildcards, searchTerm, user -> updatePlayer(server, sender, user, commandArgs)); } - protected void loopOnlinePlayersConsumer(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final UserConsumer userConsumer) throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException { + protected void loopOnlinePlayersConsumer(final Server server, final CommandSource sender, final boolean multipleStringMatches, final boolean matchWildcards, final String searchTerm, final UserConsumer userConsumer) throws NotEnoughArgumentsException, TranslatableException { if (searchTerm.isEmpty()) { throw new PlayerNotFoundException(); } @@ -143,6 +144,6 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand { } public interface UserConsumer { - void accept(User user) throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException; + void accept(User user) throws NotEnoughArgumentsException, TranslatableException; } } diff --git a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/Commandxmppspy.java b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/Commandxmppspy.java index ef586c4b1..ad6c7d1a5 100644 --- a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/Commandxmppspy.java +++ b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/Commandxmppspy.java @@ -1,13 +1,10 @@ package com.earth2me.essentials.xmpp; -import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; import com.earth2me.essentials.commands.EssentialsLoopCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; -import com.earth2me.essentials.commands.PlayerExemptException; -import com.earth2me.essentials.commands.PlayerNotFoundException; -import net.ess3.api.MaxMoneyException; +import net.ess3.api.TranslatableException; import org.bukkit.Server; public class Commandxmppspy extends EssentialsLoopCommand { @@ -16,7 +13,7 @@ public class Commandxmppspy extends EssentialsLoopCommand { } @Override - protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException, PlayerExemptException, MaxMoneyException, ChargeException, PlayerNotFoundException { + protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException, TranslatableException { if (args.length == 0) { throw new NotEnoughArgumentsException(); }