Search in sources :

Example 1 with ServerboundClientInformationPacket

use of net.minecraft.network.protocol.game.ServerboundClientInformationPacket in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method impl$handleClientSettings.

@SuppressWarnings({ "ConstantConditions", "UnstableApiUsage" })
@Inject(method = "updateOptions", at = @At("HEAD"))
private void impl$handleClientSettings(final ServerboundClientInformationPacket packet, final CallbackInfo ci) {
    if (!ShouldFire.PLAYER_CHANGE_CLIENT_SETTINGS_EVENT) {
        return;
    }
    final ServerboundClientInformationPacketAccessor $packet = (ServerboundClientInformationPacketAccessor) packet;
    final Locale newLocale = LocaleCache.getLocale($packet.accessor$language());
    final ImmutableSet<SkinPart> skinParts = Sponge.game().registry(RegistryTypes.SKIN_PART).stream().map(part -> (SpongeSkinPart) part).filter(part -> part.test(packet.getModelCustomisation())).collect(ImmutableSet.toImmutableSet());
    final int viewDistance = $packet.accessor$viewDistance();
    // Post before the player values are updated
    try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
        final ChatVisibility visibility = (ChatVisibility) (Object) packet.getChatVisibility();
        final PlayerChangeClientSettingsEvent event = SpongeEventFactory.createPlayerChangeClientSettingsEvent(frame.currentCause(), visibility, skinParts, newLocale, (ServerPlayer) this, packet.getChatColors(), viewDistance);
        SpongeCommon.post(event);
    }
}
Also used : Locale(java.util.Locale) Inject(org.spongepowered.asm.mixin.injection.Inject) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) PermissionService(org.spongepowered.api.service.permission.PermissionService) PlayerList(net.minecraft.server.players.PlayerList) Team(net.minecraft.world.scores.Team) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) ClientboundPlayerCombatPacket(net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket) ServerScoreboardBridge(org.spongepowered.common.bridge.server.ServerScoreboardBridge) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) Living(org.spongepowered.api.entity.living.Living) BossEventBridge(org.spongepowered.common.bridge.world.BossEventBridge) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Set(java.util.Set) InteractionResult(net.minecraft.world.InteractionResult) Locales(org.spongepowered.api.util.locale.Locales) EntityUtil(org.spongepowered.common.entity.EntityUtil) TextComponent(net.minecraft.network.chat.TextComponent) PlatformHooks(org.spongepowered.common.hooks.PlatformHooks) TicketType(net.minecraft.server.level.TicketType) Shadow(org.spongepowered.asm.mixin.Shadow) ItemStack(net.minecraft.world.item.ItemStack) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) EventContextKeys(org.spongepowered.api.event.EventContextKeys) ServerWorld(org.spongepowered.api.world.server.ServerWorld) DestructEntityEvent(org.spongepowered.api.event.entity.DestructEntityEvent) ClientboundContainerSetSlotPacket(net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket) Overwrite(org.spongepowered.asm.mixin.Overwrite) SpongeSkinPart(org.spongepowered.common.data.type.SpongeSkinPart) ClientboundLevelEventPacket(net.minecraft.network.protocol.game.ClientboundLevelEventPacket) LevelData(net.minecraft.world.level.storage.LevelData) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) ServerboundClientInformationPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundClientInformationPacketAccessor) DataCompoundHolder(org.spongepowered.common.bridge.data.DataCompoundHolder) RotateEntityEvent(org.spongepowered.api.event.entity.RotateEntityEvent) Stats(net.minecraft.stats.Stats) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Opcodes(org.objectweb.asm.Opcodes) Identity(net.kyori.adventure.identity.Identity) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) Scoreboard(org.spongepowered.api.scoreboard.Scoreboard) ShouldFire(org.spongepowered.common.event.ShouldFire) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) DataUtil(org.spongepowered.common.data.DataUtil) Cause(org.spongepowered.api.event.Cause) Channel(io.netty.channel.Channel) ChunkPos(net.minecraft.world.level.ChunkPos) VecHelper(org.spongepowered.common.util.VecHelper) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) InteractionHand(net.minecraft.world.InteractionHand) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) ClientboundGameEventPacket(net.minecraft.network.protocol.game.ClientboundGameEventPacket) Either(com.mojang.datafixers.util.Either) LivingEntity(net.minecraft.world.entity.LivingEntity) Score(net.minecraft.world.scores.Score) PlayerBridge(org.spongepowered.common.bridge.world.entity.player.PlayerBridge) SpongeCommonEventFactory(org.spongepowered.common.event.SpongeCommonEventFactory) ClientboundBossEventPacket(net.minecraft.network.protocol.game.ClientboundBossEventPacket) LocaleCache(org.spongepowered.common.util.LocaleCache) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) PortalLogic(org.spongepowered.common.world.portal.PortalLogic) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) PlayerChangeClientSettingsEvent(org.spongepowered.api.event.entity.living.player.PlayerChangeClientSettingsEvent) ServerGamePacketListenerImplBridge(org.spongepowered.common.bridge.server.network.ServerGamePacketListenerImplBridge) CriteriaTriggers(net.minecraft.advancements.CriteriaTriggers) ChatFormatting(net.minecraft.ChatFormatting) ServerboundClientInformationPacket(net.minecraft.network.protocol.game.ServerboundClientInformationPacket) Locale(java.util.Locale) At(org.spongepowered.asm.mixin.injection.At) Stat(net.minecraft.stats.Stat) BiomeManager(net.minecraft.world.level.biome.BiomeManager) ImmutableSet(com.google.common.collect.ImmutableSet) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) KickPlayerEvent(org.spongepowered.api.event.entity.living.player.KickPlayerEvent) GameRules(net.minecraft.world.level.GameRules) Sponge(org.spongepowered.api.Sponge) ChatType(net.minecraft.network.chat.ChatType) UUID(java.util.UUID) Final(org.spongepowered.asm.mixin.Final) ClientboundUpdateMobEffectPacket(net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket) Player(net.minecraft.world.entity.player.Player) Tristate(org.spongepowered.api.util.Tristate) HoverEvent(net.minecraft.network.chat.HoverEvent) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) PlayerMixin(org.spongepowered.common.mixin.core.world.entity.player.PlayerMixin) Optional(java.util.Optional) Level(net.minecraft.world.level.Level) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ClientboundPlayerAbilitiesPacket(net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket) Unit(net.minecraft.util.Unit) ResultSlot(net.minecraft.world.inventory.ResultSlot) ServerLevel(net.minecraft.server.level.ServerLevel) HashSet(java.util.HashSet) ChangeEntityWorldEvent(org.spongepowered.api.event.entity.ChangeEntityWorldEvent) Component(net.kyori.adventure.text.Component) DamageSource(net.minecraft.world.damagesource.DamageSource) ObjectiveCriteria(net.minecraft.world.scores.criteria.ObjectiveCriteria) SkinPart(org.spongepowered.api.data.type.SkinPart) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Audiences(org.spongepowered.api.adventure.Audiences) PortalInfo(net.minecraft.world.level.portal.PortalInfo) SpongeCommon(org.spongepowered.common.SpongeCommon) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) MovementTypes(org.spongepowered.api.event.cause.entity.MovementTypes) ServerPlayerGameMode(net.minecraft.server.level.ServerPlayerGameMode) Entity(net.minecraft.world.entity.Entity) SubjectBridge(org.spongepowered.common.bridge.permissions.SubjectBridge) ClientboundRespawnPacket(net.minecraft.network.protocol.game.ClientboundRespawnPacket) Vector3d(org.spongepowered.math.vector.Vector3d) ConnectionAccessor(org.spongepowered.common.accessor.network.ConnectionAccessor) Slice(org.spongepowered.asm.mixin.injection.Slice) PlayerOwnBorderListener(org.spongepowered.common.world.border.PlayerOwnBorderListener) PlayerChangeClientSettingsEvent(org.spongepowered.api.event.entity.living.player.PlayerChangeClientSettingsEvent) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ServerboundClientInformationPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundClientInformationPacketAccessor) SpongeSkinPart(org.spongepowered.common.data.type.SpongeSkinPart) SkinPart(org.spongepowered.api.data.type.SkinPart) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with ServerboundClientInformationPacket

use of net.minecraft.network.protocol.game.ServerboundClientInformationPacket in project SpongeCommon by SpongePowered.

the class PacketPhaseUtil method onProcessPacket.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
public static void onProcessPacket(final Packet packetIn, final PacketListener netHandler) {
    if (netHandler instanceof ServerGamePacketListenerImpl) {
        net.minecraft.server.level.ServerPlayer packetPlayer = ((ServerGamePacketListenerImpl) netHandler).player;
        // Only process the CustomPayload & Respawn packets from players if they are dead.
        if (!packetPlayer.isAlive() && (!(packetIn instanceof ServerboundCustomPayloadPacket) && (!(packetIn instanceof ServerboundClientCommandPacket) || ((ServerboundClientCommandPacket) packetIn).getAction() != ServerboundClientCommandPacket.Action.PERFORM_RESPAWN))) {
            return;
        }
        try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
            frame.pushCause(packetPlayer);
            // Don't process movement capture logic if player hasn't moved
            boolean ignoreMovementCapture;
            if (packetIn instanceof ServerboundMovePlayerPacket) {
                final ServerboundMovePlayerPacket movingPacket = ((ServerboundMovePlayerPacket) packetIn);
                if (movingPacket instanceof ServerboundMovePlayerPacket.Rot) {
                    ignoreMovementCapture = true;
                } else if (packetPlayer.getX() == ((ServerboundMovePlayerPacketAccessor) movingPacket).accessor$x() && packetPlayer.getY() == ((ServerboundMovePlayerPacketAccessor) movingPacket).accessor$y() && packetPlayer.getZ() == ((ServerboundMovePlayerPacketAccessor) movingPacket).accessor$z()) {
                    ignoreMovementCapture = true;
                } else {
                    ignoreMovementCapture = false;
                }
                // we cannot ignore movement capture
                if (ignoreMovementCapture) {
                    // Basically, we need to sanity check the nearby blocks because if they have
                    // any positional logic, we need to run captures
                    final AABB boundingBox = packetPlayer.getBoundingBox();
                    final BlockPos min = new BlockPos(boundingBox.minX + 0.001D, boundingBox.minY + 0.001D, boundingBox.minZ + 0.001D);
                    final BlockPos max = new BlockPos(boundingBox.maxX - 0.001D, boundingBox.maxY - 0.001D, boundingBox.maxZ - 0.001D);
                    final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
                    if (packetPlayer.level.hasChunksAt(min, max)) {
                        for (int x = min.getX(); x <= max.getX(); ++x) {
                            for (int y = min.getY(); y <= max.getY(); ++y) {
                                for (int z = min.getZ(); z <= max.getZ(); ++z) {
                                    pos.set(x, y, z);
                                    final Block block = packetPlayer.level.getBlockState(pos).getBlock();
                                    if (((TrackableBlockBridge) block).bridge$hasEntityInsideLogic()) {
                                        ignoreMovementCapture = false;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                ignoreMovementCapture = false;
            }
            if (ignoreMovementCapture || (packetIn instanceof ServerboundClientInformationPacket)) {
                packetIn.handle(netHandler);
            } else {
                final IPhaseState<? extends PacketContext<?>> packetState = PacketPhase.getInstance().getStateForPacket(packetIn);
                // At the very least make an unknown packet state case.
                final PacketContext<?> context = packetState.createPhaseContext(PhaseTracker.SERVER);
                context.source(packetPlayer).packetPlayer(packetPlayer).packet(packetIn);
                if (!PacketPhase.getInstance().isPacketInvalid(packetIn, packetPlayer, packetState)) {
                    PacketPhase.getInstance().populateContext(packetIn, packetPlayer, packetState, context);
                    context.creator(((ServerPlayer) packetPlayer).uniqueId());
                    context.notifier(((ServerPlayer) packetPlayer).uniqueId());
                }
                try (final PhaseContext<?> packetContext = context) {
                    packetContext.buildAndSwitch();
                    packetIn.handle(netHandler);
                }
            }
        }
    } else {
        // client
        packetIn.handle(netHandler);
    }
}
Also used : ServerboundMovePlayerPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundMovePlayerPacketAccessor) TrackableBlockBridge(org.spongepowered.common.bridge.world.level.block.TrackableBlockBridge) ServerboundCustomPayloadPacket(net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket) ServerboundClientCommandPacket(net.minecraft.network.protocol.game.ServerboundClientCommandPacket) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ServerboundMovePlayerPacket(net.minecraft.network.protocol.game.ServerboundMovePlayerPacket) Block(net.minecraft.world.level.block.Block) ServerboundClientInformationPacket(net.minecraft.network.protocol.game.ServerboundClientInformationPacket) BlockPos(net.minecraft.core.BlockPos) AABB(net.minecraft.world.phys.AABB) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl)

Aggregations

BlockPos (net.minecraft.core.BlockPos)2 ServerboundClientInformationPacket (net.minecraft.network.protocol.game.ServerboundClientInformationPacket)2 ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Either (com.mojang.datafixers.util.Either)1 Channel (io.netty.channel.Channel)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Identity (net.kyori.adventure.identity.Identity)1 Component (net.kyori.adventure.text.Component)1 ChatFormatting (net.minecraft.ChatFormatting)1 CriteriaTriggers (net.minecraft.advancements.CriteriaTriggers)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 ChatType (net.minecraft.network.chat.ChatType)1 HoverEvent (net.minecraft.network.chat.HoverEvent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1