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:
Kitten 2018-06-09 20:08:40 +01:00 committed by Shadowfacts
parent 438c604d52
commit be61809a7b
1 changed files with 4 additions and 2 deletions

View File

@ -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) {