NpcQuery
A search over the NPCs around you. Chain filters, then take a result.
ClassRLPlugins API
public class NpcQuery extends AbstractActorQuery<NpcEx, NpcQuery>Each filter returns the same query, so you can chain them in any order. The search runs when you call AbstractActorQuery.nearest(), AbstractQuery.first(), AbstractQuery.count() or AbstractQuery.isEmpty().
Example
NpcEx guard = NpcAPI.search()
.withName("Guard")
.withAction("Attack")
.alive()
.within(10)
.nearest();Members
Constructors
- newNpcQuery()
Initializes the NpcQuery with the list of all NPCs from the GameManager.
Methods
- NpcQueryalive()
Keeps NPCs that are not dead.
- NpcQuerywalkable()
Walkable.
- NpcQuerywithAction(String)
Keeps NPCs that offer this action.
- NpcQuerywithIds(int...)
Keeps NPCs with one of these IDs.
- NpcQuerywithIndex(int)
Filters NPCs by their index.
- NpcQuerywithinWorldArea(WorldArea)
Within world area.
- NpcQuerywithName(String)
Keeps NPCs with this name.
- AbstractActorQuerywithName(String)
Keeps NPCs with this name.
- NpcQuerywithNameContains(String)
Filters NPCs whose names contain the specified substring.
- AbstractActorQuerywithNameContains(String)
Filters NPCs whose names contain the specified substring.
- NpcQuerywithNames(String...)
Keeps NPCs with any of these names.
Inherited from AbstractQuery
- Raggregate(Function<Stream<NpcEx>, R>)
Generic aggregation method for custom terminal operations Executes filters and allows custom stream processing.
- booleanall(Predicate<NpcEx>)
Check if all filtered results match the predicate.
- booleanany(Predicate<NpcEx>)
Check if any filtered result matches the predicate.
- List<NpcEx>collect()
Get the filtered/sorted list.
- Rcollect(Collector<NpcEx, ?, R>)
Execute filters and process with custom collector.
- intcount()
How many results match.
- NpcQuerydistinct()
Ensure results are distinct.
- NpcExfirst()
The first match.
- voidfirstIfPresent(Consumer<NpcEx>)
First if present.
- voidfirstOrElse(Consumer<NpcEx>, Runnable)
Perform action on the first element, or else run elseAction if no results.
- voidforEach(Consumer<NpcEx>)
Executes filters and performs an action on each result.
- booleanisEmpty()
Whether nothing matches.
- NpcQuerykeepIf(Predicate<NpcEx>)
Lazily filter by predicate (keeps matching items).
- NpcExlast()
Get the last element from the filtered/sorted list.
- voidlastOrElse(Consumer<NpcEx>, Runnable)
Perform action on the last element, or else run elseAction if no results.
- NpcQuerylimit(int)
Limit the number of results.
- booleannone(Predicate<NpcEx>)
Check if no filtered results match the predicate.
- NpcQuerypeek(Consumer<NpcEx>)
Peek at each element during processing.
- NpcQuerypostProcess(Function<List<NpcEx>, List<NpcEx>>)
Apply a post-processing function after sorting.
- NpcExrandom()
Get a random element from the filtered/sorted list.
- NpcQueryremoveIf(Predicate<NpcEx>)
Lazily filter by predicate (removes matching items).
- NpcQueryskip(int)
Skip a number of results.
- NpcQuerysort(Comparator<NpcEx>)
Lazily add sorting.
Inherited from AbstractActorQuery
- NpcQueryatLocation(WorldPoint)
Filter by exact location.
- NpcQuerycanAttack()
Filter to npcs the player can attack.
- NpcExfarthest()
Get the farthest Actor from the filtered list Terminal operation - executes the query.
- NpcExfarthest(WorldPoint)
Get the farthest Actor from a specific point Terminal operation - executes the query.
- NpcQueryfree()
Filter actors that are already interacting.
- NpcQueryhasLos()
Filter actors that the player has line of sight to.
- NpcQueryinteractingWith(ActorEx<?>)
Filter actors that are currently interacting with a specific target actor.
- NpcQueryisReachable()
Filter reachable actors.
- NpcExlongestPath()
Get the Actor with the furthest path from the filtered list Terminal operation - executes the query.
- NpcExnearest()
The match closest to you.
- NpcExnearest(WorldPoint)
The match closest to a point.
- NpcExshortestPath()
Get the Actor with the shortest path from the filtered list Terminal operation - executes the query.
- NpcQuerysortFurthest()
Sort by furthest from the player.
- NpcQuerysortFurthest(WorldPoint)
Sort by furthest from a specific point.
- NpcQuerysortLongestPath()
Sort by furthest path from the player.
- NpcQuerysortLongestPath(WorldPoint)
Sort by furthest path from a specific point.
- NpcQuerysortNearest()
Sort by nearest to the player.
- NpcQuerysortNearest(WorldPoint)
Sort by nearest to a specific point.
- NpcQuerysortShortestPath()
Sort by shortest path from the player.
- NpcQuerysortShortestPath(WorldPoint)
Sort by shortest path from a specific point.
- NpcQuerywithin(int)
Keeps matches within this many tiles of you.
- NpcQuerywithin(WorldPoint, int)
Keeps matches within this many tiles of a point.
NpcQuery()
public NpcQuery()Initializes the NpcQuery with the list of all NPCs from the GameManager.
alive()
public NpcQuery alive()Keeps NPCs that are not dead.
Returns
This query.
walkable()
public NpcQuery walkable()Walkable.
withAction(String)
public NpcQuery withAction(String action)Keeps NPCs that offer this action.
Parameters
action- A menu action such as
"Attack". Capital letters are ignored; the whole action must match.
Returns
This query.
withIds(int...)
public NpcQuery withIds(int... ids)Keeps NPCs with one of these IDs.
Parameters
ids- One or more NPC IDs.
Returns
This query.
withIndex(int)
public NpcQuery withIndex(int index)Filters NPCs by their index.
Parameters
index- The index to filter by.
Returns
NpcQuery.
withinWorldArea(WorldArea)
public NpcQuery withinWorldArea(WorldArea area)Within world area.
Parameters
area- Area.
withName(String)
public NpcQuery withName(String name)Keeps NPCs with this name.
Parameters
name- The NPC's name. Capital letters are ignored; the whole name must match.
Returns
This query.
withName(String)
public AbstractActorQuery withName(String name)Keeps NPCs with this name.
Parameters
name- The NPC's name. Capital letters are ignored; the whole name must match.
Returns
This query.
withNameContains(String)
public NpcQuery withNameContains(String name)Filters NPCs whose names contain the specified substring.
Parameters
name- The substring to filter by.
Returns
The updated NpcQuery instance.
withNameContains(String)
public AbstractActorQuery withNameContains(String name)Filters NPCs whose names contain the specified substring.
Parameters
name- The substring to filter by.
Returns
The updated NpcQuery instance.
withNames(String...)
public NpcQuery withNames(String... names)Keeps NPCs with any of these names.
Parameters
names- NPC names. Capital letters are ignored; the whole name must match.
Returns
This query.
aggregate(Function<Stream<NpcEx>, R>)from AbstractQuery
public R aggregate(Function<Stream<NpcEx>, R> aggregator)Generic aggregation method for custom terminal operations Executes filters and allows custom stream processing.
Parameters
aggregator- Aggregator.
all(Predicate<NpcEx>)from AbstractQuery
public boolean all(Predicate<NpcEx> predicate)Check if all filtered results match the predicate.
Parameters
predicate- Predicate to test.
Returns
True if all match, false otherwise.
any(Predicate<NpcEx>)from AbstractQuery
public boolean any(Predicate<NpcEx> predicate)Check if any filtered result matches the predicate.
Parameters
predicate- Predicate to test.
Returns
True if any match, false otherwise.
collect()from AbstractQuery
public List<NpcEx> collect()Get the filtered/sorted list.
collect(Collector<NpcEx, ?, R>)from AbstractQuery
public R collect(Collector<NpcEx, ?, R> collector)Execute filters and process with custom collector.
Parameters
collector- Collector.
count()from AbstractQuery
public int count()How many results match.
Returns
The number of matches.
distinct()from AbstractQuery
public NpcQuery distinct()Ensure results are distinct.
Returns
The query instance.
first()from AbstractQuery
public NpcEx first()The first match.
The order is the game's own. Use AbstractActorQuery.nearest() for the closest one.
Returns
The first match, or null when nothing matches.
firstIfPresent(Consumer<NpcEx>)from AbstractQuery
public void firstIfPresent(Consumer<NpcEx> action)First if present.
Parameters
action- Action.
firstOrElse(Consumer<NpcEx>, Runnable)from AbstractQuery
public void firstOrElse(Consumer<NpcEx> action, Runnable elseAction)Perform action on the first element, or else run elseAction if no results.
Parameters
action- Action to perform on the first element.
elseAction- Action to perform if no results.
forEach(Consumer<NpcEx>)from AbstractQuery
public void forEach(Consumer<NpcEx> action)Executes filters and performs an action on each result.
Parameters
action- Action.
isEmpty()from AbstractQuery
public boolean isEmpty()Whether nothing matches.
Returns
true when there are no matches.
keepIf(Predicate<NpcEx>)from AbstractQuery
public NpcQuery keepIf(Predicate<NpcEx> predicate)Lazily filter by predicate (keeps matching items).
Parameters
predicate- Predicate.
Returns
The query instance.
last()from AbstractQuery
public NpcEx last()Get the last element from the filtered/sorted list.
lastOrElse(Consumer<NpcEx>, Runnable)from AbstractQuery
public void lastOrElse(Consumer<NpcEx> action, Runnable elseAction)Perform action on the last element, or else run elseAction if no results.
Parameters
action- Action to perform on the last element.
elseAction- Action to perform if no results.
limit(int)from AbstractQuery
public NpcQuery limit(int maxSize)Limit the number of results.
Parameters
maxSize- Max size.
Returns
The query instance.
none(Predicate<NpcEx>)from AbstractQuery
public boolean none(Predicate<NpcEx> predicate)Check if no filtered results match the predicate.
Parameters
predicate- Predicate to test.
Returns
True if none match, false otherwise.
peek(Consumer<NpcEx>)from AbstractQuery
public NpcQuery peek(Consumer<NpcEx> action)Peek at each element during processing.
Parameters
action- Action to perform on each element.
Returns
The query instance.
postProcess(Function<List<NpcEx>, List<NpcEx>>)from AbstractQuery
public NpcQuery postProcess(Function<List<NpcEx>, List<NpcEx>> processor)Apply a post-processing function after sorting.
Useful for reordering algorithms that can't be expressed as Comparators.
Parameters
processor- Function to transform the result list.
Returns
The query instance.
random()from AbstractQuery
public NpcEx random()Get a random element from the filtered/sorted list.
removeIf(Predicate<NpcEx>)from AbstractQuery
public NpcQuery removeIf(Predicate<NpcEx> predicate)Lazily filter by predicate (removes matching items).
Parameters
predicate- Predicate.
Returns
The query instance.
skip(int)from AbstractQuery
public NpcQuery skip(int count)Skip a number of results.
Parameters
count- Count.
Returns
The query instance.
sort(Comparator<NpcEx>)from AbstractQuery
public NpcQuery sort(Comparator<NpcEx> comparator)Lazily add sorting.
Parameters
comparator- Comparator.
Returns
The query instance.
atLocation(WorldPoint)from AbstractActorQuery
public NpcQuery atLocation(WorldPoint location)Filter by exact location.
Parameters
location- Location.
Returns
ActorQuery.
canAttack()from AbstractActorQuery
public NpcQuery canAttack()Filter to npcs the player can attack.
Returns
ActorQuery.
farthest()from AbstractActorQuery
public NpcEx farthest()Get the farthest Actor from the filtered list Terminal operation - executes the query.
farthest(WorldPoint)from AbstractActorQuery
public NpcEx farthest(WorldPoint center)Get the farthest Actor from a specific point Terminal operation - executes the query.
Parameters
center- Center.
free()from AbstractActorQuery
public NpcQuery free()Filter actors that are already interacting.
Returns
ActorQuery.
hasLos()from AbstractActorQuery
public NpcQuery hasLos()Filter actors that the player has line of sight to.
Returns
ActorQuery.
interactingWith(ActorEx<?>)from AbstractActorQuery
public NpcQuery interactingWith(ActorEx<?> target)Filter actors that are currently interacting with a specific target actor.
Parameters
target- Actor.
Returns
ActorQuery.
isReachable()from AbstractActorQuery
public NpcQuery isReachable()Filter reachable actors.
Returns
ActorQuery.
longestPath()from AbstractActorQuery
public NpcEx longestPath()Get the Actor with the furthest path from the filtered list Terminal operation - executes the query.
nearest()from AbstractActorQuery
public NpcEx nearest()The match closest to you.
Measures the straight line on the map, ignoring planes.
Returns
The nearest match, or null when nothing matches.
- Call it while you are logged in.
nearest(WorldPoint)from AbstractActorQuery
public NpcEx nearest(WorldPoint center)The match closest to a point.
Measures the straight line on the map, ignoring planes.
Parameters
center- The point to measure from.
Returns
The nearest match, or null when nothing matches.
shortestPath()from AbstractActorQuery
public NpcEx shortestPath()Get the Actor with the shortest path from the filtered list Terminal operation - executes the query.
sortFurthest()from AbstractActorQuery
public NpcQuery sortFurthest()Sort by furthest from the player.
Returns
ActorQuery.
sortFurthest(WorldPoint)from AbstractActorQuery
public NpcQuery sortFurthest(WorldPoint center)Sort by furthest from a specific point.
Parameters
center- Center point.
Returns
ActorQuery.
sortLongestPath()from AbstractActorQuery
public NpcQuery sortLongestPath()Sort by furthest path from the player.
Returns
ActorQuery.
sortLongestPath(WorldPoint)from AbstractActorQuery
public NpcQuery sortLongestPath(WorldPoint center)Sort by furthest path from a specific point.
Parameters
center- Center point.
Returns
ActorQuery.
sortNearest()from AbstractActorQuery
public NpcQuery sortNearest()Sort by nearest to the player.
Returns
ActorQuery.
sortNearest(WorldPoint)from AbstractActorQuery
public NpcQuery sortNearest(WorldPoint center)Sort by nearest to a specific point.
Parameters
center- Center point.
Returns
ActorQuery.
sortShortestPath()from AbstractActorQuery
public NpcQuery sortShortestPath()Sort by shortest path from the player.
Returns
ActorQuery.
sortShortestPath(WorldPoint)from AbstractActorQuery
public NpcQuery sortShortestPath(WorldPoint center)Sort by shortest path from a specific point.
Parameters
center- Center point.
Returns
ActorQuery.
within(int)from AbstractActorQuery
public NpcQuery within(int distance)Keeps matches within this many tiles of you.
Counts tiles in a square around you, so a diagonal step is one tile.
Parameters
distance- The largest distance in tiles.
Returns
This query.
- Call it while you are logged in.
within(WorldPoint, int)from AbstractActorQuery
public NpcQuery within(WorldPoint center, int distance)Keeps matches within this many tiles of a point.
Counts tiles in a square around the point, so a diagonal step is one tile.
Parameters
center- The point to measure from.
distance- The largest distance in tiles.
Returns
This query.
Also allowed
Every class has these, as in plain Java.
equals, toString