Paper/Spigot-Server-Patches/0072-Access-items-by-EquipmentSlot.patch
2019-05-05 19:58:04 -07:00

69 lines
2.3 KiB
Diff

From 8c74d27fd8b984b8301ef5712a94a74d5733a0ad Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
Date: Sun, 20 Mar 2016 06:45:01 -0400
Subject: [PATCH] Access items by EquipmentSlot
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
index 5873b76236..ef4cd7a7b6 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
@@ -268,4 +268,54 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
public void setBootsDropChance(float chance) {
throw new UnsupportedOperationException("Cannot set drop chance for PlayerInventory");
}
+
+ // Paper start
+ @Override
+ public ItemStack getItem(org.bukkit.inventory.EquipmentSlot slot) {
+ Preconditions.checkNotNull(slot, "slot");
+ switch (slot) {
+ case HAND:
+ return this.getItemInMainHand();
+ case OFF_HAND:
+ return this.getItemInOffHand();
+ case HEAD:
+ return this.getHelmet();
+ case CHEST:
+ return this.getChestplate();
+ case LEGS:
+ return this.getLeggings();
+ case FEET:
+ return this.getBoots();
+ }
+
+ throw new UnsupportedOperationException(slot.name());
+ }
+
+ @Override
+ public void setItem(org.bukkit.inventory.EquipmentSlot slot, ItemStack stack) {
+ Preconditions.checkNotNull(slot, "slot");
+ switch (slot) {
+ case HAND:
+ this.setItemInMainHand(stack);
+ return;
+ case OFF_HAND:
+ this.setItemInOffHand(stack);
+ return;
+ case HEAD:
+ this.setHelmet(stack);
+ return;
+ case CHEST:
+ this.setChestplate(stack);
+ return;
+ case LEGS:
+ this.setLeggings(stack);
+ return;
+ case FEET:
+ this.setBoots(stack);
+ return;
+ }
+
+ throw new UnsupportedOperationException(slot.name());
+ }
+ // Paper end
}
--
2.21.0