From 1778bf5ada1afc55d7326ffbfc6ecb9841b311e8 Mon Sep 17 00:00:00 2001 From: Ahmed Waleed <61851106+iiAhmedYT@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:24:03 +0200 Subject: [PATCH] Respect per player locale for command descriptions (#5972) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../com/earth2me/essentials/Essentials.java | 7 ++++++- .../essentials/commands/Commandhelp.java | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index 936f697bbb6..ad4e4719966 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -154,6 +154,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.MissingResourceException; import java.util.Set; import java.util.UUID; import java.util.function.Predicate; @@ -903,7 +904,11 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co } catch (final NotEnoughArgumentsException ex) { if (getSettings().isVerboseCommandUsages() && !cmd.getUsageStrings().isEmpty()) { sender.sendTl("commandHelpLine1", commandLabel); - sender.sendTl("commandHelpLine2", command.getDescription()); + String description = command.getDescription(); + try { + description = sender.tl(command.getName() + "CommandDescription"); + } catch (MissingResourceException ignored) {} + sender.sendTl("commandHelpLine2", description); sender.sendTl("commandHelpLine3"); for (Map.Entry usage : cmd.getUsageStrings().entrySet()) { sender.sendTl("commandHelpLineUsage", AdventureUtil.parsed(usage.getKey().replace("", commandLabel)), AdventureUtil.parsed(usage.getValue())); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java index 453a35bbcd7..2df0eb13f38 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.MissingResourceException; public class Commandhelp extends EssentialsCommand { public Commandhelp() { @@ -37,18 +38,25 @@ protected void run(final Server server, final User user, final String commandLab final String cmd = pageStr.substring(1); for (final Map.Entry knownCmd : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) { if (knownCmd.getKey().equalsIgnoreCase(cmd)) { + final Command bukkit = knownCmd.getValue(); + final boolean isEssCommand = bukkit instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) bukkit).getPlugin().equals(ess); + final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(bukkit.getName()) : null; user.sendTl("commandHelpLine1", cmd); - user.sendTl("commandHelpLine2", knownCmd.getValue().getDescription()); - user.sendTl("commandHelpLine4", knownCmd.getValue().getAliases().toString()); + String description = bukkit.getDescription(); + if (essCommand != null) { + try { + description = user.playerTl(bukkit.getName() + "CommandDescription"); + } catch (MissingResourceException ignored) {} + } + user.sendTl("commandHelpLine2", description); + user.sendTl("commandHelpLine4", bukkit.getAliases().toString()); user.sendTl("commandHelpLine3"); - final boolean isEssCommand = knownCmd.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) knownCmd.getValue()).getPlugin().equals(ess); - final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(knownCmd.getValue().getName()) : null; if (essCommand != null && !essCommand.getUsageStrings().isEmpty()) { for (Map.Entry usage : essCommand.getUsageStrings().entrySet()) { user.sendTl("commandHelpLineUsage", AdventureUtil.parsed(usage.getKey().replace("", cmd)), AdventureUtil.parsed(usage.getValue())); } } else { - user.sendMessage(knownCmd.getValue().getUsage()); + user.sendMessage(bukkit.getUsage()); } return; }