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

[Feature] Advanced usages #12

Closed rokrieger closed 5 months ago

rokrieger commented 5 months ago

Description of the new feature

I know it's possible to define a use for the commands, but would it be possible to use them to send messages to senders when you enter invalid arguments in the commands or don't specify the arguments correctly?

Ex:

public class BankCommands {

    public final APIProvider apiProvider = APIProvider.get();

    public BankCommands() {
        var commandFramework = apiProvider.getCommandFramework();

        commandFramework.registerCommands(this);
    }

    // /gold = returns info to sender

    // /gold a = returns usage msg to sender
    // /gold a b c ... = returns usage msg to sender
    // /gold info <player> = returns usage msg to sender

    @Command(
            name = "gold", aliases = {"bank"},
            permission = "gold.info",
            usage = "§cIncorrect usage: /gold",
            senderType = SenderType.PLAYER
    )
    public void info(CommandArguments args) {
        var gold = apiProvider.getBank((Player) args.getSender());
        args.sendMessage(BankConfig.infoMessage.replace("%gold%", NumberFormatter.formatDecimal(gold)));
    }

    // /gold help = returns help message to sender

    // /gold helpdsgds = returns usage msg to sender
    // /gold help a b c ... = returns usage msg to sender

    @Command(
            name = "gold.help", aliases = {"bank.help"},
            permission = "gold.help",
            usage = "§cIncorrect usage: /gold help",
            senderType = SenderType.PLAYER
    )
    public void help(CommandArguments args) {
        args.sendMessage("§c/gold -");
        args.sendMessage("§c/gold help");
    }

}
Despical commented 5 months ago

With the latest 2 commit you can now have a detailed access on the argument length messages. By default the command usage will be sent, if it is not set then the old messages will be sent to the sender.

You can also customize the behaviour by editing CommandFramework#SHORT_ARG_SIZE and CommandFramework#LONG_ARG_SIZE variables.

You can try the latest update using the version as 07de19300c.

rokrieger commented 5 months ago

It worked fine! Thank you!