Skip to content

Commit 1913408

Browse files
committed
Fix plugins not receiving events on Forge
We'll have to rework the dual bus too
1 parent 7125066 commit 1913408

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

forge/src/launch/java/org/spongepowered/forge/launch/plugin/PluginModContainer.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
package org.spongepowered.forge.launch.plugin;
2626

2727
import 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;
2930
import net.minecraftforge.fml.Logging;
3031
import net.minecraftforge.fml.ModContainer;
3132
import net.minecraftforge.fml.ModList;
@@ -38,6 +39,7 @@
3839
import net.minecraftforge.forgespi.language.ModFileScanData;
3940
import org.apache.logging.log4j.LogManager;
4041
import org.apache.logging.log4j.Logger;
42+
import org.spongepowered.api.Sponge;
4143
import org.spongepowered.common.inject.plugin.PluginGuice;
4244
import org.spongepowered.common.launch.Launch;
4345
import 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

Comments
 (0)