From 799f32bca7cc42e51e1d04053786b9e967e1352a Mon Sep 17 00:00:00 2001 From: Zontreck Date: Tue, 13 Feb 2024 21:16:49 -0700 Subject: [PATCH] Replace a function in the API --- .../zontreck/eventsbus/EventDispatcher.java | 41 +++---------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/src/main/java/dev/zontreck/eventsbus/EventDispatcher.java b/src/main/java/dev/zontreck/eventsbus/EventDispatcher.java index 6d57cba..18ee435 100644 --- a/src/main/java/dev/zontreck/eventsbus/EventDispatcher.java +++ b/src/main/java/dev/zontreck/eventsbus/EventDispatcher.java @@ -92,43 +92,12 @@ public class EventDispatcher /** - * Scan all event subscribers + * Register a class */ - private static void Scan() + public static void Register(Class clazz) { - Package[] packages = Package.getPackages(); - - List> loaded = new ArrayList<>(); - - for(Package pkg : packages) - { - - try { - - String packageName = pkg.getName(); - - 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) - { - if(clazz.getPackage().getName().equalsIgnoreCase(packageName)) - { - - if(clazz.isAnnotationPresent(EventSubscriber.class)) - loaded.add(clazz); - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - subscribers = loaded; + if(clazz.isAnnotationPresent(EventSubscriber.class)) + subscribers.add(clazz); } /** @@ -140,8 +109,8 @@ public class EventDispatcher { Post(new ResetEventBusEvent()); + subscribers.clear(); singleshot.clear(); - Scan(); ClassScanner.DoScan(); Post(new EventBusReadyEvent());