mirror of
https://github.com/plexusorg/Plex.git
synced 2025-06-28 14:36:41 +00:00
Move Plex to API-driven plugin and fix NoClassDefFoundError on startup
This commit is contained in:
50
server/src/main/java/dev/plex/handlers/CommandHandler.java
Normal file
50
server/src/main/java/dev/plex/handlers/CommandHandler.java
Normal file
@ -0,0 +1,50 @@
|
||||
package dev.plex.handlers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandHandler implements PlexBase
|
||||
{
|
||||
public CommandHandler()
|
||||
{
|
||||
Set<Class<? extends PlexCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", PlexCommand.class);
|
||||
List<PlexCommand> commands = Lists.newArrayList();
|
||||
|
||||
commandSet.forEach(clazz ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (clazz.isAnnotationPresent(System.class))
|
||||
{
|
||||
System annotation = clazz.getDeclaredAnnotation(System.class);
|
||||
if (annotation.value().equalsIgnoreCase(plugin.getSystem().toLowerCase()))
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
|
||||
if (plugin.config.getBoolean("debug") && annotation.debug())
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException ex)
|
||||
{
|
||||
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a command!");
|
||||
}
|
||||
});
|
||||
PlexLog.log(String.format("Registered %s commands from %s classes!", commands.size(), commandSet.size()));
|
||||
}
|
||||
}
|
45
server/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
45
server/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
@ -0,0 +1,45 @@
|
||||
package dev.plex.handlers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.listener.annotation.Toggleable;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ListenerHandler implements PlexBase
|
||||
{
|
||||
public ListenerHandler()
|
||||
{
|
||||
Set<Class<? extends PlexListener>> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", PlexListener.class);
|
||||
List<PlexListener> listeners = Lists.newArrayList();
|
||||
|
||||
listenerSet.forEach(clazz ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (clazz.isAnnotationPresent(Toggleable.class))
|
||||
{
|
||||
Toggleable annotation = clazz.getDeclaredAnnotation(Toggleable.class);
|
||||
if (plugin.config.get(annotation.value()) != null && plugin.config.getBoolean(annotation.value()))
|
||||
{
|
||||
listeners.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listeners.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException ex)
|
||||
{
|
||||
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a listener!");
|
||||
}
|
||||
});
|
||||
PlexLog.log(String.format("Registered %s listeners from %s classes!", listeners.size(), listenerSet.size()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user