use of org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge in project SpongeCommon by SpongePowered.
the class ForgeEventManager method post.
@Override
public boolean post(final Event event, final IEventBusInvokeDispatcher wrapper) {
if (event instanceof ForgeEventBridge_Forge) {
// intercept!
final ForgeEventBridge_Forge forgeEvent = (ForgeEventBridge_Forge) event;
final org.spongepowered.api.event.@Nullable Event spongeEvent = forgeEvent.bridge$createSpongeEvent();
if (spongeEvent != null) {
return this.postDualBus(spongeEvent, Collections.singleton(event), wrapper);
}
}
// Do as Forge does - SpongeVanilla has no role to play here.
return this.wrappedEventBus.post(event, wrapper);
}
use of org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge in project SpongeCommon by SpongePowered.
the class ForgeEventManager method postDualBus.
// Implementation
private boolean postDualBus(final org.spongepowered.api.event.Event spongeEvent, final Collection<? extends Event> forgeEvents, final IEventBusInvokeDispatcher dispatcher) {
try (final NoExceptionClosable ignored = this.preparePost(spongeEvent)) {
final RegisteredListener.Cache listeners = this.getHandlerCache(spongeEvent);
final List<RegisteredListener<?>> beforeModifications = listeners.beforeModifications();
if (!beforeModifications.isEmpty()) {
// First, we fire the Sponge beforeModifications on the Sponge event
this.post(spongeEvent, beforeModifications);
// Then we sync to the Forge events
for (final Event forgeEvent : forgeEvents) {
((ForgeEventBridge_Forge) forgeEvent).bridge$syncFrom(spongeEvent);
}
}
// Then, we fire all our Forge events
for (final Event forgeEvent : forgeEvents) {
this.wrappedEventBus.post(forgeEvent, dispatcher);
// We must sync back the event's changes, if there are any.
// For complex events, this will be a partial sync.
((ForgeEventBridge_Forge) forgeEvent).bridge$syncTo(spongeEvent);
}
// and now we do our standard event listener stuff.
return this.post(spongeEvent, listeners.afterModifications());
}
}
Aggregations