Class EntityQuery<T extends EntityContext, Q extends EntityQuery<T,Q>>
java.lang.Object
com.botwithus.bot.api.entities.EntityQuery<T,Q>
- Type Parameters:
T- rich entity typeQ- self-type for fluent chaining (CRTP)
- Direct Known Subclasses:
GroundItems.Query, Npcs.Query, Players.Query, Projectiles.Query, SceneObjects.Query
public abstract class EntityQuery<T extends EntityContext, Q extends EntityQuery<T,Q>>
extends Object
Fluent query builder shared across entity types. Subclasses bind the
concrete result type
T (Npc, Player, ...) and provide the
snapshot-backed source stream plus the bits that are entity-specific
(id field, name resolution).
Filters compose: each call narrows the set. Terminal operations
(all(), nearest(), first(), count(),
exists(), stream()) materialise the result. The builder
is single-use — once you call a terminal it's done; build a new query
for another lookup.
All filters run client-side against the published snapshot, so a query is a few microseconds plus whatever definition lookups the rich wrappers trigger (which are cached by id on the entity facade).
-
Method Summary
Modifier and TypeMethodDescriptionall()intcount()booleanexists()Adds a predicate; multiple calls AND together.First match as Optional.Nearest as Optional.first()First match in source order, ornull.limit(int max) Cap the number of results.Filter by display name (case-insensitive substring).namedExact(String name) Filter by display name (case-insensitive exact match).nameMatching(String regex) Filter by display name (regex match against the full name).nearest()Nearest result, ornullwhen no match.onPlane(int plane) Filter to a specific plane.Sort results by distance from the local player, ascending.stream()Stream over the materialised result list (filters/sort already applied).visible()Convenience shim — the snapshot only carries visible entities, so this method is a no-op chain.withId(int typeId) Filter by type/definition id.within(int tileX, int tileY, int radius) Filter to entities withinradiustiles (Chebyshev) of the given world tile.withinDistance(int radius) Filter to entities withinradiustiles of the local player.
-
Method Details
-
filter
-
named
-
namedExact
-
nameMatching
Filter by display name (regex match against the full name).- Throws:
PatternSyntaxException- ifregexis malformed
-
withId
Filter by type/definition id. -
onPlane
Filter to a specific plane. -
visible
Convenience shim — the snapshot only carries visible entities, so this method is a no-op chain. Kept so call sites that pre-date the rewrite (e.g.new SceneObjects(api).query().withId(id).visible().all()) keep compiling. -
within
Filter to entities withinradiustiles (Chebyshev) of the given world tile. -
withinDistance
Filter to entities withinradiustiles of the local player. Returns no results when the local player is not in-game. -
sortByDistance
Sort results by distance from the local player, ascending. -
limit
Cap the number of results. Applied after sorting. -
all
-
nearest
Nearest result, ornullwhen no match. ImpliessortByDistance(). -
findNearest
-
first
First match in source order, ornull. No distance sort applied. -
findFirst
-
count
public int count() -
exists
public boolean exists() -
stream
-