Search in sources :

Example 1 with DelegatedPlayer

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);
    }
}
Also used : EventContext(org.spongepowered.api.event.cause.EventContext) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Player(org.spongepowered.api.entity.living.player.Player) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Cause(org.spongepowered.api.event.cause.Cause) GameInitializationEvent(org.spongepowered.api.event.game.state.GameInitializationEvent) GameReloadEvent(org.spongepowered.api.event.game.GameReloadEvent) GameStartedServerEvent(org.spongepowered.api.event.game.state.GameStartedServerEvent) GameStoppingServerEvent(org.spongepowered.api.event.game.state.GameStoppingServerEvent) TriggerReactorStopEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent) TabCompleteEvent(org.spongepowered.api.event.command.TabCompleteEvent) Event(org.spongepowered.api.event.Event) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) TriggerReactorStartEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent) GameAboutToStartServerEvent(org.spongepowered.api.event.game.state.GameAboutToStartServerEvent) SendCommandEvent(org.spongepowered.api.event.command.SendCommandEvent) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource)

Aggregations

IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)1 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)1 SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)1 TriggerReactorStartEvent (io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent)1 TriggerReactorStopEvent (io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent)1 DelegatedPlayer (io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer)1 ConsoleSource (org.spongepowered.api.command.source.ConsoleSource)1 Player (org.spongepowered.api.entity.living.player.Player)1 Event (org.spongepowered.api.event.Event)1 Cause (org.spongepowered.api.event.cause.Cause)1 EventContext (org.spongepowered.api.event.cause.EventContext)1 SendCommandEvent (org.spongepowered.api.event.command.SendCommandEvent)1 TabCompleteEvent (org.spongepowered.api.event.command.TabCompleteEvent)1 GameReloadEvent (org.spongepowered.api.event.game.GameReloadEvent)1 GameAboutToStartServerEvent (org.spongepowered.api.event.game.state.GameAboutToStartServerEvent)1 GameInitializationEvent (org.spongepowered.api.event.game.state.GameInitializationEvent)1 GameStartedServerEvent (org.spongepowered.api.event.game.state.GameStartedServerEvent)1 GameStoppingServerEvent (org.spongepowered.api.event.game.state.GameStoppingServerEvent)1 InteractInventoryEvent (org.spongepowered.api.event.item.inventory.InteractInventoryEvent)1