Search in sources :

Example 1 with ServerPlayerConnection

use of net.minecraft.server.network.ServerPlayerConnection 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 2 with ServerPlayerConnection

use of net.minecraft.server.network.ServerPlayerConnection 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)

Example 3 with ServerPlayerConnection

use of net.minecraft.server.network.ServerPlayerConnection in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method enableNetworkManager.

public static void enableNetworkManager() {
    for (World w : Bukkit.getWorlds()) {
        for (ChunkMap.TrackedEntity tracker : ((CraftWorld) w).getHandle().getChunkSource().chunkMap.entityMap.values()) {
            ArrayList<ServerPlayerConnection> connections = new ArrayList<>(tracker.seenBy);
            tracker.seenBy.clear();
            for (ServerPlayerConnection connection : connections) {
                tracker.seenBy.add(connection.getPlayer().connection);
            }
        }
    }
}
Also used : ServerPlayerConnection(net.minecraft.server.network.ServerPlayerConnection) ChunkMap(net.minecraft.server.level.ChunkMap) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Aggregations

ChunkMap (net.minecraft.server.level.ChunkMap)3 ServerPlayerConnection (net.minecraft.server.network.ServerPlayerConnection)3 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 World (org.bukkit.World)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1