add Command description

This commit is contained in:
方块君 2022-05-08 11:51:32 +08:00 committed by Melledy
parent 05e1e5502c
commit f49862145c
4 changed files with 7 additions and 5 deletions

View File

@ -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 "";

View File

@ -7,7 +7,7 @@ import java.util.List;
public interface CommandHandler {
String description();
default String description() { return null; };
/**
* Send a message to the target.

View File

@ -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"));

View File

@ -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();