Package wbs.utils.util.entities.selector
Class EntitySelector<T extends org.bukkit.entity.Entity,E extends EntitySelector<T,E>>
java.lang.Object
wbs.utils.util.entities.selector.EntitySelector<T,E>
- Type Parameters:
T- The subclass of entity to selectE- The class of an implementing type, for ease of use in end point methods.
- Direct Known Subclasses:
LineOfSightSelector,RadiusSelector
public abstract class EntitySelector<T extends org.bukkit.entity.Entity,E extends EntitySelector<T,E>>
extends Object
A helper class for selecting an entity or collection of entities in a variety of controllable ways.
Designed to replace the many selection methods in the now deprecated
Designed to replace the many selection methods in the now deprecated
WbsEntities.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Eexclude(Collection<T> toAdd) final Efilter(Collection<U> collection) A utility method for use in implementations, that filters the given collection againstEntitySelectorto ensure all instances are of type T (or removed otherwise)final intThe current entity predicate.final doublegetRange()protected @NotNull Predicate<org.bukkit.entity.Entity>getSelection(org.bukkit.Location loc) Perform a selection and return all found.protected abstract EgetThis()protected booleanselect(org.bukkit.entity.Entity entity) Selects all entities of the given type, limited tomaxSelections.select(org.bukkit.Location loc) Selects all entities of the given type, limited tomaxSelections.selectExcluding(org.bukkit.Location loc, T entity) Selects all entities of the given type, limited tomaxSelections, excluding the given entityselectExcluding(T entity) Selects all entities of the given type, limited tomaxSelections, excluding the given entityfinal TselectFirst(org.bukkit.entity.Entity entity) Select only the first found selectable entity.final TselectFirst(org.bukkit.Location loc) Select only the first found selectable entityfinal TselectFirstExcluding(org.bukkit.Location loc, T entity) Select only the first found selectable entity, excluding the provided one.final TselectFirstExcluding(T entity) Select only the first found selectable entity, excluding the provided one.final TselectRandom(org.bukkit.entity.Entity entity) Select a single random selectable entity To ignore the provided entity, useselectRandomExcluding(Entity)instead.final TselectRandom(org.bukkit.Location loc) Select a single random selectable entityfinal TselectRandomExcluding(org.bukkit.Location loc, T entity) Select only the first found selectable entity, excluding the provided one.final TselectRandomExcluding(T entity) Select only the first found selectable entity, excluding the provided one.final EsetMaxSelections(int maxSelections) final EsetPredicate(Predicate<T> predicate) final EsetPredicateRaw(Predicate<org.bukkit.entity.Entity> predicate) final EsetRange(double range) final booleanunexclude(Collection<T> toRemove) final boolean
-
Field Details
-
clazz
The subclass to be selected -
range
protected double rangeThe range the selector will search in.
-
-
Constructor Details
-
EntitySelector
- Parameters:
clazz- The subclass to be selected
-
-
Method Details
-
getSelection
Perform a selection and return all found.- Parameters:
loc- The location to perform the selection from- Returns:
- All selections
-
getThis
- Returns:
- This object as the subclass
-
select
Selects all entities of the given type, limited tomaxSelections.- Parameters:
loc- The location to perform the selection from- Returns:
- An ordered selection, limited to
maxSelectionsentities.
-
select
Selects all entities of the given type, limited tomaxSelections.- Parameters:
entity- The entity whose location will be used to perform the selection.- Returns:
- An ordered selection, limited to
maxSelectionsentities.
-
selectExcluding
Selects all entities of the given type, limited tomaxSelections, excluding the given entity- Parameters:
entity- The entity whose location will be used to perform the selection.- Returns:
- The first found entity, or null if none were found.
-
selectExcluding
Selects all entities of the given type, limited tomaxSelections, excluding the given entity- Parameters:
loc- The location to perform the selection fromentity- The entity to exclude from this operation only- Returns:
- The first found entity, or null if none were found.
-
selectFirst
Select only the first found selectable entity- Parameters:
loc- The location to perform the selection from- Returns:
- The first found entity, or null if none were found.
-
selectFirst
Select only the first found selectable entity. To ignore the provided entity, useselectFirstExcluding(Entity)instead.- Parameters:
entity- The entity whose location will be used to perform the selection.- Returns:
- The first found entity, or null if none were found.
-
selectFirstExcluding
Select only the first found selectable entity, excluding the provided one.- Parameters:
entity- The entity whose location will be used to perform the selection.- Returns:
- The first found entity, or null if none were found.
-
selectFirstExcluding
Select only the first found selectable entity, excluding the provided one.- Parameters:
loc- The location to perform the selection fromentity- The entity to exclude from this operation only- Returns:
- The first found entity, or null if none were found.
-
selectRandom
Select a single random selectable entity- Parameters:
loc- The location to perform the selection from- Returns:
- A random found entity, or null if none were found.
-
selectRandom
Select a single random selectable entity To ignore the provided entity, useselectRandomExcluding(Entity)instead.- Parameters:
entity- The entity whose location will be used to perform the selection.- Returns:
- A random found entity, or null if none were found.
-
selectRandomExcluding
Select only the first found selectable entity, excluding the provided one.- Parameters:
entity- The entity whose location will be used to perform the selection.- Returns:
- A random found entity, or null if none were found.
-
selectRandomExcluding
Select only the first found selectable entity, excluding the provided one.- Parameters:
loc- The location to perform the selection fromentity- The entity to exclude from this operation only- Returns:
- A random found entity, or null if none were found.
-
filter
A utility method for use in implementations, that filters the given collection againstEntitySelectorto ensure all instances are of type T (or removed otherwise)- Type Parameters:
U- Some extension ofEntity- Parameters:
collection- The collection of entities to filter- Returns:
- The filtered collection as a Set of T.
-
getRawPredicate
- Returns:
- A new predicate against Entity that returns true if:
- The entity is of type
EntitySelector; - The entity is not in the exclusion list as defined by
exclude(Collection); and - The custom predicate returns true, as defined by
setPredicate(Predicate)
- The entity is of type
-
isValid
- Parameters:
entity- The entity to test.- Returns:
- true if the entity is not excluded, and the custom predicate passes.
-
getRange
public final double getRange()- Returns:
- Gets the current range of selection
-
setRange
- Parameters:
range- The range of selection- Returns:
- The same object.
-
getMaxSelections
public final int getMaxSelections()- Returns:
- The maximum number of entities to find in a given
select(Location).
-
setMaxSelections
- Parameters:
maxSelections- The maximum number of entities to find in a givenselect(Location).- Returns:
- The same object.
-
getPredicate
The current entity predicate.- Returns:
- The same object.
-
setPredicate
- Parameters:
predicate- The new predicate- Returns:
- The same object.
-
setPredicateRaw
- Parameters:
predicate- The new predicate, which will also require a test for being an instance of T.- Returns:
- The same object.
-
getExclude
- Returns:
- Gets the set of currently excluded entities
-
exclude
- Parameters:
toAdd- The entity to exclude- Returns:
- The same object.
-
exclude
- Parameters:
toAdd- The entities to exclude- Returns:
- The same object.
-
unexclude
- Parameters:
toRemove- The entity to remove from the exclusion set, to allow it to be selected- Returns:
- The same object.
-
unexclude
- Parameters:
toRemove- The entities to remove from the exclusion set, to allow it to be selected- Returns:
- The same object.
-