Fix Bukkit Description being null, supply usage/description to Sponge/Bungee

This commit is contained in:
Aikar
2018-03-17 19:51:52 -04:00
parent 901359356f
commit ec235d80fc
3 changed files with 28 additions and 33 deletions
@@ -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 "";
}
}
@@ -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 "";
}
}
@@ -77,7 +77,8 @@ public class SpongeRootCommand implements CommandCallable, RootCommand {
@Override
public Optional<Text> 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) {