Search in sources :

Example 16 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_Forge method forge$onElytraUse.

// override from LivingEntityMixin_Forge
@Override
protected void forge$onElytraUse(final CallbackInfo ci) {
    final PhaseContext<?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    final net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer) (Object) this;
    try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.STANDARD)) {
        // capture
        player.inventoryMenu.broadcastChanges();
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) ServerPlayer(net.minecraft.server.level.ServerPlayer) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)

Example 17 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class PlayerListMixin method impl$onInitPlayer_join.

@Inject(method = "placeNewPlayer", at = @At(value = "RETURN"))
private void impl$onInitPlayer_join(final Connection networkManager, final net.minecraft.server.level.ServerPlayer mcPlayer, final CallbackInfo ci) {
    final ServerPlayer player = (ServerPlayer) mcPlayer;
    final ServerSideConnection connection = player.connection();
    final Cause cause = Cause.of(EventContext.empty(), connection, player);
    final Audience audience = Audiences.onlinePlayers();
    final Component joinComponent = SpongeAdventure.asAdventure(((ServerPlayerBridge) mcPlayer).bridge$getConnectionMessageToSend());
    final ServerSideConnectionEvent.Join event = SpongeEventFactory.createServerSideConnectionEventJoin(cause, audience, Optional.of(audience), joinComponent, joinComponent, connection, player, false);
    SpongeCommon.post(event);
    if (!event.isMessageCancelled()) {
        event.audience().ifPresent(audience1 -> audience1.sendMessage(Identity.nil(), event.message()));
    }
    ((ServerPlayerBridge) mcPlayer).bridge$setConnectionMessageToSend(null);
    final PhaseContext<?> context = PhaseTracker.SERVER.getPhaseContext();
    PhaseTracker.SERVER.pushCause(event);
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    transactor.logPlayerInventoryChange(mcPlayer, PlayerInventoryTransaction.EventCreator.STANDARD);
    try (EffectTransactor ignored = BroadcastInventoryChangesEffect.transact(transactor)) {
        // in case plugins modified it
        mcPlayer.inventoryMenu.broadcastChanges();
    }
}
Also used : TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) Audience(net.kyori.adventure.audience.Audience) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Cause(org.spongepowered.api.event.Cause) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TextComponent(net.minecraft.network.chat.TextComponent) MutableComponent(net.minecraft.network.chat.MutableComponent) Component(net.kyori.adventure.text.Component) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 18 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_Inventory method inventory$onTouch.

@Override
protected void inventory$onTouch(final Entity entity, final Player player) {
    if (entity instanceof ItemEntity) {
        // ItemEntityMixin_Inventory creates transactions for pickup event
        entity.playerTouch(player);
        return;
    }
    if (!((EntityBridge) entity).bridge$isPlayerTouchDeclared()) {
        entity.playerTouch(player);
        return;
    }
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    try (final EffectTransactor ignored = context.getTransactor().logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.STANDARD)) {
        entity.playerTouch(player);
        // capture
        this.inventoryMenu.broadcastChanges();
    }
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)

Example 19 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_Inventory method inventory$onUpdateUsingItem.

@Override
protected void inventory$onUpdateUsingItem(final LivingEntity thisPlayer) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect((ServerPlayer) (Object) this, PlayerInventoryTransaction.EventCreator.STANDARD)) {
        this.shadow$completeUsingItem();
        this.inventoryMenu.broadcastChanges();
    }
}
Also used : TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)

Example 20 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_Inventory method inventory$switchToCloseWindowState.

@Override
protected void inventory$switchToCloseWindowState(final AbstractContainerMenu container, final Player player) {
    // Corner case where the server is shutting down on the client, the server player is also being killed off.
    if (Sponge.isServerAvailable() && Sponge.isClientAvailable()) {
        container.removed(player);
        return;
    }
    final ServerPlayer serverPlayer = (ServerPlayer) player;
    try (final PhaseContext<@NonNull ?> ctx = PacketPhase.General.CLOSE_WINDOW.createPhaseContext(PhaseTracker.SERVER).source(serverPlayer).packetPlayer(serverPlayer)) {
        ctx.buildAndSwitch();
        try (final EffectTransactor ignored = ctx.getTransactor().logCloseInventory(player, true)) {
            // Drop & capture cursor item
            container.removed(player);
            container.broadcastChanges();
        }
    }
    // Handle Viewers
    this.impl$onCloseMenu();
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)

Aggregations

EffectTransactor (org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)24 TransactionalCaptureSupplier (org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)16 Redirect (org.spongepowered.asm.mixin.injection.Redirect)13 ResultingTransactionBySideEffect (org.spongepowered.common.event.tracking.context.transaction.ResultingTransactionBySideEffect)4 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)3 Inventory (org.spongepowered.api.item.inventory.Inventory)3 LevelBridge (org.spongepowered.common.bridge.world.level.LevelBridge)3 ServerLevel (net.minecraft.server.level.ServerLevel)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 ItemStack (net.minecraft.world.item.ItemStack)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 CraftingInventory (org.spongepowered.api.item.inventory.crafting.CraftingInventory)2 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)2 EffectResult (org.spongepowered.common.event.tracking.context.transaction.effect.EffectResult)2 Audience (net.kyori.adventure.audience.Audience)1 Component (net.kyori.adventure.text.Component)1 MutableComponent (net.minecraft.network.chat.MutableComponent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1