Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,18 @@ final class Holder {
@Nullable
public EntityDamageEvent getLastDamageCause();

/**
* Gets the item being used as a weapon by this entity.
* <p>
* Note: In most cases this is the item in the entity's main hand, but
* it may be the offhand if for ex: the entity is using the riptide
* enchantment on a trident.
*
* @return The weapon item
*/
@NotNull
ItemStack getWeaponItem();

/**
* Returns a unique and persistent id for this entity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
import org.bukkit.craftbukkit.util.CraftChatMessage;
Expand Down Expand Up @@ -567,6 +568,12 @@ public EntityDamageEvent getLastDamageCause() {
return this.lastDamageEvent;
}

@Override
public @NotNull ItemStack getWeaponItem() {
net.minecraft.world.item.ItemStack stack = this.getHandle().getWeaponItem();
return stack == null ? ItemStack.empty() : stack.asBukkitCopy();
}

@Override
public UUID getUniqueId() {
return this.entity.getUUID();
Expand Down
Loading