diff --git a/common/src/main/java/revxrsal/commands/Lamp.java b/common/src/main/java/revxrsal/commands/Lamp.java index 6d32d950..fc7e072b 100644 --- a/common/src/main/java/revxrsal/commands/Lamp.java +++ b/common/src/main/java/revxrsal/commands/Lamp.java @@ -63,6 +63,7 @@ import java.util.function.Predicate; import java.util.function.Supplier; +import static revxrsal.commands.util.Classes.checkRetention; import static revxrsal.commands.util.Classes.wrap; import static revxrsal.commands.util.Preconditions.notNull; @@ -744,6 +745,7 @@ public Builder() { public Builder annotationReplacer(@NotNull Class annotationType, @NotNull AnnotationReplacer replacer) { notNull(annotationType, "annotation type"); notNull(replacer, "annotation replacer"); + checkRetention(annotationType); annotationReplacers.computeIfAbsent(annotationType, k -> new HashSet<>()).add(replacer); return this; } diff --git a/common/src/main/java/revxrsal/commands/autocomplete/SuggestionProvider.java b/common/src/main/java/revxrsal/commands/autocomplete/SuggestionProvider.java index 8e712d91..36db1ea3 100644 --- a/common/src/main/java/revxrsal/commands/autocomplete/SuggestionProvider.java +++ b/common/src/main/java/revxrsal/commands/autocomplete/SuggestionProvider.java @@ -37,6 +37,8 @@ import java.util.List; import java.util.function.Function; +import static revxrsal.commands.util.Classes.checkRetention; + /** * An interface that supplies completions for the user depending on their input. */ @@ -154,6 +156,7 @@ static Factory forTypeAndSubclasses(@NotNull * @return The newly created {@link Factory}. */ static @NotNull SuggestionProvider.@NotNull Factory forAnnotation(@NotNull Class annotationType, @NotNull Function> provider) { + checkRetention(annotationType); return (type, annotations, lamp) -> { L annotation = annotations.get(annotationType); if (annotation != null) diff --git a/common/src/main/java/revxrsal/commands/command/CommandPermission.java b/common/src/main/java/revxrsal/commands/command/CommandPermission.java index f1ea7491..686889c6 100644 --- a/common/src/main/java/revxrsal/commands/command/CommandPermission.java +++ b/common/src/main/java/revxrsal/commands/command/CommandPermission.java @@ -31,6 +31,8 @@ import java.lang.annotation.Annotation; import java.util.function.Function; +import static revxrsal.commands.util.Classes.checkRetention; + /** * Represents a permission that is required in order to execute a * command. @@ -82,6 +84,7 @@ static Factory forAnnotation( @NotNull Class annotationType, @NotNull Function> permissionCreator ) { + checkRetention(annotationType); return (annotations, lamp) -> { T annotation = annotations.get(annotationType); if (annotation != null) diff --git a/common/src/main/java/revxrsal/commands/util/Classes.java b/common/src/main/java/revxrsal/commands/util/Classes.java index 2cd234d5..b1720e9a 100644 --- a/common/src/main/java/revxrsal/commands/util/Classes.java +++ b/common/src/main/java/revxrsal/commands/util/Classes.java @@ -262,6 +262,7 @@ private static void addPrimitive( */ public static void checkRetention(@NotNull Class type) { if (!type.isAnnotationPresent(Retention.class) || type.getAnnotation(Retention.class).value() != RetentionPolicy.RUNTIME) - throw new IllegalArgumentException("Tried to check for annotation @" + type.getName() + ", but it does not have @Retention(RetentionPolicy.RUNTIME)!"); + throw new IllegalArgumentException("Tried to check for annotation @" + type.getName() + ", but it does not have @Retention(RetentionPolicy.RUNTIME)! " + + "As such, it may be present but we cannot see it."); } }