From ec235d80fc8d7662a40dc6c449c03c4c35ca858f Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 17 Mar 2018 19:51:52 -0400 Subject: [PATCH] Fix Bukkit Description being null, supply usage/description to Sponge/Bungee --- .../co/aikar/commands/BukkitRootCommand.java | 31 ------------------- .../java/co/aikar/commands/RootCommand.java | 24 ++++++++++++++ .../co/aikar/commands/SpongeRootCommand.java | 6 ++-- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/bukkit/src/main/java/co/aikar/commands/BukkitRootCommand.java b/bukkit/src/main/java/co/aikar/commands/BukkitRootCommand.java index 11970a22..db658455 100644 --- a/bukkit/src/main/java/co/aikar/commands/BukkitRootCommand.java +++ b/bukkit/src/main/java/co/aikar/commands/BukkitRootCommand.java @@ -94,35 +94,4 @@ public class BukkitRootCommand extends Command implements RootCommand { return defCommand; } - @Override - public String getDescription() { - final RegisteredCommand cmd = this.getDefaultRegisteredCommand(); - if (cmd != null) { - return cmd.helpText; - } - BaseCommand defCommand = getDefCommand(); - if (defCommand != null) { - Description descAnno = defCommand.getClass().getAnnotation(Description.class); - if (descAnno != null) { - return descAnno.value(); - } - } - return ""; - } - - @Override - public String getUsage() { - final RegisteredCommand cmd = this.getDefaultRegisteredCommand(); - if (cmd != null) { - return cmd.syntaxText; - } - BaseCommand defCommand = getDefCommand(); - if (defCommand != null) { - Syntax syntaxAnno = defCommand.getClass().getAnnotation(Syntax.class); - if (syntaxAnno != null) { - return syntaxAnno.value(); - } - } - return ""; - } } diff --git a/core/src/main/java/co/aikar/commands/RootCommand.java b/core/src/main/java/co/aikar/commands/RootCommand.java index be179a7a..2266a359 100644 --- a/core/src/main/java/co/aikar/commands/RootCommand.java +++ b/core/src/main/java/co/aikar/commands/RootCommand.java @@ -23,6 +23,8 @@ package co.aikar.commands; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Syntax; import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil; import com.google.common.collect.SetMultimap; @@ -108,4 +110,26 @@ interface RootCommand { default BaseCommand getDefCommand(){ return null; } + + + default String getDescription() { + final RegisteredCommand cmd = this.getDefaultRegisteredCommand(); + if (cmd != null) { + return cmd.helpText != null ? cmd.helpText : ""; + } + BaseCommand defCommand = getDefCommand(); + if (defCommand != null && defCommand.description != null) { + return defCommand.description; + } + return ""; + } + + + default String getUsage() { + final RegisteredCommand cmd = this.getDefaultRegisteredCommand(); + if (cmd != null) { + return cmd.syntaxText != null ? cmd.syntaxText : ""; + } + return ""; + } } diff --git a/sponge/src/main/java/co/aikar/commands/SpongeRootCommand.java b/sponge/src/main/java/co/aikar/commands/SpongeRootCommand.java index 6e69daca..6764ba7b 100644 --- a/sponge/src/main/java/co/aikar/commands/SpongeRootCommand.java +++ b/sponge/src/main/java/co/aikar/commands/SpongeRootCommand.java @@ -77,7 +77,8 @@ public class SpongeRootCommand implements CommandCallable, RootCommand { @Override public Optional getShortDescription(@NotNull CommandSource source) { - return Optional.empty(); + String description = getDescription(); + return description != null ? Optional.of(Text.of(description)) : Optional.empty(); } @Override @@ -87,7 +88,8 @@ public class SpongeRootCommand implements CommandCallable, RootCommand { @Override public Text getUsage(@NotNull CommandSource source) { - return Text.of(); + String usage = getUsage(); + return usage != null ? Text.of(usage) : Text.of(); } private CommandResult executeSponge(CommandIssuer sender, String commandLabel, String[] args) {