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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
Aggregations