Injecting sub commands
Since 1.0.0
This is probably one of my favourite features of the MCCommand class. With it, you can add a sub command to an existing MCCommand at any argument position. Sub commands don't use an special class, so they can also be registered as an standalone command or even have sub commands themselves, so sub commands on sub commands. Let's see how that works.
First, let's create the actual sub command, this will be the /clan info sub command.
Now let's inject it to the /clan command itself, the info sub command should be injected on the position 0 of /clan as we will use it as /clan info, right before the main command name.
Automatizations
One thing to note is that once the sub command is injected, MCUtils will automatically deduce that when a sender tries to tab-complete (onTab
) the main command, in this case MainClanCommand, it should suggest the name and aliases of the injected commands. So if a user types on chat /clan, "info" will be suggested, so you don't have to do that manually, sub-commands that return false
on their hasAccess
method won't be included.
Tab suggestions are also filtered by MCUtils, so if the suggestion list is ["info", "create", "kick", "invite"] and the user types "/clan i" and then presses tab, the suggestions will only be "info" and "invite", as those are the only suggestions starting with "i".
Lastly, the most obvious one, you don't need to handle the logic of what sub command should be called when the user executes a command, this is done by MCUtils and is the whole point of the sub command system on the first place.
Last updated