2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.handlers;
|
2020-10-31 08:55:27 +00:00
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2022-01-30 01:31:10 +00:00
|
|
|
import dev.plex.PlexBase;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.command.PlexCommand;
|
2022-03-19 03:33:23 +00:00
|
|
|
import dev.plex.command.annotation.System;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.util.PlexLog;
|
2022-03-19 03:33:23 +00:00
|
|
|
import dev.plex.util.PlexUtils;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2022-01-04 03:04:39 +00:00
|
|
|
import java.util.List;
|
2022-03-19 03:33:23 +00:00
|
|
|
import java.util.Set;
|
2022-01-04 03:04:39 +00:00
|
|
|
|
2022-01-30 01:31:10 +00:00
|
|
|
public class CommandHandler extends PlexBase
|
2020-10-31 08:55:27 +00:00
|
|
|
{
|
|
|
|
public CommandHandler()
|
|
|
|
{
|
2022-03-19 03:33:23 +00:00
|
|
|
Set<Class<? extends PlexCommand>> commandSet = PlexUtils.getClassesBySubType("dev.plex.command.impl", PlexCommand.class);
|
2021-06-20 08:02:07 +00:00
|
|
|
List<PlexCommand> commands = Lists.newArrayList();
|
2022-03-19 03:33:23 +00:00
|
|
|
|
|
|
|
commandSet.forEach(clazz ->
|
2022-02-22 00:20:22 +00:00
|
|
|
{
|
2022-03-19 03:33:23 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
System annotation = clazz.getDeclaredAnnotation(System.class);
|
|
|
|
if (annotation != null && annotation.value().equalsIgnoreCase(plugin.getSystem()))
|
|
|
|
{
|
|
|
|
commands.add(clazz.getConstructor().newInstance());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
commands.add(clazz.getConstructor().newInstance());
|
|
|
|
}
|
|
|
|
catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException ex)
|
|
|
|
{
|
|
|
|
PlexLog.log("Failed to register " + clazz.getSimpleName() + " as a command!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
PlexLog.log(String.format("Registered %s commands from %s classes!", commands.size(), commandSet.size()));
|
2020-10-31 08:55:27 +00:00
|
|
|
}
|
|
|
|
}
|