Class EntityUtils

java.lang.Object
net.paulem.arcana.utils.EntityUtils

public class EntityUtils extends Object
Utility methods for working with entities, such as finding nearby entities, checking line-of-sight, and teleporting to the ground.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static List<org.bukkit.entity.LivingEntity>
    getEntitiesTargeting(@NotNull org.bukkit.entity.Player player, double dist)
    Finds all living entities within dist blocks of player that the player is currently looking at.
    static <T extends org.bukkit.entity.Entity>
    T
    getNearestEntity(@NotNull org.bukkit.entity.Entity entity, double dist, Class<T> filterClass)
    Finds the closest entity of type filterClass to entity within dist blocks.
    static boolean
    isLookingAt(org.bukkit.entity.Player player, org.bukkit.entity.LivingEntity livingEntity)
    Checks whether player is looking at livingEntity.
    static void
    tpToGround(@NotNull org.bukkit.entity.Entity entity)
    Teleports the given entity down to the ground below its current location.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 type filterClass to entity within dist blocks. 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 around
      dist - the search radius, in blocks, on each axis
      filterClass - the type of entity to look for
      Returns:
      the nearest matching entity, or null if 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 within dist blocks of player that the player is currently looking at.
      Parameters:
      player - the player whose look direction is checked
      dist - 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 whether player is looking at livingEntity. 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 checked
      livingEntity - the entity to check
      Returns:
      true if the player is looking at the entity, false otherwise
    • 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