--- a/net/minecraft/world/item/ItemArmor.java +++ b/net/minecraft/world/item/ItemArmor.java @@ -29,6 +29,12 @@ import net.minecraft.world.level.block.BlockDispenser; import net.minecraft.world.phys.AxisAlignedBB; +// CraftBukkit start +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockDispenseArmorEvent; +// CraftBukkit end + public class ItemArmor extends Item implements Equipable { public static final IDispenseBehavior DISPENSE_ITEM_BEHAVIOR = new DispenseBehaviorItem() { @@ -51,8 +57,34 @@ EntityLiving entityliving = (EntityLiving) list.get(0); EnumItemSlot enumitemslot = entityliving.getEquipmentSlotForItem(itemstack); ItemStack itemstack1 = itemstack.split(1); + // CraftBukkit start + World world = sourceblock.level(); + org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); - entityliving.setItemSlot(enumitemslot, 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(sourceblock, eventStack); + return true; + } + } + + entityliving.setItemSlot(enumitemslot, CraftItemStack.asNMSCopy(event.getItem())); + // CraftBukkit end if (entityliving instanceof EntityInsentient) { ((EntityInsentient) entityliving).setDropChance(enumitemslot, 2.0F); ((EntityInsentient) entityliving).setPersistenceRequired();