fix missing cause for custom data registration
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.Cancellable;
+import org.spongepowered.api.event.CauseStackManager;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.action.LightningEvent;
@@ -325,8 +326,17 @@ protected boolean post(Event event, List<RegisteredListener<?>> listeners, boole
((AbstractEvent) event).currentOrder = listener.getOrder();
}
+ final boolean mainThread = !Sponge.isServerAvailable() || Sponge.getServer().isMainThread();
+ if (mainThread) {
+ Sponge.getCauseStackManager().pushCause(listener.getPlugin());
+ try (CauseStackManager.StackFrame frame = 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 {
