Class EntityUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatLocation(org.bukkit.Location loc) Formats aLocationobject into a readable string containing the world name and coordinates.
Example output:world (100.00, 64.00, 200.00)static StringformatLocation(org.bukkit.Location loc, String format) Formats aLocationobject into a string based on the given format.static List<org.bukkit.Location> generateSafeCircularSpawnLocations(org.bukkit.Location location, int amount, double radius) Generates safe spawn locations arranged in a circle around a given origin location.static doublegetAttackSpeed(org.bukkit.entity.Mob mob) Returns the weapon attack speed for aMobby inspecting the attribute modifiers on its main-handItemStack.static doublegetDamage(org.bukkit.entity.Mob mob) Returns the weapon attack damage for aMobby inspecting the attribute modifiers on its main-handItemStack.static org.bukkit.LocationgetEntityCenter(org.bukkit.entity.Entity entity) Get the center location of an entity's bounding box.static doublegetHealthPercentage(org.bukkit.entity.LivingEntity entity) Calculate the current health percentage of a living entity.static org.bukkit.entity.PlayergetNearestPlayer(org.bukkit.entity.LivingEntity entity) Finds the nearest player to the given rare entity.static IntegergetNearestPlayerDistance(org.bukkit.entity.LivingEntity entity) Gets the distance to the nearest player from the given rare entity.static List<org.bukkit.entity.Player> getPlayersInRadius(org.bukkit.entity.LivingEntity entity, double radius) Get a list of players within a specific radius around a living entity.static booleanisExposedToSunlight(org.bukkit.entity.Entity entity) Check if an entity is exposed to direct sunlight.static booleanisLocationSafe(org.bukkit.Location location) Checks if the location is safe (not inside a solid block).
-
Constructor Details
-
EntityUtils
public EntityUtils()
-
-
Method Details
-
getPlayersInRadius
public static List<org.bukkit.entity.Player> getPlayersInRadius(org.bukkit.entity.LivingEntity entity, double radius) Get a list of players within a specific radius around a living entity.- Parameters:
entity- The entity around which to search for players.radius- The radius within which to search for players.- Returns:
- A list of players within the specified radius.
-
getHealthPercentage
public static double getHealthPercentage(org.bukkit.entity.LivingEntity entity) Calculate the current health percentage of a living entity.- Parameters:
entity- The entity whose health percentage is to be calculated.- Returns:
- The health percentage (0-100) of the entity.
-
isExposedToSunlight
public static boolean isExposedToSunlight(org.bukkit.entity.Entity entity) Check if an entity is exposed to direct sunlight.This checks if the entity's current Y position is greater than or equal to the highest block at its X and Z coordinates.
- Parameters:
entity- The entity to check.- Returns:
trueif the entity is exposed to sunlight,falseotherwise.
-
getEntityCenter
public static org.bukkit.Location getEntityCenter(org.bukkit.entity.Entity entity) Get the center location of an entity's bounding box.This method calculates the midpoint of the entity's bounding box in all three dimensions. Useful for effects or precise positioning relative to the entity.
- Parameters:
entity- The entity whose center location is to be calculated.- Returns:
- The
Locationrepresenting the center of the entity's bounding box.
-
generateSafeCircularSpawnLocations
public static List<org.bukkit.Location> generateSafeCircularSpawnLocations(org.bukkit.Location location, int amount, double radius) Generates safe spawn locations arranged in a circle around a given origin location. Ensures each spawn point is not inside a solid block; otherwise, falls back to the origin.- Parameters:
location- The center/origin location to spawn around.amount- Number of spawn points to generate.radius- The radius of the circle.- Returns:
- List of safe spawn locations.
-
isLocationSafe
public static boolean isLocationSafe(org.bukkit.Location location) Checks if the location is safe (not inside a solid block).- Parameters:
location- The location to check.- Returns:
- True if the location is safe, false otherwise.
-
formatLocation
Formats aLocationobject into a readable string containing the world name and coordinates.
Example output:world (100.00, 64.00, 200.00)- Parameters:
loc- the location to format- Returns:
- a formatted string in the form
"world (x, y, z)", with coordinates rounded to two decimals
-
formatLocation
Formats aLocationobject into a string based on the given format.The format string can include the following placeholders:
%w- Replaced with the world's name%x- Replaced with the X coordinate%y- Replaced with the Y coordinate%z- Replaced with the Z coordinate
"%w - %x %y %z"→world - 100.0 64.0 200.0- Parameters:
loc- the location to formatformat- the format string containing placeholders- Returns:
- a string with placeholders replaced by location values
-
getDamage
public static double getDamage(org.bukkit.entity.Mob mob) Returns the weapon attack damage for aMobby inspecting the attribute modifiers on its main-handItemStack.Looks up Attribute.ATTACK_DAMAGE and, for version compatibility, falls back to Attribute.GENERIC_ATTACK_DAMAGE. If the item has multiple matching modifiers, the first one encountered is used. If the mob holds no item or the item has no relevant modifiers, this method returns
3.0.Note: This reads only the item's attribute modifiers; it does not combine with the mob's base attributes, enchantments, or effects.
- Parameters:
mob- the mob whose main-hand weapon is inspected- Returns:
- the attack damage value from the weapon's attribute modifiers, or 3.0 if unavailable
-
getAttackSpeed
public static double getAttackSpeed(org.bukkit.entity.Mob mob) Returns the weapon attack speed for aMobby inspecting the attribute modifiers on its main-handItemStack.Looks up Attribute.ATTACK_SPEED and, for version compatibility, falls back to Attribute.GENERIC_ATTACK_SPEED. If multiple matching modifiers exist, the first one encountered is used. If absent, this method returns
1.0.Note: Only item attribute modifiers are considered; this does not account for the mob's base attributes or temporary effects.
- Parameters:
mob- the mob whose main-hand weapon is inspected- Returns:
- the attack speed value from the weapon's attribute modifiers, or 1.0 if unavailable
-
getNearestPlayer
public static org.bukkit.entity.Player getNearestPlayer(org.bukkit.entity.LivingEntity entity) Finds the nearest player to the given rare entity.- Parameters:
entity- The rare entity to check from.- Returns:
- The nearest Player, or null if none found.
-
getNearestPlayerDistance
Gets the distance to the nearest player from the given rare entity.- Parameters:
entity- The rare entity to check from.- Returns:
- The distance to the nearest player as an integer, or Integer.MAX_VALUE if none found.
-