From 305ebae9bf5e645fd29f099ef9707c47603aea60 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Fri, 11 Aug 2023 15:58:40 -0500 Subject: [PATCH] Attempt at fixing command registration Signed-off-by: Paul Reilly --- .../fns/patchwork/command/BukkitDelegate.java | 35 ++++++++++++------- .../fns/patchwork/command/CommandHandler.java | 5 +-- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Patchwork/src/main/java/fns/patchwork/command/BukkitDelegate.java b/Patchwork/src/main/java/fns/patchwork/command/BukkitDelegate.java index 0823307..95d9e44 100644 --- a/Patchwork/src/main/java/fns/patchwork/command/BukkitDelegate.java +++ b/Patchwork/src/main/java/fns/patchwork/command/BukkitDelegate.java @@ -24,6 +24,8 @@ package fns.patchwork.command; import fns.patchwork.command.annotation.Completion; +import fns.patchwork.command.annotation.Info; +import fns.patchwork.command.annotation.Permissive; import fns.patchwork.command.annotation.Subcommand; import fns.patchwork.provider.ContextProvider; import fns.patchwork.utils.logging.FreedomLogger; @@ -68,20 +70,19 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC { super(command.getInfo() .name()); + + final Info info = command.getInfo(); + final Permissive perms = command.getPerms(); + this.command = command; this.plugin = command.getPlugin(); - this.setDescription(command.getInfo() - .description()); - this.setUsage(command.getInfo() - .usage()); - this.setPermission(command.getPerms() - .perm()); - this.setAliases(Arrays.asList(command.getInfo() - .aliases())); - this.permissionMessage(Component.text(command.getPerms() - .noPerms())); - this.noConsole = command.getPerms() - .onlyPlayers(); + this.setLabel(info.name()); + this.setDescription(info.description()); + this.setUsage(info.usage()); + this.setPermission(perms.perm()); + this.setAliases(Arrays.asList(info.aliases())); + this.permissionMessage(Component.text(perms.noPerms())); + this.noConsole = perms.onlyPlayers(); } @Override @@ -216,6 +217,16 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC { final Set completions = command.getCompletions(); final List results = new ArrayList<>(); + + if (args.length == 0) + { + results.addAll(getAliases()); + results.add(getLabel()); + return results.stream() + .filter(s -> s.startsWith(alias)) + .toList(); + } + for (final Completion completion : completions) { if (completion.index() != args.length) diff --git a/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java b/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java index a77ae98..c0ff38f 100644 --- a/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java +++ b/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java @@ -61,10 +61,7 @@ public class CommandHandler */ public void registerCommand(final T command) { - final BukkitDelegate delegate = new BukkitDelegate(command); - - Bukkit.getCommandMap() - .register(plugin.getName(), delegate); + new BukkitDelegate(command).register(Bukkit.getServer().getCommandMap()); } /**