Despical / CommandFramework

A lightweight annotation based command system
https://spigotmc.org/resources/89933
GNU General Public License v3.0
23 stars 5 forks source link

[Bug] Cmd aliases don't work with subcmds #10

Closed rokrieger closed 5 months ago

rokrieger commented 5 months ago

Description of Issue

When I use the @Command annotation and specify aliases they are not inherited in subcommands, i.e. they don't work in subcommands, only in commands.

Steps to Reproduce

Just typing "/k" sends the help message, but typing "/k remove" sends nothing. The same goes for completers, aliases only take the command, when you use aliases in subcommands it doesn't complete.

Ex:

    @Command(
            name = "kingdom",
            aliases = {"k", "kd"},
            permission = "kingdom.help"
    )
    public void help(CommandArguments args) {
        args.getSender().sendMessage(
                args.hasPermission("kingdom.admin")
                        ? KingdomConfig.helpAdminMessage
                        : KingdomConfig.helpMessage
        );
    }

    @Command(
            name = "kingdom.remove",
            permission = "kingdom.remove",
            min = 1, max = 1,
            usage = "Usage: /kingdom remove <player>",
            desc = "Removes a player from their kingdom"
    )
    public void remove(Player player, CommandArguments args) {
        if (player == null) {
            args.sendMessage(KingdomConfig.playerNotFoundMessage);
            return;
        }

        var kingdom = apiProvider.getKingdomByMember(player.getUniqueId());
        if (kingdom == null) {
            args.sendMessage(KingdomConfig.playerNotInKingdomMessage);
            return;
        }

        kingdom.removeMember(player.getUniqueId());

        args.sendMessage(KingdomConfig.playerRemovedMessage);
    }

    @Completer(name = "kingdom", aliases = "k")
    public List<String> kingdomCompletions(CommandArguments args) {
        return Arrays.asList("remove", "ally", "create", "delete", "set", "setrank", "leave", "createrank", "info");
    }

    @Completer(name = "kingdom.remove", permission = "kingdom.remove")
    public List<String> removeCompletions(CommandArguments args) {
        return Collections.singletonList("<player>");
    }

image image

Command Framework Version

1.4.1

Server Version

1.20

Stack Trace/Log Files/Crash Reports

No logs.

Additional Information

No additional information.

Despical commented 5 months ago

Could you try again to run the same code but with the latest commit? Also, you have to define aliases for each command and completer annotations indivually.

Maven dependency ```xml com.github.Despical CommandFramework 78a302c2b7 ```
Gradle dependency ``` dependencies { implementation 'com.github.Despical:CommandFramework:78a302c2b7'; } ```
Code (added aliases for testing) ```java @Command( name = "kingdom", aliases = {"k", "kd"}, permission = "kingdom.help" ) public void help(CommandArguments args) { args.getSender().sendMessage( args.hasPermission("kingdom.admin") ? KingdomConfig.helpAdminMessage : KingdomConfig.helpMessage ); } @Command( name = "kingdom.remove", permission = "kingdom.remove", aliases = {"k.remove", "k.rem", "removekingdom"}, min = 1, max = 1, usage = "Usage: /kingdom remove ", desc = "Removes a player from their kingdom" ) public void remove(Player player, CommandArguments args) { if (player == null) { args.sendMessage(KingdomConfig.playerNotFoundMessage); return; } var kingdom = apiProvider.getKingdomByMember(player.getUniqueId()); if (kingdom == null) { args.sendMessage(KingdomConfig.playerNotInKingdomMessage); return; } kingdom.removeMember(player.getUniqueId()); args.sendMessage(KingdomConfig.playerRemovedMessage); } @Completer(name = "kingdom", aliases = "k") public List kingdomCompletions(CommandArguments args) { return Arrays.asList("remove", "ally", "create", "delete", "set", "setrank", "leave", "createrank", "info"); } @Completer(name = "kingdom.remove", aliases = {"k.remove", "k.rem", "removekingdom"}, permission = "kingdom.remove") public List removeCompletions(CommandArguments args) { return Collections.singletonList(""); } ```

@rokrieger

rokrieger commented 5 months ago

I did exactly as you specified. Now it works fine, thanks problem solved!

Despical commented 5 months ago

No problem. I'm going to release the update tomorrow morning.