Add missing retention policy to annotation classes

This commit is contained in:
Focusvity 2022-04-02 12:46:04 +11:00
parent 90cccb804a
commit 099680d068
No known key found for this signature in database
GPG Key ID: 85AD157561ABE94B
4 changed files with 14 additions and 6 deletions

View File

@ -1,5 +1,9 @@
package dev.plex.command.annotation; package dev.plex.command.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface System public @interface System
{ {
String value() default ""; String value() default "";

View File

@ -21,10 +21,9 @@ public class CommandHandler extends PlexBase
{ {
try try
{ {
System annotation = clazz.getDeclaredAnnotation(System.class); if (clazz.isAnnotationPresent(System.class))
// TODO: Annotations are always null?
if (annotation != null)
{ {
System annotation = clazz.getDeclaredAnnotation(System.class);
PlexLog.debug(clazz.getName() + " has annotations"); PlexLog.debug(clazz.getName() + " has annotations");
if (annotation.value().equalsIgnoreCase(plugin.getSystem().toLowerCase())) if (annotation.value().equalsIgnoreCase(plugin.getSystem().toLowerCase()))
{ {
@ -41,7 +40,6 @@ public class CommandHandler extends PlexBase
else else
{ {
commands.add(clazz.getConstructor().newInstance()); commands.add(clazz.getConstructor().newInstance());
// PlexLog.debug("Adding command normally " + clazz.getName());
} }
} }
catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException ex) catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException ex)

View File

@ -21,12 +21,14 @@ public class ListenerHandler extends PlexBase
{ {
try try
{ {
Toggleable annotation = clazz.getDeclaredAnnotation(Toggleable.class); if (clazz.isAnnotationPresent(Toggleable.class))
if (annotation != null)
{ {
Toggleable annotation = clazz.getDeclaredAnnotation(Toggleable.class);
PlexLog.debug(clazz.getName() + " has annotations");
if (plugin.config.get(annotation.value()) != null && plugin.config.getBoolean(annotation.value())) if (plugin.config.get(annotation.value()) != null && plugin.config.getBoolean(annotation.value()))
{ {
listeners.add(clazz.getConstructor().newInstance()); listeners.add(clazz.getConstructor().newInstance());
PlexLog.debug("Registering " + clazz.getName() + " as a listener");
} }
} }
else else

View File

@ -1,5 +1,9 @@
package dev.plex.listener.annotation; package dev.plex.listener.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Toggleable public @interface Toggleable
{ {
String value(); String value();