Search in sources :

Example 1 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method sendHidePacket.

/*
        Hide Entity
     */
@Override
public void sendHidePacket(Player pl, Entity entity) {
    if (entity instanceof Player) {
        pl.hidePlayer(Denizen.getInstance(), (Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) pl;
    ServerPlayer entityPlayer = craftPlayer.getHandle();
    if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
        ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkSource().chunkMap;
        net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
        ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
        if (entry != null) {
            entry.removePlayer(entityPlayer);
        }
        if (Denizen.supportsPaper) {
            // Workaround for Paper issue
            entityPlayer.connection.send(new ClientboundRemoveEntitiesPacket(other.getId()));
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ChunkMap(net.minecraft.server.level.ChunkMap) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) org.bukkit.entity(org.bukkit.entity) org.bukkit.craftbukkit.v1_18_R1.entity(org.bukkit.craftbukkit.v1_18_R1.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 2 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method sendHidePacket.

/*
        Hide Entity
     */
@Override
public void sendHidePacket(Player pl, Entity entity) {
    if (entity instanceof Player) {
        pl.hidePlayer(Denizen.getInstance(), (Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) pl;
    ServerPlayer entityPlayer = craftPlayer.getHandle();
    if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
        ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkProvider().chunkMap;
        net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
        ChunkMap.TrackedEntity entry = tracker.G.get(other.getId());
        if (entry != null) {
            entry.removePlayer(entityPlayer);
        }
        if (Denizen.supportsPaper) {
            // Workaround for Paper issue
            entityPlayer.connection.send(new ClientboundRemoveEntitiesPacket(other.getId()));
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ChunkMap(net.minecraft.server.level.ChunkMap) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) org.bukkit.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 3 with ClientboundRemoveEntitiesPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditorImpl method updatePlayer.

@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
    final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    final UUID uuid = player.getUniqueId();
    ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (!p.getUniqueId().equals(uuid)) {
            PacketHelperImpl.send(p, destroyPacket);
        }
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
            ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                PacketHelperImpl.send(player, playerInfo);
                if (!player.getUniqueId().equals(uuid)) {
                    PacketHelperImpl.send(player, spawnPacket);
                } else {
                    if (isSkinChanging) {
                        ((CraftServer) Bukkit.getServer()).getHandle().respawn(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
                    }
                    player.updateInventory();
                }
            }
        }
    }.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ClientboundAddPlayerPacket(net.minecraft.network.protocol.game.ClientboundAddPlayerPacket) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v1_18_R1.CraftServer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 4 with ClientboundRemoveEntitiesPacket

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

the class HumanEntity method respawnOnClient.

private void respawnOnClient() {
    this.pushPackets(new ClientboundRemoveEntitiesPacket(this.getId()), this.createPlayerListPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER));
    this.pushPackets(this.getAddEntityPacket());
    this.removeFromTabListDelayed(null, this.createPlayerListPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER));
}
Also used : ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)

Example 5 with ClientboundRemoveEntitiesPacket

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

the class EntityMixin method impl$updateVanishState.

@SuppressWarnings({ "ConstantConditions", "RedundantCast" })
@Inject(method = "tick", at = @At("RETURN"))
private void impl$updateVanishState(final CallbackInfo callbackInfo) {
    if (this.impl$pendingVisibilityUpdate && !this.level.isClientSide) {
        final ChunkMap_TrackedEntityAccessor trackerAccessor = ((ChunkMapAccessor) ((ServerWorld) this.level).chunkManager()).accessor$entityMap().get(this.shadow$getId());
        if (trackerAccessor != null && this.impl$visibilityTicks % 4 == 0) {
            if (this.bridge$vanishState().invisible()) {
                for (final ServerPlayer entityPlayerMP : trackerAccessor.accessor$seenBy()) {
                    entityPlayerMP.connection.send(new ClientboundRemoveEntitiesPacket(this.shadow$getId()));
                    if ((Entity) (Object) this instanceof ServerPlayer) {
                        entityPlayerMP.connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, (ServerPlayer) (Object) this));
                    }
                }
            } else {
                this.impl$visibilityTicks = 1;
                this.impl$pendingVisibilityUpdate = false;
                for (final ServerPlayer entityPlayerMP : SpongeCommon.server().getPlayerList().getPlayers()) {
                    if ((Entity) (Object) this == entityPlayerMP) {
                        continue;
                    }
                    if ((Entity) (Object) this instanceof ServerPlayer) {
                        final Packet<?> packet = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, (ServerPlayer) (Object) this);
                        entityPlayerMP.connection.send(packet);
                    }
                    trackerAccessor.accessor$updatePlayer(entityPlayerMP);
                }
            }
        }
        if (this.impl$visibilityTicks > 0) {
            this.impl$visibilityTicks--;
        } else {
            this.impl$pendingVisibilityUpdate = false;
        }
    }
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)7 ServerPlayer (net.minecraft.server.level.ServerPlayer)6 ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 UUID (java.util.UUID)2 ClientboundAddPlayerPacket (net.minecraft.network.protocol.game.ClientboundAddPlayerPacket)2 ChunkMap (net.minecraft.server.level.ChunkMap)2 net.minecraft.world.entity (net.minecraft.world.entity)2 org.bukkit.entity (org.bukkit.entity)2 Player (org.bukkit.entity.Player)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 ChunkMap_TrackedEntityAccessor (org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClientboundAddPaintingPacket (net.minecraft.network.protocol.game.ClientboundAddPaintingPacket)1 Motive (net.minecraft.world.entity.decoration.Motive)1 Painting (net.minecraft.world.entity.decoration.Painting)1 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)1 org.bukkit.craftbukkit.v1_17_R1.entity (org.bukkit.craftbukkit.v1_17_R1.entity)1 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1