From 2393352770fa141cfc2d97c4a77e4ac0558e42ed Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 17 Feb 2024 20:02:16 +0100 Subject: [PATCH] Better display of BadCommandUsage message on paper server --- .../lib/commands/BadCommandUsage.java | 29 +++++++++++++++++++ .../paper/commands/PaperBrigadierCommand.java | 4 +++ 2 files changed, 33 insertions(+) create mode 100644 pandalib-commands/src/main/java/fr/pandacube/lib/commands/BadCommandUsage.java diff --git a/pandalib-commands/src/main/java/fr/pandacube/lib/commands/BadCommandUsage.java b/pandalib-commands/src/main/java/fr/pandacube/lib/commands/BadCommandUsage.java new file mode 100644 index 0000000..bf1de47 --- /dev/null +++ b/pandalib-commands/src/main/java/fr/pandacube/lib/commands/BadCommandUsage.java @@ -0,0 +1,29 @@ +package fr.pandacube.lib.commands; + +import java.util.logging.Logger; + +/** + * Throw an instance of this exception to indicate to the plugin command handler that the user has missused the command. + * The message, if provided, must indicate the reason of the mussusage of the command. It will be displayed on the + * screen with eventual indications of how to use the command (help command for example). + * If a {@link Throwable} cause is provided, it will be relayed to the plugin {@link Logger}. + * + */ +public class BadCommandUsage extends RuntimeException { + + public BadCommandUsage() { + super(); + } + + public BadCommandUsage(Throwable cause) { + super(cause); + } + + public BadCommandUsage(String message) { + super(message); + } + + public BadCommandUsage(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java index 2ee81cc..709ff27 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java @@ -10,6 +10,7 @@ import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.RootCommandNode; import fr.pandacube.lib.chat.Chat; +import fr.pandacube.lib.commands.BadCommandUsage; import fr.pandacube.lib.commands.BrigadierCommand; import fr.pandacube.lib.commands.SuggestionsSupplier; import fr.pandacube.lib.paper.permissions.PandalibPaperPermissions; @@ -461,6 +462,9 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand