--- a/net/minecraft/world/item/ItemArmor.java +++ b/net/minecraft/world/item/ItemArmor.java @@ -27,6 +27,11 @@ import net.minecraft.world.level.block.BlockDispenser; import net.minecraft.world.phys.AxisAlignedBB; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockDispenseArmorEvent; +// CraftBukkit end + public class ItemArmor extends Item implements Equipable { private static final EnumMap ARMOR_MODIFIER_UUID_PER_TYPE = (EnumMap) SystemUtils.make(new EnumMap(ItemArmor.a.class), (enummap) -> { @@ -58,8 +63,34 @@ EntityLiving entityliving = (EntityLiving) list.get(0); EnumItemSlot enumitemslot = EntityInsentient.getEquipmentSlotForItem(itemstack); ItemStack itemstack1 = itemstack.split(1); + // CraftBukkit start + World world = isourceblock.getLevel(); + org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getPos().getX(), isourceblock.getPos().getY(), isourceblock.getPos().getZ()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); + + BlockDispenseArmorEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) entityliving.getBukkitEntity()); + if (!BlockDispenser.eventFired) { + world.getCraftServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + itemstack.grow(1); + return false; + } + + if (!event.getItem().equals(craftItem)) { + itemstack.grow(1); + // Chain to handler for new item + ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); + if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) { + idispensebehavior.dispense(isourceblock, eventStack); + return true; + } + } - entityliving.setItemSlot(enumitemslot, itemstack1); + entityliving.setItemSlot(enumitemslot, CraftItemStack.asNMSCopy(event.getItem())); + // CraftBukkit end if (entityliving instanceof EntityInsentient) { ((EntityInsentient) entityliving).setDropChance(enumitemslot, 2.0F); ((EntityInsentient) entityliving).setPersistenceRequired();