diff --git a/.gitignore b/.gitignore index be3bb25..f414120 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,4 @@ buildNumber.properties # Common working directory run/ +target/ \ No newline at end of file diff --git a/src/main/java/me/kodysimpson/simpapi/command/CommandManager.java b/src/main/java/me/kodysimpson/simpapi/command/CommandManager.java index c600446..07a20a7 100644 --- a/src/main/java/me/kodysimpson/simpapi/command/CommandManager.java +++ b/src/main/java/me/kodysimpson/simpapi/command/CommandManager.java @@ -17,6 +17,16 @@ */ public class CommandManager { + private static boolean isQualifiedSubcommand(Class clazz) { + return clazz.isAnnotationPresent(QualifiedSubCommand.class); + } + + private static List fetchAliasesForSubcommand(Class clazz) { + if(!isQualifiedSubcommand(clazz)) return Collections.emptyList(); + QualifiedSubCommand marker = clazz.getAnnotation(QualifiedSubCommand.class); + return Arrays.asList(marker.aliases); + } + /** * @param plugin An instance of your plugin that is using this API. If called within plugin main class, provide this keyword * @param commandName The name of the command @@ -38,8 +48,22 @@ public static void createCoreCommand(JavaPlugin plugin, String commandName, Arrays.stream(subcommands).map(subcommand -> { try{ Constructor constructor = subcommand.getConstructor(); - return constructor.newInstance(); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + SubCommand sub = constructor.newInstance(); + + //Should this subcommand be treated as an independent command in its own right? + if(isQualifiedSubcommand(subcommand)) { + createCoreCommand( + plugin, + sub.getName(), + sub.getDescription(), + sub.getSyntax(), + commandList, + fetchAliasesForSubcommand(subcommand) + ); + } + + return sub; + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | NoSuchFieldException e) { e.printStackTrace(); } return null; diff --git a/src/main/java/me/kodysimpson/simpapi/command/QualifiedSubCommand.java b/src/main/java/me/kodysimpson/simpapi/command/QualifiedSubCommand.java new file mode 100644 index 0000000..95a0318 --- /dev/null +++ b/src/main/java/me/kodysimpson/simpapi/command/QualifiedSubCommand.java @@ -0,0 +1,12 @@ +package me.kodysimpson.simpapi.command; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface QualifiedSubCommand { + String[] aliases = { "" }; +} \ No newline at end of file