Files
Plex/server/src/main/java/dev/plex/handlers/CommandHandler.java
T

46 lines
1.5 KiB
Java

package dev.plex.handlers;
import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.command.ServerCommand;
import dev.plex.command.impl.DebugCMD;
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
{
private final Plex plugin;
public CommandHandler(Plex plugin)
{
this.plugin = plugin;
Set<Class<? extends ServerCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", ServerCommand.class);
List<ServerCommand> commands = Lists.newArrayList();
commandSet.forEach(clazz ->
{
try
{
if (plugin.config.getBoolean("debug") && DebugCMD.class.isAssignableFrom(clazz))
{
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()));
}
}