From 8217606437f660bc227b949c7dd421fc93a86348 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 25 Dec 2024 08:54:05 +0700 Subject: [PATCH] refactor: `[click for usages]` when invalid argument --- build-number.txt | 2 +- .../chayapak1/chomens_bot/command/CommandContext.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build-number.txt b/build-number.txt index 5b398d96..16b75613 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1299 \ No newline at end of file +1300 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java b/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java index 5c146c76..76398416 100644 --- a/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java +++ b/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java @@ -3,6 +3,7 @@ package me.chayapak1.chomens_bot.command; import me.chayapak1.chomens_bot.Bot; import me.chayapak1.chomens_bot.data.PlayerEntry; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.TextDecoration; @@ -27,7 +28,7 @@ public class CommandContext { public String[] fullArgs; public String[] args; - public CommandContext(Bot bot, String prefix, PlayerEntry sender, boolean inGame) { + public CommandContext (Bot bot, String prefix, PlayerEntry sender, boolean inGame) { this.bot = bot; this.prefix = prefix; this.sender = sender; @@ -48,7 +49,7 @@ public class CommandContext { if (required) { throw new CommandException( Component.translatable( - "Expected %s at position %s (%s %s)", + "Expected %s at position %s (%s %s) [%s]", Component.text(type), Component.text(argsPosition), Component.text(prefix + userInputCommandName), @@ -57,7 +58,10 @@ public class CommandContext { Component .text(String.join(" ", args)) .append(Component.space()) - .append(UNKNOWN_ARGUMENT_COMPONENT) + .append(UNKNOWN_ARGUMENT_COMPONENT), + Component + .text("click for usages") + .clickEvent(ClickEvent.suggestCommand(prefix + "help " + this.commandName)) ) ); } else {