diff options
author | Dennis Bliefernicht <dennis.bliefernicht@triphoenix.de> | 2013-03-22 08:41:37 +0100 |
---|---|---|
committer | Nate Mortensen <nate.richard.mortensen@gmail.com> | 2013-03-23 16:12:52 -0600 |
commit | e61a6bab05bbc19902f486a174b2073f3b884ceb (patch) | |
tree | c637ef254762023bf32ef09e886e701b9610b005 /src | |
parent | b10474253cad44f18781cecbe724e3d97c2f7387 (diff) | |
download | craftbukkit-e61a6bab05bbc19902f486a174b2073f3b884ceb.tar craftbukkit-e61a6bab05bbc19902f486a174b2073f3b884ceb.tar.gz craftbukkit-e61a6bab05bbc19902f486a174b2073f3b884ceb.tar.lz craftbukkit-e61a6bab05bbc19902f486a174b2073f3b884ceb.tar.xz craftbukkit-e61a6bab05bbc19902f486a174b2073f3b884ceb.zip |
Implement InventoryMoveItemEvent. Adds BUKKIT-3765
This makes droppers, hoppers and hopper minecarts fire an
InventoryMoveItemEvent whenever an item is being moved from or to another
inventory.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/net/minecraft/server/BlockDropper.java | 20 | ||||
-rw-r--r-- | src/main/java/net/minecraft/server/TileEntityHopper.java | 44 |
2 files changed, 58 insertions, 6 deletions
diff --git a/src/main/java/net/minecraft/server/BlockDropper.java b/src/main/java/net/minecraft/server/BlockDropper.java index 856aadab..ac7bb51a 100644 --- a/src/main/java/net/minecraft/server/BlockDropper.java +++ b/src/main/java/net/minecraft/server/BlockDropper.java @@ -1,5 +1,11 @@ package net.minecraft.server; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.inventory.Inventory; +// CraftBukkit end + public class BlockDropper extends BlockDispenser { private final IDispenseBehavior cR = new DispenseBehaviorItem(); @@ -32,8 +38,18 @@ public class BlockDropper extends BlockDispenser { ItemStack itemstack1; if (iinventory != null) { - itemstack1 = TileEntityHopper.addItem(iinventory, itemstack.cloneItemStack().a(1), Facing.OPPOSITE_FACING[i1]); - if (itemstack1 == null) { + // CraftBukkit start - fire event when pushing items into other inventories + CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.cloneItemStack().a(1)); + + Inventory destinationInventory = iinventory.getOwner() != null ? iinventory.getOwner().getInventory() : null; + InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentitydispenser.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true); + world.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + itemstack1 = TileEntityHopper.addItem(iinventory, CraftItemStack.asNMSCopy(event.getItem()), Facing.OPPOSITE_FACING[i1]); + if (event.getItem().equals(oitemstack) && itemstack1 == null) { + // CraftBukkit end itemstack1 = itemstack.cloneItemStack(); if (--itemstack1.count == 0) { itemstack1 = null; diff --git a/src/main/java/net/minecraft/server/TileEntityHopper.java b/src/main/java/net/minecraft/server/TileEntityHopper.java index a1e2bc26..8e0918d6 100644 --- a/src/main/java/net/minecraft/server/TileEntityHopper.java +++ b/src/main/java/net/minecraft/server/TileEntityHopper.java @@ -4,8 +4,11 @@ import java.util.List; // CraftBukkit start import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.inventory.Inventory; // CraftBukkit end public class TileEntityHopper extends TileEntity implements IHopper { @@ -199,10 +202,26 @@ public class TileEntityHopper extends TileEntity implements IHopper { for (int i = 0; i < this.getSize(); ++i) { if (this.getItem(i) != null) { ItemStack itemstack = this.getItem(i).cloneItemStack(); - ItemStack itemstack1 = addItem(iinventory, this.splitStack(i, 1), Facing.OPPOSITE_FACING[BlockHopper.c(this.p())]); + // CraftBukkit start - fire event when pushing items into other inventories + CraftItemStack oitemstack = CraftItemStack.asCraftMirror(this.splitStack(i, 1)); + + Inventory destinationInventory = iinventory.getOwner() != null ? iinventory.getOwner().getInventory() : null; + InventoryMoveItemEvent event = new InventoryMoveItemEvent(this.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true); + this.getWorld().getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + this.setItem(i, itemstack); + this.c(8); // delay hopper checks + return false; + } + ItemStack itemstack1 = addItem(iinventory, CraftItemStack.asNMSCopy(event.getItem()), Facing.OPPOSITE_FACING[BlockHopper.c(this.p())]); if (itemstack1 == null || itemstack1.count == 0) { - iinventory.update(); + if (event.getItem().equals(oitemstack)) { + iinventory.update(); + } else { + this.setItem(i, itemstack); + } + // CraftBukkit end return true; } @@ -254,10 +273,27 @@ public class TileEntityHopper extends TileEntity implements IHopper { if (itemstack != null && canTakeItemFromInventory(iinventory, itemstack, i, j)) { ItemStack itemstack1 = itemstack.cloneItemStack(); - ItemStack itemstack2 = addItem(ihopper, iinventory.splitStack(i, 1), -1); + // CraftBukkit start - fire event on collection of items from inventories into the hopper + CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.splitStack(i, 1)); + + Inventory sourceInventory = iinventory.getOwner() != null ? iinventory.getOwner().getInventory() : null; + InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false); + + ihopper.getWorld().getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + iinventory.setItem(i, itemstack1); + ((TileEntityHopper) ihopper).c(8); // delay hopper checks + return false; + } + ItemStack itemstack2 = addItem(ihopper, CraftItemStack.asNMSCopy(event.getItem()), -1); if (itemstack2 == null || itemstack2.count == 0) { - iinventory.update(); + if (event.getItem().equals(oitemstack)) { + iinventory.update(); + } else { + iinventory.setItem(i, itemstack1); + } + // CraftBukkit end return true; } |