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.
This commit is contained in:
parent
438c604d52
commit
be61809a7b
|
@ -43,9 +43,11 @@ object ForgelinAutomaticEventSubscriber {
|
||||||
|
|
||||||
LOGGER.debug("Registering @EventBusSubscriber object for {} for mod {}", subscriber.className, mod.modId)
|
LOGGER.debug("Registering @EventBusSubscriber object for {} for mod {}", subscriber.className, mod.modId)
|
||||||
|
|
||||||
val subscriberClass = Class.forName(subscriber.className, false, loader)?.kotlin ?: continue
|
val subscriberClass = Class.forName(subscriber.className, false, loader) ?: continue
|
||||||
val subscriberInstance = subscriberClass.objectInstance ?: subscriberClass.companionObjectInstance ?: continue
|
val kotlinClass = subscriberClass?.kotlin ?: continue
|
||||||
|
val subscriberInstance = kotlinClass.objectInstance ?: kotlinClass.companionObjectInstance ?: continue
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.unregister(subscriberClass)
|
||||||
MinecraftForge.EVENT_BUS.register(subscriberInstance)
|
MinecraftForge.EVENT_BUS.register(subscriberInstance)
|
||||||
LOGGER.debug("Registered @EventBusSubscriber object {}", subscriber.className)
|
LOGGER.debug("Registered @EventBusSubscriber object {}", subscriber.className)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
|
Loading…
Reference in New Issue