diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2013-03-16 16:38:19 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2013-03-16 16:55:27 -0500 |
commit | 0e60f1f7b8049a886b86be0522e6cd8f02e7b5c8 (patch) | |
tree | 4dbaa74c4054dff2bcad5b85929f08adbb921e5f /src/main/java/net/minecraft/server/DispenseBehaviorArmor.java | |
parent | fbe609bdbe11d480cba162385926c2f0a36c8a49 (diff) | |
download | craftbukkit-0e60f1f7b8049a886b86be0522e6cd8f02e7b5c8.tar craftbukkit-0e60f1f7b8049a886b86be0522e6cd8f02e7b5c8.tar.gz craftbukkit-0e60f1f7b8049a886b86be0522e6cd8f02e7b5c8.tar.lz craftbukkit-0e60f1f7b8049a886b86be0522e6cd8f02e7b5c8.tar.xz craftbukkit-0e60f1f7b8049a886b86be0522e6cd8f02e7b5c8.zip |
Fire BlockDispenseEvent for new dispenser behaviors. Fixes BUKKIT-3774
Diffstat (limited to 'src/main/java/net/minecraft/server/DispenseBehaviorArmor.java')
-rw-r--r-- | src/main/java/net/minecraft/server/DispenseBehaviorArmor.java | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorArmor.java b/src/main/java/net/minecraft/server/DispenseBehaviorArmor.java index 06e77b62..1c50ad4f 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorArmor.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorArmor.java @@ -2,6 +2,11 @@ package net.minecraft.server; import java.util.List; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockDispenseEvent; +// CraftBukkit end + final class DispenseBehaviorArmor extends DispenseBehaviorItem { DispenseBehaviorArmor() {} @@ -18,12 +23,39 @@ final class DispenseBehaviorArmor extends DispenseBehaviorItem { EntityLiving entityliving = (EntityLiving) list.get(0); int l = entityliving instanceof EntityHuman ? 1 : 0; int i1 = EntityLiving.b(itemstack); - ItemStack itemstack1 = itemstack.cloneItemStack(); + + // CraftBukkit start + ItemStack itemstack1 = itemstack.a(1); + World world = isourceblock.k(); + org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); + + BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0)); + if (!BlockDispenser.eventFired) { + world.getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + itemstack.count++; + return itemstack; + } + + if (!event.getItem().equals(craftItem)) { + itemstack.count++; + // Chain to handler for new item + ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); + if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { + idispensebehavior.a(isourceblock, eventStack); + return itemstack; + } + } + // CraftBukkit end itemstack1.count = 1; entityliving.setEquipment(i1 - l, itemstack1); entityliving.a(i1, 2.0F); - --itemstack.count; + // --itemstack.count; // CraftBukkit - handled above return itemstack; } else { return super.b(isourceblock, itemstack); |