CommandAlias and Subcommand on inner classes leads to unexpected behavior
I have the following setup:
@CommandAlias("main")
public class MainCommand extends BaseCommand {
@Subcommand("setup")
public void setup() { /* stuff */ }
@Subcommand("sub")
@CommandAlias("sc")
public class SubCommand extends BaseCommand {
@Subcommand("create")
public void create() { /* stuff */ }
}
}
My expectation is that the following commands exist:
/main setup
/main sub create
/sc create
However, the actual commands end up being:
/main setup
/main sub create
/sc sub create
Is this the intended behavior?
do you have @CommandAlias("main") on your MainCommand class?
Well yeah this is intended behavior. So that you can break subcommands into its own root class file, do CA/SC on it and define all commands in that file is for example /root sub
not sure if theres a clean way to achieve both
@MiniDigger yes. I updated the example.
@aikar Are you saying the desired behavior is not possible?
@dumptruckman you'll need another inner class sadly.
@CommandAlias("main")
public class MainCommand extends BaseCommand {
@Subcommand("setup")
public void setup() { /* stuff */ }
@Subcommand("sub")
public class SubCommand extends BaseCommand {
@CommandAlias("sc")
public class SubCommandInner extends BaseCommand {
@Subcommand("create")
public void create() { /* stuff */ }
}
}
}
Your desired syntax doesn't make sense on a root class, what would this be?
@CommandAlias("foo")
@Subcommand("bar")
@CommandPermission("command.foo.bar")
public class FooCommand extends BaseCommand {
@Subcommand("baz")
public void onBaz() {}
}
As it stands now, they are combined. /foo bar baz
I use this in my own commands to group sections of subcommands into their own files.
Alternatively, PR a feature to do like manager.registerCommandAlias("sc", "main sub");
@aikar I tried the extra inner class thing but ended up with the same result. I'm not sure why you would attempt this on a root class.
@dumptruckman because how it works currently DOES work on a root class and behaves consistently on a subclass. Ultimately, the syntax combination is already in use for a feature for ACF and the feature it currently provides is more consistent than your proposed idea, so not going to consider a breaking change there.
So to achieve what you are looking for, you need a different solution.
Ahhh, I see. Yes, I also considered a boolean param on the CommandAlias annotation as another way to deal with this but I couldn't think of what to name it. (Or just add another annotation to attain this desired behavior.)