diff --git a/core/src/main/java/co/aikar/commands/Annotations.java b/core/src/main/java/co/aikar/commands/Annotations.java index 3e8dcdfc..717b4161 100644 --- a/core/src/main/java/co/aikar/commands/Annotations.java +++ b/core/src/main/java/co/aikar/commands/Annotations.java @@ -41,28 +41,41 @@ class Annotations extends AnnotationLookups { private final M manager; private Map, Method> valueMethods = new IdentityHashMap<>(); + private Map, Void> noValueAnnotations = new IdentityHashMap<>(); Annotations(M manager) { this.manager = manager; } String getValue(Annotation annotation, Class annoClass, int options) { - if (annotation == null) { - // TODO: Alias support - return null; - } - try { + String value = null; + + if (annotation != null) { Method valueMethod = valueMethods.get(annoClass); if (valueMethod == null) { - valueMethod = annoClass.getMethod("value"); - valueMethod.setAccessible(true); - valueMethods.put(annoClass, valueMethod); - } - String value = (String) valueMethod.invoke(annotation); - if (value == null) { - // TODO: Alias support - return null; + if (noValueAnnotations.containsKey(annoClass)) { + value = ""; + } else { + try { + valueMethod = annoClass.getMethod("value"); + value = (String) valueMethod.invoke(annotation); + valueMethod.setAccessible(true); + valueMethods.put(annoClass, valueMethod); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + if (!(e instanceof NoSuchMethodException)) { + manager.log(LogLevel.ERROR, "Error getting annotation value", e); + } + noValueAnnotations.put(annoClass, null); + value = ""; + } + } } + } + + // TODO: Aliases + + // transforms + if (value != null) { if (hasOption(options, REPLACEMENTS)) { value = manager.getCommandReplacements().replace(value); } @@ -71,14 +84,13 @@ class Annotations extends AnnotationLookups { } else if (hasOption(options, UPPERCASE)) { value = value.toUpperCase(manager.getLocales().getDefaultLocale()); } - if (value.isEmpty() && hasOption(options, NO_EMPTY)) { - return null; - } - return value; - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - manager.log(LogLevel.ERROR, "Error getting annotation value", e); } - return null; + + // validation + if (value != null && value.isEmpty() && hasOption(options, NO_EMPTY)) { + value = null; + } + return value; } private static boolean hasOption(int options, int option) {