Skip to content

Commit

Permalink
Unregister class reference from the event bus (#36)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kitten authored and shadowfacts committed Jun 9, 2018
1 parent 438c604 commit be61809
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit be61809

Please sign in to comment.