Skip to content
Hxncus edited this page Jan 15, 2025 · 3 revisions

EntityUtil

EntityUtil is a utility class for interacting with entities, attributes, and other common tasks in Minecraft plugin development.


Methods

ItemStack getBowFromArrow(Arrow arrow)

Gets the bow from which the arrow was shot.
Returns: The ItemStack representing the bow, or null if unavailable.


double getAttribute(LivingEntity entity, Attribute attribute)

Gets the current value of an attribute for a given entity.
Returns: The value of the attribute, or 0.0 if the attribute is not present.


double getAttributeBase(LivingEntity entity, Attribute attribute)

Gets the base value of an attribute for a given entity.
Returns: The base value of the attribute, or 0.0 if the attribute is not present.


boolean isUnderWater(Entity entity)

Checks if the entity is underwater.
Returns: true if the entity is underwater, otherwise false.


boolean isFixed(ItemDisplay itemDisplay)

Checks if the ItemDisplay has its transform set to FIXED.
Returns: true if the transform is FIXED, otherwise false.


boolean isNone(ItemDisplay itemDisplay)

Checks if the ItemDisplay has its transform set to NONE.
Returns: true if the transform is NONE, otherwise false.


void teleport(Location location, Entity entity, PlayerTeleportEvent.TeleportCause cause)

Teleports an entity to a specified location with a given cause.


void teleport(Location location, Entity entity)

Teleports an entity to a specified location using PLUGIN as the teleportation cause.


Notes

  • Methods like isUnderWater and teleport adapt to server types and versions (e.g., Paper, Folia).
  • Version-specific logic ensures compatibility with Minecraft 1.19+.
  • The utility class focuses on simplifying repetitive tasks.

Examples

// Example: Retrieve the bow used to shoot an arrow
Arrow arrow = ...; // An arrow instance
ItemStack bow = EntityUtil.getBowFromArrow(arrow);

if (bow != null) {
    System.out.println("Bow retrieved: " + bow);
}

// Example: Teleport an entity to a new location
Location destination = new Location(world, 100, 65, 200);
EntityUtil.teleport(destination, entity);