aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0376-Add-EquipmentSlot-convenience-methods.patch
blob: 14a97a21b4d0f6f8a7c8e7457b7c375078e2f77b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: SoSeDiK <mrsosedik@gmail.com>
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 5642d8af60b6649497aba9b0f6ab7bba7702b9ee..a10d56b797e58b56bd4cef6de40691f7eac9b5b1 100644
--- a/src/main/java/org/bukkit/inventory/EquipmentSlot.java
+++ b/src/main/java/org/bukkit/inventory/EquipmentSlot.java
@@ -33,4 +33,42 @@ public enum EquipmentSlot {
     public EquipmentSlotGroup getGroup() {
         return group.get();
     }
+    // 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;
+    }
+
+    /**
+     * Gets the opposite hand
+     *
+     * @return the opposite hand
+     * @throws IllegalArgumentException if this equipment slot is not a hand
+     * @see #isHand()
+     */
+    public @NotNull EquipmentSlot getOppositeHand() {
+        return switch (this) {
+            case HAND -> OFF_HAND;
+            case OFF_HAND -> HAND;
+            default -> throw new IllegalArgumentException("Unable to determine an opposite hand for equipment slot: " + name());
+        };
+    }
+
+    /**
+     * Checks whether this equipment slot
+     * is one of the armor slots:
+     * {@link #HEAD}, {@link #CHEST},
+     * {@link #LEGS}, {@link #FEET}, or {@link #BODY}
+     *
+     * @return whether this is an armor slot
+     */
+    public boolean isArmor() {
+        return this == HEAD || this == CHEST || this == LEGS || this == FEET || this == BODY;
+    }
+    // Paper end
 }