2525package org .spongepowered .forge .launch .plugin ;
2626
2727import com .google .inject .Injector ;
28- import net .minecraftforge .eventbus .internal .Event ;
28+ import net .minecraftforge .eventbus .api .bus .BusGroup ;
29+ import net .minecraftforge .eventbus .api .bus .EventBus ;
2930import net .minecraftforge .fml .Logging ;
3031import net .minecraftforge .fml .ModContainer ;
3132import net .minecraftforge .fml .ModList ;
3839import net .minecraftforge .forgespi .language .ModFileScanData ;
3940import org .apache .logging .log4j .LogManager ;
4041import org .apache .logging .log4j .Logger ;
42+ import org .spongepowered .api .Sponge ;
4143import org .spongepowered .common .inject .plugin .PluginGuice ;
4244import org .spongepowered .common .launch .Launch ;
4345import org .spongepowered .plugin .metadata .model .PluginDependency ;
@@ -49,6 +51,7 @@ public final class PluginModContainer extends ModContainer {
4951 private static final Logger LOGGER = LogManager .getLogger ();
5052
5153 private final ModFileScanData scanResults ;
54+ private final BusGroup eventBusGroup ;
5255 private Object modInstance ;
5356 private final Class <?> modClass ;
5457 private final CountDownLatch initializationLock ;
@@ -58,6 +61,7 @@ public PluginModContainer(IModInfo info, String className, ModFileScanData modFi
5861 LOGGER .debug (Logging .LOADING , "Creating PluginModContainer instance for {}" , className );
5962 this .scanResults = modFileScanResults ;
6063 this .activityMap .put (ModLoadingStage .CONSTRUCT , this ::constructPlugin );
64+ this .eventBusGroup = BusGroup .create ("modBusFor" + info .getModId ());
6165 this .contextExtension = () -> null ;
6266 this .initializationLock = new CountDownLatch (1 );
6367
@@ -71,14 +75,6 @@ public PluginModContainer(IModInfo info, String className, ModFileScanData modFi
7175 }
7276 }
7377
74- @ Override
75- public void dispatchConfigEvent (IConfigEvent event ) {
76- }
77-
78- // private void onEventFailed(IEventBus iEventBus, Event event, IEventListener[] iEventListeners, int i, Throwable throwable) {
79- // LOGGER.error(new EventBusErrorMessage(event, i, iEventListeners, throwable));
80- // }
81-
8278 private void constructPlugin () {
8379 try {
8480 LOGGER .trace (Logging .LOADING , "Loading plugin instance {} of type {}" , getModId (), this .modClass .getName ());
@@ -100,7 +96,7 @@ private void constructPlugin() {
10096 final Injector pluginInjector = PluginGuice .create (pluginContainer , this .modClass , Launch .instance ().lifecycle ().platformInjector ());
10197 this .modInstance = pluginInjector .getInstance (this .modClass );
10298 pluginContainer .setInjector (pluginInjector );
103- // ((ForgeEventManager) MinecraftForge.EVENT_BUS ).registerListeners(pluginContainer, this.modInstance);
99+ Sponge . eventManager ( ).registerListeners (pluginContainer , this .modInstance );
104100
105101 LOGGER .trace (Logging .LOADING , "Loaded plugin instance {} of type {}" , getModId (), this .modClass .getName ());
106102
@@ -130,16 +126,23 @@ public Object getMod() {
130126 return this .modInstance ;
131127 }
132128
133- protected <T extends Event & IModBusEvent > void acceptEvent (final T e ) {
129+ @ Override
130+ protected <T extends IModBusEvent > void acceptEvent (final T e ) {
134131 try {
135132 LOGGER .trace (Logging .LOADING , "Firing event for modid {} : {}" , this .getModId (), e );
133+ IModBusEvent .getBus (this .eventBusGroup , (Class <T >) e .getClass ()).post (e );
136134 LOGGER .trace (Logging .LOADING , "Fired event for modid {} : {}" , this .getModId (), e );
137135 } catch (Throwable t ) {
138136 LOGGER .error (Logging .LOADING , "Caught exception during event {} dispatch for modid {}" , e , this .getModId (), t );
139137 throw new ModLoadingException (this .modInfo , this .modLoadingStage , "fml.modloading.errorduringevent" , t );
140138 }
141139 }
142140
141+ @ Override
142+ public void dispatchConfigEvent (final IConfigEvent event ) {
143+ EventBus .create (this .eventBusGroup , event .self ().getClass ()).post (event .self ());
144+ }
145+
143146 private void waitForInitialization () {
144147 try {
145148 this .initializationLock .await ();
0 commit comments