Allow @Default to work on classes bound to a @Subcommand

```java
@CommandAlias("foo")
@Subcommand("bar")
class FooBarCommand {
    @Default
    public void onFooBar(CommandIssuer issuer) {}
}
```

Will now pass `/foo bar` to onFooBar.
Previously this required @Subcommand("") which was unintuitive
This commit is contained in:
Aikar
2017-12-01 23:56:26 -05:00
parent 7798c37ee0
commit fe1be188a4
3 changed files with 43 additions and 6 deletions
+1 -2
View File
@@ -10,7 +10,6 @@
</option>
<option name="goals">
<list>
<option value="clean" />
<option value="install" />
</list>
</option>
@@ -23,7 +22,7 @@
</option>
</MavenSettings>
<method>
<option name="Maven.BeforeRunTask" enabled="true" file="$PROJECT_DIR$/core/pom.xml" goal="clean install" />
<option name="Maven.BeforeRunTask" enabled="true" file="$PROJECT_DIR$/core/pom.xml" goal="install" />
</method>
</configuration>
</component>
+29
View File
@@ -0,0 +1,29 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ACF (Core + Bukkit + Paper)" type="MavenRunConfiguration" factoryName="Maven" singleton="true">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="install" />
</list>
</option>
<option name="profilesMap">
<map />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$/paper" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method>
<option name="Maven.BeforeRunTask" enabled="true" file="$PROJECT_DIR$/core/pom.xml" goal="install" />
<option name="Maven.BeforeRunTask" enabled="true" file="$PROJECT_DIR$/bukkit/pom.xml" goal="install" />
</method>
</configuration>
</component>
@@ -81,6 +81,7 @@ public abstract class BaseCommand {
private ExceptionHandler exceptionHandler = null;
CommandOperationContext lastCommandOperationContext;
private String parentSubcommand;
public BaseCommand() {}
public BaseCommand(String cmd) {
@@ -129,6 +130,7 @@ public abstract class BaseCommand {
this.description = this.commandName + " commands";
this.usageMessage = "/" + this.commandName;
this.parentSubcommand = getParentSubcommand(this.getClass());
final CommandPermission perm = self.getAnnotation(CommandPermission.class);
if (perm != null) {
@@ -137,16 +139,19 @@ public abstract class BaseCommand {
boolean foundDefault = false;
boolean foundUnknown = false;
boolean isParentEmpty = parentSubcommand.isEmpty();
for (Method method : self.getMethods()) {
method.setAccessible(true);
String sublist = null;
String sub = getSubcommandValue(method);
final Default def = method.getAnnotation(Default.class);
final HelpCommand helpCommand = method.getAnnotation(HelpCommand.class);
final CommandAlias commandAliases = method.getAnnotation(CommandAlias.class);
if (def != null || (!foundDefault && helpCommand != null)) {
if (!isParentEmpty && def != null) {
sub = parentSubcommand;
}
if (isParentEmpty && (def != null || (!foundDefault && helpCommand != null))) {
if (!foundDefault) {
registerSubcommand(method, DEFAULT);
if (def != null) {
@@ -236,9 +241,13 @@ public abstract class BaseCommand {
if (sub == null) {
return null;
}
List<String> subList = new ArrayList<>();
subList.add(sub.value());
Class<?> clazz = method.getDeclaringClass();
String parent = getParentSubcommand(clazz);
return parent == null || parent.isEmpty() ? sub.value() : parent + " " + sub.value();
}
private String getParentSubcommand(Class<?> clazz) {
List<String> subList = new ArrayList<>();
while (clazz != null) {
Subcommand classSub = clazz.getAnnotation(Subcommand.class);
if (classSub != null) {