mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
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:
+1
-2
@@ -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>
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user