From be61809a7b0ca2e0f2d0a4db45d3c63b29dc22fc Mon Sep 17 00:00:00 2001 From: Kitten Date: Sat, 9 Jun 2018 20:08:40 +0100 Subject: [PATCH] Unregister class reference from the event bus (#36) When Forgelin registers the object instance of an `@EventBusSubscriber` annotated object class to the event bus, it does not unregister the static class reference that Forge will have registered before Forgelin parses the annotation candidates. This could potentially cause issues, and breaks expectations/semantics from having the annotation register a class both statically and as an instance. This pull request adds a call to `MinecraftForge.EVENT_BUS#unregister` to remove the Forge-registered class reference before registering the instance reference. --- .../forgelin/ForgelinAutomaticEventSubscriber.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/forgelin/ForgelinAutomaticEventSubscriber.kt b/src/main/kotlin/net/shadowfacts/forgelin/ForgelinAutomaticEventSubscriber.kt index a450730..dfef1f1 100644 --- a/src/main/kotlin/net/shadowfacts/forgelin/ForgelinAutomaticEventSubscriber.kt +++ b/src/main/kotlin/net/shadowfacts/forgelin/ForgelinAutomaticEventSubscriber.kt @@ -43,9 +43,11 @@ object ForgelinAutomaticEventSubscriber { LOGGER.debug("Registering @EventBusSubscriber object for {} for mod {}", subscriber.className, mod.modId) - val subscriberClass = Class.forName(subscriber.className, false, loader)?.kotlin ?: continue - val subscriberInstance = subscriberClass.objectInstance ?: subscriberClass.companionObjectInstance ?: continue + val subscriberClass = Class.forName(subscriber.className, false, loader) ?: continue + val kotlinClass = subscriberClass?.kotlin ?: continue + val subscriberInstance = kotlinClass.objectInstance ?: kotlinClass.companionObjectInstance ?: continue + MinecraftForge.EVENT_BUS.unregister(subscriberClass) MinecraftForge.EVENT_BUS.register(subscriberInstance) LOGGER.debug("Registered @EventBusSubscriber object {}", subscriber.className) } catch (e: Throwable) {