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

Tab Completer per argument #13

Closed wockhardt-wizard closed 4 months ago

wockhardt-wizard commented 4 months ago
@Command(
            name = "bounty",
            desc = "Shows all available commands.",
            usage = "/bounty",
            onlyOp = false,
            senderType = Command.SenderType.BOTH
    )
    public void defaultCommand(CommandArguments arguments) {
        // do stuff
    }

    /*@Completer(
            name = "bounty"
    )
    public List<String> defaultCommandCompleter(CommandArguments arguments) {
        return Arrays.asList("help", "bdc", "tutorial", "check", "list", "top", "stats", "set", "buy", "immunity", "whitelist");
    }*/

    @Command(
            name = "bounty.set",
            usage = "/bounty set [player] [amount]",
            desc = "Set a bounty on a player.",
            min = 2,
            senderType = Command.SenderType.BOTH
    )
    public void bountySetCommand(CommandArguments arguments) {
       // do stuff
    }

The tab completer will work for every argument in the bounty.set command, how do i make the tab completer only work in one command instead of all of them

Despical commented 4 months ago

There are a few options such as:

@Completer(
    name = "bounty.set"
)
public List<String> bountyCompleter(CommandArguments arguments) {
    return Arrays.asList("arg1", "arg2");
}

or

@Completer(
        name = "bounty"
)
public List<String> bountyCompleter(CommandArguments arguments) {
    if (arguments.isArgumentsEmpty()) {
        return Arrays.asList("help", "bdc", "tutorial", "check", "list", "top", "stats", "set", "buy", "immunity", "whitelist");
    }

    String firstArg = arguments.getArgument(0);

    if ("set".equals(firstArg)) {
        return Arrays.asList("completer", "for", "set", "command");
    }

    // If you return null server may complete this as player names.
    // Should return an empty list if you do not want any completer in any case.
    return null;
}
wockhardt-wizard commented 4 months ago

Looks good, thank you !