Search in sources :

Example 1 with ServerPlayerBridge

use of org.spongepowered.common.bridge.server.level.ServerPlayerBridge in project SpongeCommon by SpongePowered.

the class PlayerListMixin method impl$callRespawnPlayerRecreateEvent.

@Redirect(method = "respawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;send(Lnet/minecraft/network/protocol/Packet;)V", ordinal = 1))
private void impl$callRespawnPlayerRecreateEvent(final ServerGamePacketListenerImpl serverPlayNetHandler, final Packet<?> packetIn, final net.minecraft.server.level.ServerPlayer originalPlayer, final boolean keepAllPlayerData) {
    final net.minecraft.server.level.ServerPlayer recreatedPlayer = serverPlayNetHandler.player;
    final Vector3d originalPosition = VecHelper.toVector3d(originalPlayer.position());
    final Vector3d destinationPosition = VecHelper.toVector3d(recreatedPlayer.position());
    final org.spongepowered.api.world.server.ServerWorld originalWorld = (org.spongepowered.api.world.server.ServerWorld) originalPlayer.level;
    final org.spongepowered.api.world.server.ServerWorld originalDestinationWorld = (org.spongepowered.api.world.server.ServerWorld) this.server.getLevel(this.impl$originalDestination == null ? Level.OVERWORLD : this.impl$originalDestination);
    final org.spongepowered.api.world.server.ServerWorld destinationWorld = (org.spongepowered.api.world.server.ServerWorld) this.server.getLevel(this.impl$newDestination == null ? Level.OVERWORLD : this.impl$newDestination);
    final RespawnPlayerEvent.Recreate event = SpongeEventFactory.createRespawnPlayerEventRecreate(PhaseTracker.getCauseStackManager().currentCause(), destinationPosition, originalWorld, originalPosition, destinationWorld, originalDestinationWorld, destinationPosition, (ServerPlayer) originalPlayer, (ServerPlayer) recreatedPlayer, this.impl$isGameMechanicRespawn, !keepAllPlayerData);
    SpongeCommon.post(event);
    recreatedPlayer.setPos(event.destinationPosition().x(), event.destinationPosition().y(), event.destinationPosition().z());
    this.impl$isGameMechanicRespawn = false;
    this.impl$originalDestination = null;
    this.impl$newDestination = null;
    final ServerLevel targetWorld = (ServerLevel) event.destinationWorld();
    ((ServerPlayerBridge) recreatedPlayer).bridge$sendChangeDimension(targetWorld.dimensionType(), ((ClientboundRespawnPacketAccessor) packetIn).accessor$dimension(), ((ClientboundRespawnPacketAccessor) packetIn).accessor$seed(), recreatedPlayer.gameMode.getGameModeForPlayer(), recreatedPlayer.gameMode.getPreviousGameModeForPlayer(), targetWorld.isDebug(), targetWorld.isFlat(), keepAllPlayerData);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) RespawnPlayerEvent(org.spongepowered.api.event.entity.living.player.RespawnPlayerEvent) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) Vector3d(org.spongepowered.math.vector.Vector3d) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with ServerPlayerBridge

use of org.spongepowered.common.bridge.server.level.ServerPlayerBridge in project SpongeCommon by SpongePowered.

the class EntityUtil method performPostChangePlayerWorldLogic.

public static void performPostChangePlayerWorldLogic(final ServerPlayer player, final ServerLevel fromWorld, final ServerLevel originalToWorld, final ServerLevel toWorld, final boolean isPortal) {
    // Sponge Start - Send any platform dimension data
    ((ServerPlayerBridge) player).bridge$sendDimensionData(player.connection.connection, toWorld.dimensionType(), toWorld.dimension());
    // Sponge End
    final LevelData worldinfo = toWorld.getLevelData();
    // We send dimension change for portals before loading chunks
    if (!isPortal) {
        // Sponge Start - Allow the platform to handle how dimension changes are sent down
        ((ServerPlayerBridge) player).bridge$sendChangeDimension(toWorld.dimensionType(), toWorld.dimension(), BiomeManager.obfuscateSeed(toWorld.getSeed()), player.gameMode.getGameModeForPlayer(), player.gameMode.getPreviousGameModeForPlayer(), toWorld.isDebug(), toWorld.isFlat(), true);
    }
    // Sponge End
    player.connection.send(new ClientboundChangeDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
    final PlayerList playerlist = player.getServer().getPlayerList();
    playerlist.sendPlayerPermissionLevel(player);
    // Sponge Start - Have the platform handle removing the entity from the world. Move this to after the event call so
    // that we do not remove the player from the world unless we really have teleported..
    ((PlatformServerLevelBridge) fromWorld).bridge$removeEntity(player, true);
    ((PlatformEntityBridge) player).bridge$revive();
    // Sponge End
    player.setLevel(toWorld);
    toWorld.addDuringPortalTeleport(player);
    if (isPortal) {
        ((ServerPlayerAccessor) player).invoker$triggerDimensionChangeTriggers(toWorld);
    }
    player.gameMode.setLevel(toWorld);
    player.connection.send(new ClientboundPlayerAbilitiesPacket(player.abilities));
    playerlist.sendLevelInfo(player, toWorld);
    playerlist.sendAllPlayerInfo(player);
    for (final MobEffectInstance effectinstance : player.getActiveEffects()) {
        player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effectinstance));
    }
    if (isPortal) {
        player.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
    }
    ((ServerLevelBridge) fromWorld).bridge$getBossBarManager().onPlayerDisconnect(player);
    ((ServerLevelBridge) toWorld).bridge$getBossBarManager().onPlayerDisconnect(player);
    ((ServerPlayerAccessor) player).accessor$lastSentExp(-1);
    ((ServerPlayerAccessor) player).accessor$lastSentHealth(-1.0f);
    ((ServerPlayerAccessor) player).accessor$lastSentFood(-1);
    if (!isPortal) {
        player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.yRot, player.xRot);
        player.connection.resetPosition();
    }
    if (player.containerMenu != player.inventoryMenu) {
        player.closeContainer();
    }
    // Sponge Start - Call event
    Sponge.eventManager().post(SpongeEventFactory.createChangeEntityWorldEventPost(PhaseTracker.getCauseStackManager().currentCause(), (org.spongepowered.api.entity.Entity) player, (ServerWorld) fromWorld, (ServerWorld) originalToWorld, (ServerWorld) toWorld));
// Sponge End
}
Also used : Entity(net.minecraft.world.entity.Entity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) PlatformServerLevelBridge(org.spongepowered.common.bridge.world.level.PlatformServerLevelBridge) PlayerList(net.minecraft.server.players.PlayerList) ClientboundLevelEventPacket(net.minecraft.network.protocol.game.ClientboundLevelEventPacket) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) ClientboundUpdateMobEffectPacket(net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket) PlatformEntityBridge(org.spongepowered.common.bridge.world.entity.PlatformEntityBridge) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) ServerWorld(org.spongepowered.api.world.server.ServerWorld) ClientboundPlayerAbilitiesPacket(net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket) ServerPlayerAccessor(org.spongepowered.common.accessor.server.level.ServerPlayerAccessor) LevelData(net.minecraft.world.level.storage.LevelData)

Example 3 with ServerPlayerBridge

use of org.spongepowered.common.bridge.server.level.ServerPlayerBridge 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 4 with ServerPlayerBridge

use of org.spongepowered.common.bridge.server.level.ServerPlayerBridge in project SpongeCommon by SpongePowered.

the class ServerEntityMixin method impl$createSpoofedPacket.

@Redirect(method = "sendDirtyEntityData", at = @At(value = "NEW", target = "net/minecraft/network/protocol/game/ClientboundSetEntityDataPacket"))
private ClientboundSetEntityDataPacket impl$createSpoofedPacket(int entityId, SynchedEntityData dataManager, boolean p_i46917_3_) {
    if (!(this.entity instanceof ServerPlayerBridge && ((ServerPlayerBridge) this.entity).bridge$isHealthScaled())) {
        return new ClientboundSetEntityDataPacket(entityId, dataManager, p_i46917_3_);
    }
    final float scaledHealth = ((ServerPlayerBridge) this.entity).bridge$getInternalScaledHealth();
    final Float actualHealth = dataManager.get(LivingEntityAccessor.accessor$DATA_HEALTH_ID());
    dataManager.set(LivingEntityAccessor.accessor$DATA_HEALTH_ID(), scaledHealth);
    final ClientboundSetEntityDataPacket spoofed = new ClientboundSetEntityDataPacket(entityId, dataManager, p_i46917_3_);
    dataManager.set(LivingEntityAccessor.accessor$DATA_HEALTH_ID(), actualHealth);
    return spoofed;
}
Also used : ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 5 with ServerPlayerBridge

use of org.spongepowered.common.bridge.server.level.ServerPlayerBridge in project SpongeCommon by SpongePowered.

the class ServerPlayerData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ServerPlayer.class).create(Keys.GAME_MODE).get(h -> (GameMode) (Object) h.gameMode.getGameModeForPlayer()).set((h, v) -> h.setGameMode((GameType) (Object) v)).create(Keys.SKIN_PROFILE_PROPERTY).get(h -> {
        final Collection<Property> properties = h.getGameProfile().getProperties().get(ProfileProperty.TEXTURES);
        if (properties.isEmpty()) {
            return null;
        }
        return new SpongeProfileProperty(properties.iterator().next());
    }).create(Keys.SPECTATOR_TARGET).get(h -> (Entity) h.getCamera()).set((h, v) -> h.setCamera((net.minecraft.world.entity.Entity) v)).delete(h -> h.setCamera(null)).create(Keys.STATISTICS).get(h -> ((StatsCounterBridge) h.getStats()).bridge$getStatsData().entrySet().stream().collect(Collectors.toMap(e -> (Statistic) e.getKey(), e -> e.getValue().longValue()))).set((h, v) -> v.forEach((ik, iv) -> h.getStats().setValue(h, (Stat<?>) ik, iv.intValue()))).create(Keys.CHAT_VISIBILITY).get(h -> {
        final ChatVisibility visibility = (ChatVisibility) (Object) h.getChatVisibility();
        if (visibility == null) {
            return ChatVisibilities.FULL.get();
        }
        return visibility;
    }).asMutable(ServerPlayerAccessor.class).create(Keys.HAS_VIEWED_CREDITS).get(ServerPlayerAccessor::accessor$seenCredits).set(ServerPlayerAccessor::accessor$seenCredits).create(Keys.CHAT_COLORS_ENABLED).get(ServerPlayerAccessor::accessor$canChatColor).asMutable(ServerPlayerBridge.class).create(Keys.LOCALE).get(ServerPlayerBridge::bridge$getLanguage).create(Keys.HEALTH_SCALE).get(ServerPlayerEntityHealthScaleBridge::bridge$getHealthScale).setAnd((h, v) -> {
        if (v < 1f || v > Float.MAX_VALUE) {
            return false;
        }
        h.bridge$setHealthScale(v);
        return true;
    }).delete(b -> b.bridge$setHealthScale(null)).create(Keys.VIEW_DISTANCE).get(ServerPlayerBridge::bridge$getViewDistance).create(Keys.SKIN_PARTS).get(ServerPlayerBridge::bridge$getSkinParts).create(Keys.IS_SLEEPING_IGNORED).get(ServerPlayerBridge::bridge$sleepingIgnored).set(ServerPlayerBridge::bridge$setSleepingIgnored);
    registrator.spongeDataStore(Keys.HEALTH_SCALE.key(), ServerPlayerEntityHealthScaleBridge.class, Keys.HEALTH_SCALE);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.Player.HEALTH_SCALE, Keys.HEALTH_SCALE.key(), Keys.HEALTH_SCALE);
}
Also used : Stat(net.minecraft.stats.Stat) Statistic(org.spongepowered.api.statistic.Statistic) ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty) ChatVisibilities(org.spongepowered.api.entity.living.player.chat.ChatVisibilities) Constants(org.spongepowered.common.util.Constants) Collection(java.util.Collection) ServerPlayerEntityHealthScaleBridge(org.spongepowered.common.bridge.server.level.ServerPlayerEntityHealthScaleBridge) SpongeProfileProperty(org.spongepowered.common.profile.SpongeProfileProperty) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) SpongeDataManager(org.spongepowered.common.data.SpongeDataManager) StatsCounterBridge(org.spongepowered.common.bridge.stats.StatsCounterBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) Keys(org.spongepowered.api.data.Keys) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) Property(com.mojang.authlib.properties.Property) ServerPlayerAccessor(org.spongepowered.common.accessor.server.level.ServerPlayerAccessor) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) GameType(net.minecraft.world.level.GameType) Entity(org.spongepowered.api.entity.Entity) SpongeProfileProperty(org.spongepowered.common.profile.SpongeProfileProperty) Statistic(org.spongepowered.api.statistic.Statistic) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) Collection(java.util.Collection) ServerPlayerAccessor(org.spongepowered.common.accessor.server.level.ServerPlayerAccessor) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge)

Aggregations

ServerPlayerBridge (org.spongepowered.common.bridge.server.level.ServerPlayerBridge)5 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 ServerPlayerAccessor (org.spongepowered.common.accessor.server.level.ServerPlayerAccessor)2 Property (com.mojang.authlib.properties.Property)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 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 ClientboundChangeDifficultyPacket (net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket)1 ClientboundLevelEventPacket (net.minecraft.network.protocol.game.ClientboundLevelEventPacket)1 ClientboundPlayerAbilitiesPacket (net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket)1 ClientboundSetEntityDataPacket (net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)1 ClientboundUpdateMobEffectPacket (net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 PlayerList (net.minecraft.server.players.PlayerList)1 Stat (net.minecraft.stats.Stat)1