From 117852e6d06fbd0fe842dc78eb848f0bbe2474cf Mon Sep 17 00:00:00 2001 From: Focusvity Date: Sun, 20 Mar 2022 13:04:55 +1100 Subject: [PATCH] Few changes to toggleable listener system --- src/main/java/dev/plex/handlers/ListenerHandler.java | 6 +++--- src/main/java/dev/plex/listener/annotation/Toggleable.java | 6 ++++++ src/main/java/dev/plex/listener/annotation/Toggled.java | 6 ------ src/main/java/dev/plex/listener/impl/ChatListener.java | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 src/main/java/dev/plex/listener/annotation/Toggleable.java delete mode 100644 src/main/java/dev/plex/listener/annotation/Toggled.java diff --git a/src/main/java/dev/plex/handlers/ListenerHandler.java b/src/main/java/dev/plex/handlers/ListenerHandler.java index 7e64a16..ea4d0dd 100644 --- a/src/main/java/dev/plex/handlers/ListenerHandler.java +++ b/src/main/java/dev/plex/handlers/ListenerHandler.java @@ -3,7 +3,7 @@ package dev.plex.handlers; import com.google.common.collect.Lists; import dev.plex.PlexBase; import dev.plex.listener.PlexListener; -import dev.plex.listener.annotation.Toggled; +import dev.plex.listener.annotation.Toggleable; import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import java.lang.reflect.InvocationTargetException; @@ -21,10 +21,10 @@ public class ListenerHandler extends PlexBase { try { - Toggled annotation = clazz.getDeclaredAnnotation(Toggled.class); + Toggleable annotation = clazz.getDeclaredAnnotation(Toggleable.class); if (annotation != null) { - if (plugin.config.getBoolean("chat.enabled") && annotation.enabled()) + if (plugin.config.get(annotation.value()) != null && plugin.config.getBoolean(annotation.value())) { listeners.add(clazz.getConstructor().newInstance()); } diff --git a/src/main/java/dev/plex/listener/annotation/Toggleable.java b/src/main/java/dev/plex/listener/annotation/Toggleable.java new file mode 100644 index 0000000..1d13b11 --- /dev/null +++ b/src/main/java/dev/plex/listener/annotation/Toggleable.java @@ -0,0 +1,6 @@ +package dev.plex.listener.annotation; + +public @interface Toggleable +{ + String value(); +} diff --git a/src/main/java/dev/plex/listener/annotation/Toggled.java b/src/main/java/dev/plex/listener/annotation/Toggled.java deleted file mode 100644 index bcb1e6b..0000000 --- a/src/main/java/dev/plex/listener/annotation/Toggled.java +++ /dev/null @@ -1,6 +0,0 @@ -package dev.plex.listener.annotation; - -public @interface Toggled -{ - boolean enabled() default false; -} diff --git a/src/main/java/dev/plex/listener/impl/ChatListener.java b/src/main/java/dev/plex/listener/impl/ChatListener.java index 5d4cede..28a633f 100644 --- a/src/main/java/dev/plex/listener/impl/ChatListener.java +++ b/src/main/java/dev/plex/listener/impl/ChatListener.java @@ -2,7 +2,7 @@ package dev.plex.listener.impl; import dev.plex.cache.PlayerCache; import dev.plex.listener.PlexListener; -import dev.plex.listener.annotation.Toggled; +import dev.plex.listener.annotation.Toggleable; import dev.plex.player.PlexPlayer; import dev.plex.util.PlexUtils; import io.papermc.paper.chat.ChatRenderer; @@ -15,7 +15,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; -@Toggled(enabled = true) +@Toggleable("chat.enabled") public class ChatListener extends PlexListener { private final PlexChatRenderer renderer = new PlexChatRenderer();