Few changes to toggleable listener system

This commit is contained in:
Focusvity 2022-03-20 13:04:55 +11:00
parent d55886dcbd
commit 117852e6d0
No known key found for this signature in database
GPG Key ID: 85AD157561ABE94B
4 changed files with 11 additions and 11 deletions

View File

@ -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());
}

View File

@ -0,0 +1,6 @@
package dev.plex.listener.annotation;
public @interface Toggleable
{
String value();
}

View File

@ -1,6 +0,0 @@
package dev.plex.listener.annotation;
public @interface Toggled
{
boolean enabled() default false;
}

View File

@ -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();