Package net.paulem.arcana.utils
Class EntityUtils
java.lang.Object
net.paulem.arcana.utils.EntityUtils
Utility methods for working with entities, such as finding nearby entities,
checking line-of-sight, and teleporting to the ground.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.LocationgetBottomGround(org.bukkit.Location location) Finds the location of the first solid ground below the given location, scanning downward from its current Y position to the world's minimum height.static List<org.bukkit.entity.LivingEntity> getEntitiesTargeting(@NotNull org.bukkit.entity.Player player, double dist) Finds all living entities withindistblocks ofplayerthat the player is currently looking at.static <T extends org.bukkit.entity.Entity>
TgetNearestEntity(@NotNull org.bukkit.entity.Entity entity, double dist, Class<T> filterClass) Finds the closest entity of typefilterClasstoentitywithindistblocks.static booleanisLookingAt(org.bukkit.entity.Player player, org.bukkit.entity.LivingEntity livingEntity) Checks whetherplayeris looking atlivingEntity.static voidtpToGround(@NotNull org.bukkit.entity.Entity entity) Teleports the given entity down to the ground below its current location.
-
Constructor Details
-
EntityUtils
public EntityUtils()
-
-
Method Details
-
getNearestEntity
@Nullable public static <T extends org.bukkit.entity.Entity> T getNearestEntity(@NotNull @NotNull org.bukkit.entity.Entity entity, double dist, Class<T> filterClass) Finds the closest entity of typefilterClasstoentitywithindistblocks. The entity itself is never returned as its own nearest entity.- Type Parameters:
T- the type of entity to look for- Parameters:
entity- the entity to search arounddist- the search radius, in blocks, on each axisfilterClass- the type of entity to look for- Returns:
- the nearest matching entity, or
nullif none was found
-
getEntitiesTargeting
public static List<org.bukkit.entity.LivingEntity> getEntitiesTargeting(@NotNull @NotNull org.bukkit.entity.Player player, double dist) Finds all living entities withindistblocks ofplayerthat the player is currently looking at.- Parameters:
player- the player whose look direction is checkeddist- the search radius, in blocks, on each axis- Returns:
- the list of living entities the player is looking at
-
isLookingAt
public static boolean isLookingAt(org.bukkit.entity.Player player, org.bukkit.entity.LivingEntity livingEntity) Checks whetherplayeris looking atlivingEntity. The direction from the player's eye to the entity is compared to the player's look direction using a dot product; the resulting angle is then compared to the angular size that the entity's bounding box occupies at that distance, so that larger or closer entities are easier to be looking at. An entity occupying the exact same position as the player's eye is always considered looked at.- Parameters:
player- the player whose look direction is checkedlivingEntity- the entity to check- Returns:
trueif the player is looking at the entity,falseotherwise
-
tpToGround
public static void tpToGround(@NotNull @NotNull org.bukkit.entity.Entity entity) Teleports the given entity down to the ground below its current location.- Parameters:
entity- the entity to teleport
-
getBottomGround
public static org.bukkit.Location getBottomGround(org.bukkit.Location location) Finds the location of the first solid ground below the given location, scanning downward from its current Y position to the world's minimum height. If no solid block is found, the world's highest block at that column is used instead.- Parameters:
location- the location to scan downward from- Returns:
- the location just above the first solid block found below
location
-