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;
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<Completion> completions = command.getCompletions();
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)
{
if (completion.index() != args.length)

View File

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