Merge pull request #28 from AtlasMediaGroup/fix/command-handling

Attempt at fixing command registration
This commit is contained in:
Eva 2023-08-11 22:03:53 +01:00 committed by GitHub
commit bec93a9142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 16 deletions

View File

@ -24,6 +24,8 @@
package fns.patchwork.command; package fns.patchwork.command;
import fns.patchwork.command.annotation.Completion; 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.command.annotation.Subcommand;
import fns.patchwork.provider.ContextProvider; import fns.patchwork.provider.ContextProvider;
import fns.patchwork.utils.logging.FreedomLogger; import fns.patchwork.utils.logging.FreedomLogger;
@ -68,20 +70,19 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC
{ {
super(command.getInfo() super(command.getInfo()
.name()); .name());
final Info info = command.getInfo();
final Permissive perms = command.getPerms();
this.command = command; this.command = command;
this.plugin = command.getPlugin(); this.plugin = command.getPlugin();
this.setDescription(command.getInfo() this.setLabel(info.name());
.description()); this.setDescription(info.description());
this.setUsage(command.getInfo() this.setUsage(info.usage());
.usage()); this.setPermission(perms.perm());
this.setPermission(command.getPerms() this.setAliases(Arrays.asList(info.aliases()));
.perm()); this.permissionMessage(Component.text(perms.noPerms()));
this.setAliases(Arrays.asList(command.getInfo() this.noConsole = perms.onlyPlayers();
.aliases()));
this.permissionMessage(Component.text(command.getPerms()
.noPerms()));
this.noConsole = command.getPerms()
.onlyPlayers();
} }
@Override @Override
@ -216,6 +217,16 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC
{ {
final Set<Completion> completions = command.getCompletions(); final Set<Completion> completions = command.getCompletions();
final List<String> results = new ArrayList<>(); final List<String> 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) for (final Completion completion : completions)
{ {
if (completion.index() != args.length) if (completion.index() != args.length)

View File

@ -61,10 +61,7 @@ public class CommandHandler
*/ */
public <T extends Commander> void registerCommand(final T command) public <T extends Commander> void registerCommand(final T command)
{ {
final BukkitDelegate delegate = new BukkitDelegate(command); new BukkitDelegate(command).register(Bukkit.getServer().getCommandMap());
Bukkit.getCommandMap()
.register(plugin.getName(), delegate);
} }
/** /**