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 | |
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')
4 files changed, 131 insertions, 5 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); diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorBonemeal.java b/src/main/java/net/minecraft/server/DispenseBehaviorBonemeal.java index 4f182171..54c590b6 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorBonemeal.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorBonemeal.java @@ -1,5 +1,10 @@ package net.minecraft.server; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockDispenseEvent; +// CraftBukkit end + final class DispenseBehaviorBonemeal extends DispenseBehaviorItem { private boolean b = true; @@ -14,7 +19,34 @@ final class DispenseBehaviorBonemeal extends DispenseBehaviorItem { int j = isourceblock.getBlockY() + enumfacing.d(); int k = isourceblock.getBlockZ() + enumfacing.e(); - if (ItemDye.a(itemstack, world, i, j, k)) { + // CraftBukkit start + ItemStack itemstack1 = itemstack.a(1); + 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 + + if (ItemDye.a(itemstack1, world, i, j, k)) { // CraftBukkit - itemstack -> itemstack1 if (!world.isStatic) { world.triggerEffect(2005, i, j, k, 0); } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorFlintAndSteel.java b/src/main/java/net/minecraft/server/DispenseBehaviorFlintAndSteel.java index b143f619..834e93a2 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorFlintAndSteel.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorFlintAndSteel.java @@ -1,5 +1,10 @@ package net.minecraft.server; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockDispenseEvent; +// CraftBukkit end + final class DispenseBehaviorFlintAndSteel extends DispenseBehaviorItem { private boolean b = true; @@ -13,6 +18,30 @@ final class DispenseBehaviorFlintAndSteel extends DispenseBehaviorItem { int j = isourceblock.getBlockY() + enumfacing.d(); int k = isourceblock.getBlockZ() + enumfacing.e(); + // CraftBukkit start + org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack); + + 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()) { + return itemstack; + } + + if (!event.getItem().equals(craftItem)) { + // 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 + if (world.isEmpty(i, j, k)) { world.setTypeIdUpdate(i, j, k, Block.FIRE.id); if (itemstack.isDamaged(1, world.random)) { diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorTNT.java b/src/main/java/net/minecraft/server/DispenseBehaviorTNT.java index 724a2eef..950d9e9d 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorTNT.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorTNT.java @@ -1,5 +1,10 @@ package net.minecraft.server; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockDispenseEvent; +// CraftBukkit end + final class DispenseBehaviorTNT extends DispenseBehaviorItem { DispenseBehaviorTNT() {} @@ -10,10 +15,38 @@ final class DispenseBehaviorTNT extends DispenseBehaviorItem { int i = isourceblock.getBlockX() + enumfacing.c(); int j = isourceblock.getBlockY() + enumfacing.d(); int k = isourceblock.getBlockZ() + enumfacing.e(); - EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), (EntityLiving) null); + + // CraftBukkit start + ItemStack itemstack1 = itemstack.a(1); + 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(i + 0.5, j + 0.5, k + 0.5)); + 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; + } + } + + EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), (EntityLiving) null); + // CraftBukkit end world.addEntity(entitytntprimed); - --itemstack.count; + // --itemstack.count; // CraftBukkit - handled above return itemstack; } } |