Make a seperate method hasSenderAnnotation
@@ -87,35 +87,39 @@ public static void registerAvailable(Object provider, Console console, Context c
Predicate<? super Method> predicate = Predicates.<Method>and(ReflectionUtils.withModifier(Modifier.PUBLIC), ReflectionUtils.withAnnotation(Command.class));
Set<Method> commandMethods = ReflectionUtils.getAllMethods(provider.getClass(), predicate);
for (Method method : commandMethods) {
+ if(!hasSenderAnnotation(method)){
+ logger.error("Command {} provided by {} contains a EntityRef without @Sender annotation, may cause a NullPointerException", method.getName(), provider.getClass().getSimpleName());
+ }
+ logger.debug("Registering command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
+ try {
+ SpecificAccessibleObject<Method> specificMethod = new SpecificAccessibleObject<>(method, provider);
+ MethodCommand command = referringTo(specificMethod, context);
+ console.registerCommand(command);
+ logger.debug("Registered command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
+ } catch (RuntimeException t) {
+ logger.error("Failed to load command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName(), t);
+ }
+ }
+ }
+
+ private static boolean hasSenderAnnotation(Method method) {
final Class[] paramTypes = method.getParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
- boolean hasSenderAnnotation = false;
for (int i = 0; i < paramAnnotations.length; i++) {
if(paramTypes[i].getTypeName().equals(ENTITY_REF_NAME)) {
if(paramAnnotations[i].length == 0) {
- logger.error("Command {} provided by {} contains a EntityRef without @Sender annotation, may cause a NullPointerException", method.getName(), provider.getClass().getSimpleName());
+ return false;
} else {
for (Annotation annotation: paramAnnotations[i]) {
if (annotation instanceof Sender) {
- hasSenderAnnotation = true;
- }
- }
- if(!hasSenderAnnotation){
- logger.error("Command {} provided by {} contains a EntityRef without @Sender annotation, may cause a NullPointerException", method.getName(), provider.getClass().getSimpleName());
+ return true;
}
}
}
}
- logger.debug("Registering command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
- try {
- SpecificAccessibleObject<Method> specificMethod = new SpecificAccessibleObject<>(method, provider);
- MethodCommand command = referringTo(specificMethod, context);
- console.registerCommand(command);
- logger.debug("Registered command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
- } catch (RuntimeException t) {
- logger.error("Failed to load command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName(), t);
- }
+
}
+ return false;
}
@Override
