Replace reflections

This commit is contained in:
Zontreck 2024-02-13 02:16:58 -07:00
parent ccddf83a7c
commit 702b68a7ac
2 changed files with 20 additions and 10 deletions

View file

@ -60,7 +60,7 @@ repositories {
}
dependencies {
provided "org.reflections:reflections:0.10.2"
provided "com.google.guava:guava:31.1-jre"
}

View file

@ -1,13 +1,14 @@
package dev.zontreck.eventsbus;
import com.google.common.reflect.ClassPath;
import dev.zontreck.eventsbus.annotations.EventSubscriber;
import dev.zontreck.eventsbus.annotations.Priority;
import dev.zontreck.eventsbus.annotations.SingleshotEvent;
import dev.zontreck.eventsbus.annotations.Subscribe;
import dev.zontreck.eventsbus.events.EventBusReadyEvent;
import dev.zontreck.eventsbus.events.ResetEventBusEvent;
import org.reflections.Reflections;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -102,10 +103,16 @@ public class EventDispatcher
for(Package pkg : packages)
{
try {
String packageName = pkg.getName();
Reflections reflections = new Reflections(packageName);
var classes = reflections.getSubTypesOf(Object.class).stream().collect(Collectors.toList());
var classes = ClassPath.from(ClassLoader.getSystemClassLoader())
.getAllClasses()
.stream()
.filter(clz->clz.getPackageName().equals(packageName))
.map(c->c.load())
.collect(Collectors.toList());
for(Class<?> clazz : classes)
{
@ -116,6 +123,9 @@ public class EventDispatcher
loaded.add(clazz);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
subscribers = loaded;