Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ buildNumber.properties

# Common working directory
run/
target/
28 changes: 26 additions & 2 deletions src/main/java/me/kodysimpson/simpapi/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
*/
public class CommandManager {

private static boolean isQualifiedSubcommand(Class<? extends SubCommand> clazz) {
return clazz.isAnnotationPresent(QualifiedSubCommand.class);
}

private static List<String> fetchAliasesForSubcommand(Class<? extends SubCommand> 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
Expand All @@ -38,8 +48,22 @@ public static void createCoreCommand(JavaPlugin plugin, String commandName,
Arrays.stream(subcommands).map(subcommand -> {
try{
Constructor<? extends SubCommand> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = { "" };
}