From f49862145cd26306e0b80e87e776e771e3f1f432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=9D=97=E5=90=9B?= Date: Sun, 8 May 2022 11:51:32 +0800 Subject: [PATCH] add Command description --- src/main/java/emu/grasscutter/command/Command.java | 2 ++ src/main/java/emu/grasscutter/command/CommandHandler.java | 2 +- .../java/emu/grasscutter/command/commands/HelpCommand.java | 6 +++--- src/main/java/emu/grasscutter/tools/Tools.java | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/Command.java b/src/main/java/emu/grasscutter/command/Command.java index c94804678..734f454ea 100644 --- a/src/main/java/emu/grasscutter/command/Command.java +++ b/src/main/java/emu/grasscutter/command/Command.java @@ -9,6 +9,8 @@ public @interface Command { String usage() default "No usage specified"; + String description() default "No description specified"; + String[] aliases() default {}; String permission() default ""; diff --git a/src/main/java/emu/grasscutter/command/CommandHandler.java b/src/main/java/emu/grasscutter/command/CommandHandler.java index dadb87bb3..76d5d7b04 100644 --- a/src/main/java/emu/grasscutter/command/CommandHandler.java +++ b/src/main/java/emu/grasscutter/command/CommandHandler.java @@ -7,7 +7,7 @@ import java.util.List; public interface CommandHandler { - String description(); + default String description() { return null; }; /** * Send a message to the target. diff --git a/src/main/java/emu/grasscutter/command/commands/HelpCommand.java b/src/main/java/emu/grasscutter/command/commands/HelpCommand.java index dbb85bf9d..323c2878b 100644 --- a/src/main/java/emu/grasscutter/command/commands/HelpCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/HelpCommand.java @@ -43,7 +43,7 @@ public final class HelpCommand implements CommandHandler { } else { Command annotation = handler.getClass().getAnnotation(Command.class); - builder.append(" ").append(handler.description()).append("\n"); + builder.append(" ").append(handler.description() == null ? annotation.description(): handler.description()).append("\n"); builder.append(translate("commands.help.usage")).append(annotation.usage()); if (annotation.aliases().length >= 1) { builder.append("\n").append(translate("commands.help.aliases")); @@ -65,7 +65,7 @@ public final class HelpCommand implements CommandHandler { StringBuilder builder = new StringBuilder("\n" + translate("commands.help.available_commands") + "\n"); annotations.forEach((annotation, handler) -> { builder.append(annotation.label()).append("\n"); - builder.append(" ").append(handler.description()).append("\n"); + builder.append(" ").append(handler.description() == null ? annotation.description() : handler.description()).append("\n"); builder.append(translate("commands.help.usage")).append(annotation.usage()); if (annotation.aliases().length >= 1) { builder.append("\n").append(translate("commands.help.aliases")); @@ -82,7 +82,7 @@ public final class HelpCommand implements CommandHandler { CommandHandler.sendMessage(player, translate("commands.help.available_commands")); annotations.forEach((annotation, handler) -> { StringBuilder builder = new StringBuilder(annotation.label()).append("\n"); - builder.append(" ").append(handler.description()).append("\n"); + builder.append(" ").append(handler.description() == null ? annotation.description() : handler.description()).append("\n"); builder.append(translate("commands.help.usage")).append(annotation.usage()); if (annotation.aliases().length >= 1) { builder.append("\n").append(translate("commands.help.aliases")); diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index b5558833f..a1bcb1b9a 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -121,7 +121,7 @@ final class ToolsWithLanguageOption { while (cmdName.length() <= 15) { cmdName = " " + cmdName; } - writer.println(cmdName + " : " + handler.description()); + writer.println(cmdName + " : " + (handler.description() == null ? command.description() : handler.description())); }); writer.println();