Use reflection to load event listeners
This commit is contained in:
parent
52e51f99da
commit
3bc58b7f9c
|
|
@ -6,6 +6,7 @@ plugins {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api"))
|
implementation(project(":api"))
|
||||||
compileOnly("com.alttd:Galaxy-API:1.21.1-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Galaxy-API:1.21.1-R0.1-SNAPSHOT")
|
||||||
|
api("org.reflections:reflections:0.10.2")
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
compileOnly("org.projectlombok:lombok:1.18.34")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.34")
|
annotationProcessor("org.projectlombok:lombok:1.18.34")
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,14 @@ import com.alttd.essentia.storage.StorageType;
|
||||||
import com.alttd.essentia.user.EssentiaUserManager;
|
import com.alttd.essentia.user.EssentiaUserManager;
|
||||||
import com.alttd.essentia.api.user.UserManager;
|
import com.alttd.essentia.api.user.UserManager;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
import org.reflections.scanners.Scanners;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
|
|
||||||
|
|
@ -74,7 +80,17 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
|
|
||||||
void loadEventListeners() {
|
void loadEventListeners() {
|
||||||
final PluginManager pluginManager = getServer().getPluginManager();
|
final PluginManager pluginManager = getServer().getPluginManager();
|
||||||
pluginManager.registerEvents(new PlayerListener(this), this);
|
Reflections reflections = new Reflections("com.alttd.essentia.listeners");
|
||||||
|
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(Listener.class).asClass());
|
||||||
|
|
||||||
|
subTypes.forEach(clazz -> {
|
||||||
|
try {
|
||||||
|
Listener listener = (Listener) clazz.getDeclaredConstructor().newInstance();
|
||||||
|
pluginManager.registerEvents(listener, this);
|
||||||
|
} catch (Exception e) {
|
||||||
|
EssentiaPlugin.instance().getLogger().severe("Failed to register event listener " + clazz.getSimpleName());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadManagers() {
|
void loadManagers() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user