Search in sources :

Example 1 with ChunkMap

use of net.minecraft.server.level.ChunkMap 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 ChunkMap

use of net.minecraft.server.level.ChunkMap in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method getPlayersThatSee.

@Override
public List<Player> getPlayersThatSee(Entity entity) {
    ChunkMap tracker = ((ServerLevel) ((CraftEntity) entity).getHandle().level).getChunkSource().chunkMap;
    ChunkMap.TrackedEntity entityTracker = tracker.entityMap.get(entity.getEntityId());
    ArrayList<Player> output = new ArrayList<>();
    if (entityTracker == null) {
        return output;
    }
    for (ServerPlayerConnection player : entityTracker.seenBy) {
        output.add(player.getPlayer().getBukkitEntity());
    }
    return output;
}
Also used : ServerPlayerConnection(net.minecraft.server.network.ServerPlayerConnection) ChunkMap(net.minecraft.server.level.ChunkMap) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 3 with ChunkMap

use of net.minecraft.server.level.ChunkMap in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method sendShowPacket.

@Override
public void sendShowPacket(Player pl, Entity entity) {
    if (entity instanceof Player) {
        pl.showPlayer(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);
            entry.updatePlayer(entityPlayer);
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ChunkMap(net.minecraft.server.level.ChunkMap) 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 4 with ChunkMap

use of net.minecraft.server.level.ChunkMap 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 5 with ChunkMap

use of net.minecraft.server.level.ChunkMap in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method getPlayersThatSee.

@Override
public List<Player> getPlayersThatSee(Entity entity) {
    ChunkMap tracker = ((ServerLevel) ((CraftEntity) entity).getHandle().level).getChunkProvider().chunkMap;
    ChunkMap.TrackedEntity entityTracker = tracker.G.get(entity.getEntityId());
    ArrayList<Player> output = new ArrayList<>();
    if (entityTracker == null) {
        return output;
    }
    for (ServerPlayerConnection player : entityTracker.seenBy) {
        output.add(player.getPlayer().getBukkitEntity());
    }
    return output;
}
Also used : ServerPlayerConnection(net.minecraft.server.network.ServerPlayerConnection) ChunkMap(net.minecraft.server.level.ChunkMap) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Aggregations

ChunkMap (net.minecraft.server.level.ChunkMap)10 ServerPlayer (net.minecraft.server.level.ServerPlayer)6 net.minecraft.world.entity (net.minecraft.world.entity)4 org.bukkit.entity (org.bukkit.entity)4 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)2 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)2 ServerEntity (net.minecraft.server.level.ServerEntity)2 ServerPlayerConnection (net.minecraft.server.network.ServerPlayerConnection)2 org.bukkit.craftbukkit.v1_17_R1.entity (org.bukkit.craftbukkit.v1_17_R1.entity)2 org.bukkit.craftbukkit.v1_18_R1.entity (org.bukkit.craftbukkit.v1_18_R1.entity)2 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)1