From a7792651bbdac3c715293e461d9b14a66609e03e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 7 May 2025 10:05:02 +0700 Subject: [PATCH] fix: help not working (had to change hover event :() --- build-number.txt | 2 +- .../chomens_bot/commands/HelpCommand.java | 35 ++++++++++++++++--- src/main/resources/language-en_us.json | 2 ++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/build-number.txt b/build-number.txt index 7284cb65..908a6046 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3149 \ No newline at end of file +3155 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/HelpCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/HelpCommand.java index 4d5d87b8..2c8b8f67 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/HelpCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/HelpCommand.java @@ -41,7 +41,7 @@ public class HelpCommand extends Command { } } - public Component getCommandList (final CommandContext context) throws CommandException { + public Component getCommandList (final CommandContext context) { final List list = new ObjectArrayList<>(); for (final TrustLevel level : TrustLevel.values()) { @@ -66,7 +66,9 @@ public class HelpCommand extends Command { .append(Component.join(JoinConfiguration.separator(Component.space()), list)); } - public List getCommandListByTrustLevel (final CommandContext context, final TrustLevel trustLevel) throws CommandException { + public List getCommandListByTrustLevel (final CommandContext context, final TrustLevel trustLevel) { + final Bot bot = context.bot; + final List list = new ObjectArrayList<>(); final List commandNames = new ObjectArrayList<>(); @@ -81,19 +83,42 @@ public class HelpCommand extends Command { Collections.sort(commandNames); for (final String name : commandNames) { + final String clickSuggestion = context.prefix + name; // *command + final String insertionSuggestion = context.prefix + this.name + " " + name; // *help list.add( Component .text(name) .color(trustLevel.component.color()) .clickEvent( - ClickEvent.suggestCommand(context.prefix + name) // *command + ClickEvent.suggestCommand(clickSuggestion) ) - .insertion(context.prefix + this.name + " " + name) // *help + .insertion(insertionSuggestion) .hoverEvent( + HoverEvent.showText( + Component.empty() + .color(NamedTextColor.GREEN) + .append( + Component.translatable( + "commands.help.hover.click_to_command", + Component.text(clickSuggestion, bot.colorPalette.string) + ) + ) + .append(Component.newline()) + .append( + Component.translatable( + "commands.help.hover.shift_click_to_help_command", + Component.text(insertionSuggestion, bot.colorPalette.string) + ) + ) + ) + ) + + // there are too many commands and having hover being the usages will make the command length > 32767 :( + /* .hoverEvent( HoverEvent.showText( getUsages(context, name) ) - ) + ) */ ); } diff --git a/src/main/resources/language-en_us.json b/src/main/resources/language-en_us.json index fc7e8e45..9ed03c1c 100644 --- a/src/main/resources/language-en_us.json +++ b/src/main/resources/language-en_us.json @@ -107,6 +107,8 @@ "commands.help.description": "Shows a command list or usage for a command", "commands.help.commands_text": "Commands ", "commands.help.trust_level": "Trust level: ", + "commands.help.hover.click_to_command": "Click to suggest: %s", + "commands.help.hover.shift_click_to_help_command": "Shift+Click to suggest: %s", "commands.help.error.unknown_command": "Unknown command", "commands.info.description": "Shows an info about various things",