From e7b3fba8e659cdaf1c83b0da2a395dc1c6667888 Mon Sep 17 00:00:00 2001 From: SoSeDiK Date: Sun, 23 Oct 2022 02:50:12 +0300 Subject: [PATCH] Add EquipmentSlot convenience methods (#8477) --- ...dd-EquipmentSlot-convenience-methods.patch | 39 +++++++++++++++++++ ...-swingHand-EquipmentSlot-convenience.patch | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 patches/api/Add-EquipmentSlot-convenience-methods.patch diff --git a/patches/api/Add-EquipmentSlot-convenience-methods.patch b/patches/api/Add-EquipmentSlot-convenience-methods.patch new file mode 100644 index 0000000000..e7df2449eb --- /dev/null +++ b/patches/api/Add-EquipmentSlot-convenience-methods.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: SoSeDiK +Date: Sun, 16 Oct 2022 15:28:49 +0300 +Subject: [PATCH] Add EquipmentSlot convenience methods + + +diff --git a/src/main/java/org/bukkit/inventory/EquipmentSlot.java b/src/main/java/org/bukkit/inventory/EquipmentSlot.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/inventory/EquipmentSlot.java ++++ b/src/main/java/org/bukkit/inventory/EquipmentSlot.java +@@ -0,0 +0,0 @@ public enum EquipmentSlot { + LEGS, + CHEST, + HEAD ++ // Paper start ++ ; ++ /** ++ * Checks whether this equipment slot is a hand: ++ * either {@link #HAND} or {@link #OFF_HAND} ++ * ++ * @return whether this is a hand slot ++ */ ++ public boolean isHand() { ++ return this == HAND || this == OFF_HAND; ++ } ++ ++ /** ++ * Checks whether this equipment slot ++ * is one of the armor slots: ++ * {@link #HEAD}, {@link #CHEST}, ++ * {@link #LEGS}, or {@link #FEET} ++ * ++ * @return whether this is an armor slot ++ */ ++ public boolean isArmor() { ++ return this == HEAD || this == CHEST || this == LEGS || this == FEET; ++ } ++ // Paper end + } diff --git a/patches/api/Add-LivingEntity-swingHand-EquipmentSlot-convenience.patch b/patches/api/Add-LivingEntity-swingHand-EquipmentSlot-convenience.patch index e37fb4f1db..fc0d7814eb 100644 --- a/patches/api/Add-LivingEntity-swingHand-EquipmentSlot-convenience.patch +++ b/patches/api/Add-LivingEntity-swingHand-EquipmentSlot-convenience.patch @@ -23,7 +23,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @throws IllegalArgumentException if invalid hand is passed + */ + default void swingHand(@NotNull org.bukkit.inventory.EquipmentSlot hand) { -+ com.google.common.base.Preconditions.checkArgument(hand == org.bukkit.inventory.EquipmentSlot.HAND || hand == org.bukkit.inventory.EquipmentSlot.OFF_HAND, String.format("Expected a valid hand, got \"%s\" instead!", 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 {