Skip to content

Commit

Permalink
Implement Bukkit Description for /help
Browse files Browse the repository at this point in the history
  • Loading branch information
aikar committed Mar 15, 2019
1 parent e9857cb commit 9c1521a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions bukkit/src/main/java/co/aikar/commands/BukkitRootCommand.java
Expand Up @@ -46,6 +46,22 @@ public class BukkitRootCommand extends Command implements RootCommand {
this.name = name;
}

@Override
public String getDescription() {
RegisteredCommand command = getDefaultRegisteredCommand();

if (command != null && !command.getHelpText().isEmpty()) {
return command.getHelpText();
}
if (command != null && command.scope.description != null) {
return command.scope.description;
}
if (defCommand.description != null) {
return defCommand.description;
}
return super.getDescription();
}

@Override
public String getCommandName() {
return name;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/co/aikar/commands/BaseCommand.java
Expand Up @@ -30,6 +30,7 @@
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.HelpCommand;
import co.aikar.commands.annotation.PreCommand;
import co.aikar.commands.annotation.Subcommand;
Expand Down Expand Up @@ -247,7 +248,7 @@ private void onRegister(CommandManager manager, String cmd) {

this.commandName = cmd != null ? cmd : self.getSimpleName().toLowerCase();
this.permission = annotations.getAnnotationValue(self, CommandPermission.class, Annotations.REPLACEMENTS);
this.description = this.commandName + " commands";
this.description = annotations.getAnnotationValue(self, Description.class, Annotations.NO_EMPTY | Annotations.REPLACEMENTS);
this.parentSubcommand = getParentSubcommand(self);
this.conditions = annotations.getAnnotationValue(self, Conditions.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);

Expand Down
Expand Up @@ -33,7 +33,7 @@
* This is used in the help menus.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.PARAMETER})
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE})
public @interface Description {
String value();
}
4 changes: 4 additions & 0 deletions example/src/main/java/co/aikar/acfexample/SomeCommand.java
Expand Up @@ -30,6 +30,7 @@
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Dependency;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Values;
Expand All @@ -40,6 +41,7 @@
import org.bukkit.plugin.Plugin;

@CommandAlias("acf|somecommand|sc|somcom")
@Description("Some ACF Command")
public class SomeCommand extends BaseCommand {

{
Expand Down Expand Up @@ -91,6 +93,7 @@ public void onCondition(CommandSender sender) {
@Subcommand("admin")
@CommandPermission("some.perm")
@CommandAlias("acfadmin|acfa")
@Description("Test Admin Commands")
public void onAdminCommand(Player player) {
player.sendMessage("You got permission!");
}
Expand Down Expand Up @@ -123,6 +126,7 @@ public void onTestDefault(CommandSender sender, @Default("Unknown User") String
// Then the enum will also pick up default of its values even though it was left off of the completion
@Subcommand("completions")
@CommandAlias("acfcompletions|acfc")
@Description("Test Completions")
@CommandCompletion("* * @test foo1|foo2|foo3")
public void onTestCompletion(CommandSender sender, OnlinePlayer player, World world, String test, String foo1, TestEnum e) {
sender.sendMessage("You got " + player.getPlayer().getName() + " - " + world.getName() + " - " + test + " - " + foo1 + " - " + e.name());
Expand Down

0 comments on commit 9c1521a

Please sign in to comment.