use of org.spongepowered.api.event.impl.AbstractEvent in project SpongeForge by SpongePowered.
the class SpongeModEventManager method post.
@SuppressWarnings("unchecked")
private boolean post(Event event, List<RegisteredListener<?>> listeners, boolean beforeModifications, boolean forced, boolean useCauseStackManager) {
ModContainer oldContainer = ((IMixinLoadController) SpongeMod.instance.getController()).getActiveModContainer();
for (@SuppressWarnings("rawtypes") RegisteredListener listener : listeners) {
((IMixinLoadController) SpongeMod.instance.getController()).setActiveModContainer((ModContainer) listener.getPlugin());
try {
if (forced || (!listener.isBeforeModifications() && !beforeModifications) || (listener.isBeforeModifications() && beforeModifications)) {
listener.getTimingsHandler().startTimingIfSync();
if (event instanceof AbstractEvent) {
((AbstractEvent) event).currentOrder = listener.getOrder();
}
if (useCauseStackManager) {
Sponge.getCauseStackManager().pushCause(listener.getPlugin());
try (CauseStackManager.StackFrame ignored = Sponge.getCauseStackManager().pushCauseFrame()) {
listener.handle(event);
}
Sponge.getCauseStackManager().popCause();
} else {
listener.handle(event);
}
}
} catch (Throwable e) {
this.logger.error("Could not pass {} to {}", event.getClass().getSimpleName(), listener.getPlugin(), e);
} finally {
listener.getTimingsHandler().stopTimingIfSync();
}
}
if (event instanceof AbstractEvent) {
((AbstractEvent) event).currentOrder = null;
}
((IMixinLoadController) SpongeMod.instance.getController()).setActiveModContainer(oldContainer);
return event instanceof Cancellable && ((Cancellable) event).isCancelled();
}
Aggregations