Paper/patches/api/0391-Add-LivingEntity-swingHand-EquipmentSlot-convenience.patch
Nassim Jahnke 2cd29ddbb5
API 'done'
2023-03-14 18:21:11 +01:00

35 lines
1.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: SoSeDiK <mrsosedik@gmail.com>
Date: Tue, 11 Oct 2022 22:35:56 +0300
Subject: [PATCH] Add LivingEntity#swingHand(EquipmentSlot) convenience method
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 27187efdbcf1cf20a53175f1177c16dc40acab3c..aa2c3c4648844908b2699f6f220393f98836ed5d 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -1052,5 +1052,23 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
* @param hurtDirection hurt direction
*/
void setHurtDirection(float hurtDirection);
+
+ /**
+ * Makes this entity swing their hand.
+ *
+ * <p>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
}