diff --git a/core/src/main/java/co/aikar/commands/BaseCommand.java b/core/src/main/java/co/aikar/commands/BaseCommand.java index 1b6dd292..3382df7e 100644 --- a/core/src/main/java/co/aikar/commands/BaseCommand.java +++ b/core/src/main/java/co/aikar/commands/BaseCommand.java @@ -68,6 +68,7 @@ public abstract class BaseCommand { @SuppressWarnings("WeakerAccess") private String[] origArgs; CommandManager manager = null; + BaseCommand parentCommand; Map registeredCommands = new HashMap<>(); String description; String commandName; @@ -104,6 +105,9 @@ public abstract class BaseCommand { return origArgs; } + void setParentCommand(BaseCommand command) { + this.parentCommand = command; + } void onRegister(CommandManager manager) { onRegister(manager, this.commandName); } @@ -184,16 +188,16 @@ public abstract class BaseCommand { register(cmd, this); } for (Class clazz : this.getClass().getDeclaredClasses()) { - if (BaseSubCommand.class.isAssignableFrom(clazz)) { + if (BaseCommand.class.isAssignableFrom(clazz)) { try { - BaseSubCommand subCommand = null; + BaseCommand subCommand = null; Constructor[] declaredConstructors = clazz.getDeclaredConstructors(); for (Constructor declaredConstructor : declaredConstructors) { declaredConstructor.setAccessible(true); Parameter[] parameters = declaredConstructor.getParameters(); if (parameters.length == 1) { - subCommand = (BaseSubCommand) declaredConstructor.newInstance(this); + subCommand = (BaseCommand) declaredConstructor.newInstance(this); } else { manager.log(LogLevel.INFO, "Found unusable constructor: " + declaredConstructor.getName() + "(" + Stream.of(parameters).map(p -> p.getType().getSimpleName() + " " + p.getName()).collect(Collectors.joining(", ")) + ")"); } diff --git a/core/src/main/java/co/aikar/commands/BaseSubCommand.java b/core/src/main/java/co/aikar/commands/BaseSubCommand.java deleted file mode 100644 index c4824a6e..00000000 --- a/core/src/main/java/co/aikar/commands/BaseSubCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -public class BaseSubCommand extends BaseCommand { - private BaseCommand parentCommand; - public BaseSubCommand() {} - - void setParentCommand(BaseCommand command) { - this.parentCommand = command; - } - - @Override - public String getName() { - return parentCommand.getName(); - } -} diff --git a/example/src/main/java/co/aikar/acfexample/SomeCommand.java b/example/src/main/java/co/aikar/acfexample/SomeCommand.java index 4d211d28..6fb7ec58 100644 --- a/example/src/main/java/co/aikar/acfexample/SomeCommand.java +++ b/example/src/main/java/co/aikar/acfexample/SomeCommand.java @@ -24,7 +24,6 @@ package co.aikar.acfexample; import co.aikar.commands.BaseCommand; -import co.aikar.commands.BaseSubCommand; import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandPermission; @@ -82,7 +81,7 @@ public class SomeCommand extends BaseCommand { } @Subcommand("test|txt|tfoo") - public class Test extends BaseSubCommand { + public class Test extends BaseCommand { @Subcommand("test1|td1") @CommandCompletion("%foo") @@ -97,7 +96,7 @@ public class SomeCommand extends BaseCommand { } @Subcommand("next") - public class TestInner extends BaseSubCommand { + public class TestInner extends BaseCommand { @Subcommand("test3|td4") @CommandCompletion("FOO")