Paper/patches/api/0390-Add-LivingEntity-swingHand-EquipmentSlot-convenience.patch
Jake Potrebic 5730a94208
Updated Upstream (Bukkit/CraftBukkit) (#8991)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
2b4582fb SPIGOT-5916: getLastColors does not work with the rgb colors

CraftBukkit Changes:
f7707086d SPIGOT-7299: Fix indirect/anvil damage events and minor improvements
2023-03-18 10:05:04 -07:00

35 lines
1.5 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 4febec3623b936cf40daba6196392ebce4b8d5a8..c689003cbec3936a8e02829f0fdfa0e7989df6ee 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -1054,5 +1054,23 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
*/
@Deprecated
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
}