Class EntityQuery

java.lang.Object
nl.pim16aap2.lightkeeper.framework.EntityQuery

public final class EntityQuery extends Object
LIVE, composable entity query for one world: filters build new immutable queries, terminals re-query the server per call.

count() is a single cheap RPC, the natural probe for eventually(timeout, () -> assertThat(query.count()).isEqualTo(n)); snapshot() reads all matching entities in one main-thread burst, so the returned states are internally consistent and share one tick stamp — the property that makes "N in flight, zero after" accounting deterministic.

Only entities in loaded chunks are visible (the Bukkit contract). In a world with no players keep the relevant chunks loaded — e.g. via the console command forceload add — or the server unloads them, taking their entities out of query range.

  • Method Details

    • ofType

      public EntityQuery ofType(String typeKey)
      Returns a copy of this query filtered to one entity type.
      Parameters:
      typeKey - Namespaced entity type key, e.g. minecraft:block_display (the minecraft: prefix is optional).
      Returns:
      A new query with the type filter applied.
    • within

      public EntityQuery within(BlockPos min, BlockPos max)
      Returns a copy of this query restricted to a block-aligned bounding box (inclusive on every axis).

      An entity matches when its hitbox intersects the box (the Bukkit nearby-entities semantic), not only when its position lies inside it — a large entity standing just outside the box whose hitbox overlaps it still counts.

      Parameters:
      min - Minimum corner.
      max - Maximum corner.
      Returns:
      A new query with the spatial bound applied.
    • count

      public int count()
      Counts the matching entities — one RPC, the cheap probe shape for retrying assertions.
      Returns:
      The number of matching entities right now.
    • description

      public String description()
      Returns:
      A read-only description of the world and filters, without executing the query.
    • snapshot

      public List<EntitySnapshot> snapshot()
      Snapshots all matching entities in one main-thread burst.
      Returns:
      Internally consistent snapshots sharing one tick stamp.