Search in sources :

Example 6 with SPlayEntityEffectPacket

use of net.minecraft.network.play.server.SPlayEntityEffectPacket in project Arclight by IzzelAliz.

the class PlayerListMixin method moveToWorld.

public ServerPlayerEntity moveToWorld(ServerPlayerEntity playerIn, DimensionType type, boolean flag, Location location, boolean avoidSuffocation) {
    if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(playerIn, type))
        return playerIn;
    playerIn.stopRiding();
    this.players.remove(playerIn);
    // this.playersByName.remove(playerIn.getScoreboardName().toLowerCase(Locale.ROOT));
    playerIn.getServerWorld().removePlayer(playerIn, true);
    BlockPos pos = playerIn.getBedLocation(type);
    boolean flag2 = playerIn.isSpawnForced(type);
    org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
    playerIn.queuedEndExit = false;
    playerIn.copyFrom(playerIn, flag);
    playerIn.setEntityId(playerIn.getEntityId());
    playerIn.setPrimaryHand(playerIn.getPrimaryHand());
    for (String s : playerIn.getTags()) {
        playerIn.addTag(s);
    }
    if (location == null) {
        boolean isBedSpawn = false;
        CraftWorld cworld = (CraftWorld) Bukkit.getServer().getWorld(((ServerPlayerEntityBridge) playerIn).bridge$getSpawnWorld());
        if (cworld != null && pos != null) {
            Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), pos, flag2);
            if (optional.isPresent()) {
                Vec3d vec3d = optional.get();
                isBedSpawn = true;
                location = new Location(cworld, vec3d.x, vec3d.y, vec3d.z);
            } else {
                this.bridge$setSpawnPoint(playerIn, null, true, playerIn.dimension, false);
                playerIn.connection.sendPacket(new SChangeGameStatePacket(0, 0.0f));
            }
        }
        if (location == null) {
            cworld = (CraftWorld) Bukkit.getServer().getWorlds().get(0);
            pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
            location = new Location(cworld, pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f);
        }
        Player respawnPlayer = this.cserver.getPlayer(playerIn);
        PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
        this.cserver.getPluginManager().callEvent(respawnEvent);
        if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
            return playerIn;
        }
        location = respawnEvent.getRespawnLocation();
        if (!flag) {
            ((ServerPlayerEntityBridge) playerIn).bridge$reset();
        }
    } else {
        location.setWorld(((WorldBridge) this.server.getWorld(type)).bridge$getWorld());
    }
    ServerWorld serverWorld = ((CraftWorld) location.getWorld()).getHandle();
    playerIn.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    playerIn.connection.captureCurrentPosition();
    while (avoidSuffocation && !serverWorld.hasNoCollisions(playerIn) && playerIn.getPosY() < 256.0) {
        playerIn.setPosition(playerIn.getPosX(), playerIn.getPosY() + 1.0, playerIn.getPosZ());
    }
    if (fromWorld.getEnvironment() == ((WorldBridge) serverWorld).bridge$getWorld().getEnvironment()) {
        playerIn.connection.sendPacket(this.bridge$respawnPacket((serverWorld.dimension.getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
    }
    WorldInfo worldInfo = serverWorld.getWorldInfo();
    net.minecraftforge.fml.network.NetworkHooks.sendDimensionDataPacket(playerIn.connection.netManager, playerIn);
    playerIn.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverWorld.dimension.getType()).bridge$getType(), serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
    playerIn.connection.sendPacket(new SUpdateViewDistancePacket(((ServerWorldBridge) serverWorld).bridge$spigotConfig().viewDistance));
    playerIn.setWorld(serverWorld);
    playerIn.interactionManager.setWorld(serverWorld);
    playerIn.revive();
    ((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), playerIn.rotationYaw, playerIn.rotationPitch));
    playerIn.setSneaking(false);
    BlockPos pos1 = serverWorld.getSpawnPoint();
    playerIn.connection.sendPacket(new SSpawnPositionPacket(pos1));
    playerIn.connection.sendPacket(new SServerDifficultyPacket(worldInfo.getDifficulty(), worldInfo.isDifficultyLocked()));
    playerIn.connection.sendPacket(new SSetExperiencePacket(playerIn.experience, playerIn.experienceTotal, playerIn.experienceLevel));
    this.sendWorldInfo(playerIn, serverWorld);
    this.updatePermissionLevel(playerIn);
    if (!((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
        serverWorld.addRespawnedPlayer(playerIn);
        this.players.add(playerIn);
        // this.playersByName.put(entityplayer2.getScoreboardName().toLowerCase(Locale.ROOT), entityplayer2);
        this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn);
    }
    playerIn.setHealth(playerIn.getHealth());
    this.sendInventory(playerIn);
    playerIn.sendPlayerAbilities();
    for (Object o1 : playerIn.getActivePotionEffects()) {
        EffectInstance mobEffect = (EffectInstance) o1;
        playerIn.connection.sendPacket(new SPlayEntityEffectPacket(playerIn.getEntityId(), mobEffect));
    }
    playerIn.func_213846_b(((CraftWorld) fromWorld).getHandle());
    if (fromWorld != location.getWorld()) {
        PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
        Bukkit.getPluginManager().callEvent(event);
    }
    if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
        this.writePlayerData(playerIn);
    }
    net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerRespawnEvent(playerIn, flag);
    return playerIn;
}
Also used : DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ServerWorldBridge(io.izzel.arclight.common.bridge.world.server.ServerWorldBridge) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) SSetExperiencePacket(net.minecraft.network.play.server.SSetExperiencePacket) Player(org.bukkit.entity.Player) SUpdateViewDistancePacket(net.minecraft.network.play.server.SUpdateViewDistancePacket) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) SSpawnPositionPacket(net.minecraft.network.play.server.SSpawnPositionPacket) EffectInstance(net.minecraft.potion.EffectInstance) Location(org.bukkit.Location)

Aggregations

SPlayEntityEffectPacket (net.minecraft.network.play.server.SPlayEntityEffectPacket)6 EffectInstance (net.minecraft.potion.EffectInstance)5 ServerWorld (net.minecraft.world.server.ServerWorld)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 SChangeGameStatePacket (net.minecraft.network.play.server.SChangeGameStatePacket)3 SRespawnPacket (net.minecraft.network.play.server.SRespawnPacket)3 SServerDifficultyPacket (net.minecraft.network.play.server.SServerDifficultyPacket)3 BlockPos (net.minecraft.util.math.BlockPos)3 Vec3d (net.minecraft.util.math.Vec3d)3 WorldInfo (net.minecraft.world.storage.WorldInfo)3 Location (org.bukkit.Location)3 PlayerChangedWorldEvent (org.bukkit.event.player.PlayerChangedWorldEvent)3 ServerPlayNetHandlerBridge (io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge)2 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)2 DimensionTypeBridge (io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge)2 ServerWorldBridge (io.izzel.arclight.common.bridge.world.server.ServerWorldBridge)2 Nullable (javax.annotation.Nullable)2 SPlaySoundEventPacket (net.minecraft.network.play.server.SPlaySoundEventPacket)2 SPlayerAbilitiesPacket (net.minecraft.network.play.server.SPlayerAbilitiesPacket)2 PlayerList (net.minecraft.server.management.PlayerList)2