From 79cb2d4685c49045026c35b9950777145a385274 Mon Sep 17 00:00:00 2001 From: SoSeDiK Date: Tue, 11 Oct 2022 22:35:56 +0300 Subject: [PATCH] Add LivingEntity#swingHand(EquipmentSlot) convenience method --- .../java/org/bukkit/entity/LivingEntity.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java b/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java index 292b8d0370..be91821c47 100644 --- a/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java +++ b/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java @@ -1341,4 +1341,24 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource @Deprecated void setHurtDirection(float hurtDirection); // Paper end - hurt direction API + + // Paper start - swing hand API + /** + * Makes this entity swing their hand. + * + *

This method does nothing if this entity does not + * have an animation for swinging their hand. + * + * @param hand hand to be swung, either {@link org.bukkit.inventory.EquipmentSlot#HAND} or {@link org.bukkit.inventory.EquipmentSlot#OFF_HAND} + * @throws IllegalArgumentException if invalid hand is passed + */ + default void swingHand(@NotNull org.bukkit.inventory.EquipmentSlot hand) { + com.google.common.base.Preconditions.checkArgument(hand != null && hand.isHand(), String.format("Expected a valid hand, got \"%s\" instead!", hand)); + if (hand == org.bukkit.inventory.EquipmentSlot.HAND) { + this.swingMainHand(); + } else { + this.swingOffHand(); + } + } + // Paper end - swing hand API }