Class PlayerLookup

java.lang.Object
net.fabricmc.fabric.api.networking.v1.PlayerLookup

public final class PlayerLookup extends Object
Helper methods to lookup players in a server.

The word "tracking" means that an entity/chunk on the server is known to a player's client (within in view distance) and the (block) entity should notify tracking clients of changes.

These methods should only be called on the server thread and only be used on logical a server.

  • Method Details

    • all

      public static Collection<ServerPlayerEntity> all(MinecraftServer server)
      Gets all the players on the minecraft server.

      The returned collection is immutable.

      Parameters:
      server - the server
      Returns:
      all players on the server
    • world

      public static Collection<ServerPlayerEntity> world(ServerWorld world)
      Gets all the players in a server world.

      The returned collection is immutable.

      Parameters:
      world - the server world
      Returns:
      the players in the server world
    • tracking

      public static Collection<ServerPlayerEntity> tracking(ServerWorld world, ChunkPos pos)
      Gets all players tracking a chunk in a server world.
      Parameters:
      world - the server world
      pos - the chunk in question
      Returns:
      the players tracking the chunk
    • tracking

      public static Collection<ServerPlayerEntity> tracking(Entity entity)
      Gets all players tracking an entity in a server world.

      The returned collection is immutable.

      Warning: If the provided entity is a player, it is not guaranteed by the contract that said player is included in the resulting stream.

      Parameters:
      entity - the entity being tracked
      Returns:
      the players tracking the entity
      Throws:
      IllegalArgumentException - if the entity is not in a server world
    • tracking

      public static Collection<ServerPlayerEntity> tracking(BlockEntity blockEntity)
      Gets all players tracking a block entity in a server world.
      Parameters:
      blockEntity - the block entity
      Returns:
      the players tracking the block position
      Throws:
      IllegalArgumentException - if the block entity is not in a server world
    • tracking

      public static Collection<ServerPlayerEntity> tracking(ServerWorld world, BlockPos pos)
      Gets all players tracking a block position in a server world.
      Parameters:
      world - the server world
      pos - the block position
      Returns:
      the players tracking the block position
    • around

      public static Collection<ServerPlayerEntity> around(ServerWorld world, Vec3d pos, double radius)
      Gets all players around a position in a world.

      The distance check is done in the three-dimensional space instead of in the horizontal plane.

      Parameters:
      world - the world
      pos - the position
      radius - the maximum distance from the position in blocks
      Returns:
      the players around the position
    • around

      public static Collection<ServerPlayerEntity> around(ServerWorld world, Vec3i pos, double radius)
      Gets all players around a position in a world.

      The distance check is done in the three-dimensional space instead of in the horizontal plane.

      Parameters:
      world - the world
      pos - the position (can be a block pos)
      radius - the maximum distance from the position in blocks
      Returns:
      the players around the position