From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sun, 25 Aug 2019 00:09:52 -0500
Subject: [PATCH] Dispenser curse of binding protection


diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
index 566d6a2551ffbcf4366596cab87a7239a75156c6..9807441d53fcf4ef7aaffe3801542f5a371eb7af 100644
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -996,6 +996,13 @@ public abstract class EntityInsentient extends EntityLiving {
 
     }
 
+    // Purpur start
+    public static EnumItemSlot getSlotForDispenser(ItemStack itemstack) {
+        return EnchantmentManager.getEnchantmentLevel(Enchantments.BINDING_CURSE, itemstack) > 0 ? EnumItemSlot.MAINHAND : getSlotForItemStack(itemstack);
+    }
+    // Purpur end
+
+    public static EnumItemSlot getSlotForItemStack(ItemStack itemstack) { return j(itemstack); } // Purpur - OBFHELPER
     public static EnumItemSlot j(ItemStack itemstack) {
         Item item = itemstack.getItem();
 
diff --git a/src/main/java/net/minecraft/server/ItemArmor.java b/src/main/java/net/minecraft/server/ItemArmor.java
index 669a5041184846ca8430a7f0d3197025fe6d437e..7cd2e871b5a429a86dbc3c4208d247a4246ea1a8 100644
--- a/src/main/java/net/minecraft/server/ItemArmor.java
+++ b/src/main/java/net/minecraft/server/ItemArmor.java
@@ -35,7 +35,7 @@ public class ItemArmor extends Item implements ItemWearable {
             return false;
         } else {
             EntityLiving entityliving = (EntityLiving) list.get(0);
-            EnumItemSlot enumitemslot = EntityInsentient.j(itemstack);
+            EnumItemSlot enumitemslot = isourceblock.getWorld().purpurConfig.dispenserApplyCursedArmor ? EntityInsentient.getSlotForItemStack(itemstack) : EntityInsentient.getSlotForDispenser(itemstack); // Purpur
             ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
             // CraftBukkit start
             World world = isourceblock.getWorld();
@@ -94,6 +94,7 @@ public class ItemArmor extends Item implements ItemWearable {
         this.m = builder.build();
     }
 
+    public EnumItemSlot getEquipmentSlot() { return b(); } // Purpur - OBFHELPER
     public EnumItemSlot b() {
         return this.b;
     }
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 4d34957c6255af571e593e015fa9dcafa733aceb..26df95f502d117398c7c9c65b298b97b62021700 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -162,6 +162,11 @@ public class PurpurWorldConfig {
         });
     }
 
+    public boolean dispenserApplyCursedArmor = true;
+    private void dispenserSettings() {
+        dispenserApplyCursedArmor = getBoolean("blocks.dispenser.apply-cursed-to-armor-slots", dispenserApplyCursedArmor);
+    }
+
     public boolean farmlandGetsMoistFromBelow = false;
     private void farmlandSettings() {
         farmlandGetsMoistFromBelow = getBoolean("blocks.farmland.gets-moist-from-below", farmlandGetsMoistFromBelow);
