11package com .burchard36 ;
22
33import com .burchard36 .command .ApiCommand ;
4- import com .burchard36 .command .annotation .RegisterCommand ;
4+ import com .burchard36 .command .annotation .* ;
55import com .burchard36 .command .exceptions .CommandConstructorNotFoundException ;
66import com .burchard36 .command .exceptions .CommandInterfaceNotFoundException ;
77import com .burchard36 .command .exceptions .InvalidCommandAnnotationException ;
1717import java .lang .reflect .Field ;
1818import java .lang .reflect .InvocationTargetException ;
1919import java .util .ArrayList ;
20+ import java .util .Arrays ;
2021import java .util .List ;
2122import java .util .Set ;
2223
@@ -26,7 +27,8 @@ public final class BurchAPI implements Api {
2627 public static JavaPlugin INSTANCE ;
2728 private HologramManager hologramManager ;
2829
29- public BurchAPI () {}
30+ public BurchAPI () {
31+ }
3032
3133 /**
3234 * Initializes the API to a plugin
@@ -75,15 +77,42 @@ public BurchAPI initializeApi(final JavaPlugin plugin) {
7577 }
7678
7779 final RegisterCommand commandAnnotation = command .getClass ().getAnnotation (RegisterCommand .class );
78- if (commandAnnotation == null ) throw new CommandInterfaceNotFoundException ("The command class: " + clazz .getName () + " does not have @RegisterCommand as a Annotation!" );
80+ final CommandName commandName = command .getClass ().getAnnotation (CommandName .class );
81+ final CommandDescription commandDescription = command .getClass ().getAnnotation (CommandDescription .class );
82+ final CommandUsage commandUsage = command .getClass ().getAnnotation (CommandUsage .class );
83+ final CommandAliases commandAliases = command .getClass ().getAnnotation (CommandAliases .class );
84+
85+ if (commandAnnotation != null ) {
86+
87+ if (!commandAnnotation .name ().equalsIgnoreCase ("" ))
88+ command .setCommandName (commandAnnotation .name ());
89+
90+ if (commandAnnotation .name ().equalsIgnoreCase ("" ) && commandName != null
91+ && !commandName .name ().equalsIgnoreCase ("" )) {
92+ command .setCommandName (commandName .name ());
93+ } else throw new InvalidCommandAnnotationException ("The class: " + command .getClass ().getName () + " did not have a valid command name set!" );
94+
95+ if (!commandAnnotation .description ().equalsIgnoreCase ("" ))
96+ command .setDescription (commandAnnotation .description ());
7997
80- if (commandAnnotation .name ().equalsIgnoreCase ("" ))
81- throw new InvalidCommandAnnotationException ("The command class: " + clazz .getName () + " @RegisterCommand interface does not have a name parameter!" );
98+ if (commandAnnotation .description ().equalsIgnoreCase ("" ) && commandDescription != null
99+ && !commandDescription .description ().equalsIgnoreCase ("" ))
100+ command .setDescription (commandDescription .description ());
82101
83- command .setCommandName (commandAnnotation .name ())
84- .setCommandDescription (commandAnnotation .description ())
85- .setCommandAliases (commandAnnotation .aliases ())
86- .setCommandUsage (commandAnnotation .usageMessage ());
102+ if (!commandAnnotation .usageMessage ().equalsIgnoreCase ("" ))
103+ command .setUsage (commandAnnotation .usageMessage ());
104+
105+ if (commandAnnotation .usageMessage ().equalsIgnoreCase ("" ) && commandUsage != null
106+ && !commandUsage .usageMessage ().equalsIgnoreCase ("" ))
107+ command .setUsage (commandUsage .usageMessage ());
108+
109+ if (commandAnnotation .aliases ().length != 0 )
110+ command .setAliases (Arrays .asList (commandAnnotation .aliases ()));
111+
112+ if (commandAnnotation .aliases ().length <= 0 && commandAliases != null
113+ && commandAliases .aliases ().length > 0 )
114+ command .setAliases (Arrays .asList (commandAliases .aliases ()));
115+ }
87116 registerCommand (command );
88117 }
89118 return this ;
0 commit comments