Search in sources :

Example 1 with ForgeEventManager

use of org.spongepowered.forge.launch.event.ForgeEventManager in project SpongeCommon by SpongePowered.

the class PluginModContainer method constructPlugin.

private void constructPlugin() {
    final FMLModContainerAccessor accessor = (FMLModContainerAccessor) (Object) this;
    try {
        PluginModContainer.LOGGER.trace(Logging.LOADING, "Loading plugin instance {} of type {}", getModId(), accessor.accessor$modClass().getName());
        final Injector childInjector = Launch.instance().lifecycle().platformInjector().createChildInjector(new PluginModule((PluginContainer) (Object) this, accessor.accessor$modClass()));
        final Object instance = childInjector.getInstance(accessor.accessor$modClass());
        accessor.accessor$setModInstance(instance);
        ((ForgeEventManager) MinecraftForge.EVENT_BUS).registerListeners((PluginContainer) (Object) this, instance);
        PluginModContainer.LOGGER.trace(Logging.LOADING, "Loaded plugin instance {} of type {}", getModId(), accessor.accessor$modClass().getName());
    } catch (final Throwable e) {
        PluginModContainer.LOGGER.error(Logging.LOADING, "Failed to create plugin instance. PluginID: {}, class {}", getModId(), accessor.accessor$modClass().getName(), e);
        throw new ModLoadingException(this.modInfo, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmod", e, accessor.accessor$modClass());
    }
    try {
        PluginModContainer.LOGGER.trace(Logging.LOADING, "Injecting Automatic event subscribers for {}", getModId());
        AutomaticEventSubscriber.inject(this, accessor.accessor$scanResults(), accessor.accessor$modClass().getClassLoader());
        PluginModContainer.LOGGER.trace(Logging.LOADING, "Completed Automatic event subscribers for {}", getModId());
    } catch (final Throwable e) {
        LOGGER.error(LOADING, "Failed to register automatic subscribers. PluginID: {}, class {}", getModId(), accessor.accessor$modClass().getName(), e);
        throw new ModLoadingException(this.modInfo, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmod", e, accessor.accessor$modClass());
    }
}
Also used : FMLModContainerAccessor(org.spongepowered.forge.accessor.fml.javafmlmod.FMLModContainerAccessor) ModLoadingException(net.minecraftforge.fml.ModLoadingException) PluginContainer(org.spongepowered.plugin.PluginContainer) Injector(com.google.inject.Injector) ForgeEventManager(org.spongepowered.forge.launch.event.ForgeEventManager) PluginModule(org.spongepowered.common.inject.plugin.PluginModule)

Aggregations

Injector (com.google.inject.Injector)1 ModLoadingException (net.minecraftforge.fml.ModLoadingException)1 PluginModule (org.spongepowered.common.inject.plugin.PluginModule)1 FMLModContainerAccessor (org.spongepowered.forge.accessor.fml.javafmlmod.FMLModContainerAccessor)1 ForgeEventManager (org.spongepowered.forge.launch.event.ForgeEventManager)1 PluginContainer (org.spongepowered.plugin.PluginContainer)1