use of io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer in project TriggerReactor by wysohn.
the class TriggerReactor method createEmptyPlayerEvent.
@Override
public Object createEmptyPlayerEvent(ICommandSender sender) {
Object unwrapped = sender.get();
if (unwrapped instanceof Player) {
return new Event() {
@Override
public Cause getCause() {
Player src = (Player) unwrapped;
EventContext context = EventContext.builder().add(EventContextKeys.PLAYER, src).build();
return Cause.builder().append(unwrapped).build(context);
}
};
} else if (unwrapped instanceof ConsoleSource) {
return new Event() {
Cause cause = null;
{
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(new DelegatedPlayer((CommandSource) unwrapped));
cause = frame.getCurrentCause();
}
}
@Override
public Cause getCause() {
return cause;
}
};
} else {
throw new RuntimeException("Cannot create empty PlayerEvent for " + sender);
}
}
Aggregations