SPIGOT-7794: Cancelling InventoryItemMoveEvent destroys items
This commit is contained in:
parent
ce40c7b146
commit
9cd5a19a0f
@ -60,12 +60,13 @@
|
|||||||
public TileEntityHopper(BlockPosition blockposition, IBlockData iblockdata) {
|
public TileEntityHopper(BlockPosition blockposition, IBlockData iblockdata) {
|
||||||
super(TileEntityTypes.HOPPER, blockposition, iblockdata);
|
super(TileEntityTypes.HOPPER, blockposition, iblockdata);
|
||||||
this.items = NonNullList.withSize(5, ItemStack.EMPTY);
|
this.items = NonNullList.withSize(5, ItemStack.EMPTY);
|
||||||
@@ -167,7 +213,28 @@
|
@@ -167,7 +213,29 @@
|
||||||
|
|
||||||
if (!itemstack.isEmpty()) {
|
if (!itemstack.isEmpty()) {
|
||||||
int j = itemstack.getCount();
|
int j = itemstack.getCount();
|
||||||
- ItemStack itemstack1 = addItem(tileentityhopper, iinventory, tileentityhopper.removeItem(i, 1), enumdirection);
|
- ItemStack itemstack1 = addItem(tileentityhopper, iinventory, tileentityhopper.removeItem(i, 1), enumdirection);
|
||||||
+ // CraftBukkit start - Call event when pushing items into other inventories
|
+ // CraftBukkit start - Call event when pushing items into other inventories
|
||||||
|
+ ItemStack original = itemstack.copy();
|
||||||
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(tileentityhopper.removeItem(i, 1));
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(tileentityhopper.removeItem(i, 1));
|
||||||
+
|
+
|
||||||
+ Inventory destinationInventory;
|
+ Inventory destinationInventory;
|
||||||
@ -81,7 +82,7 @@
|
|||||||
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentityhopper.getOwner().getInventory(), oitemstack, destinationInventory, true);
|
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentityhopper.getOwner().getInventory(), oitemstack, destinationInventory, true);
|
||||||
+ world.getCraftServer().getPluginManager().callEvent(event);
|
+ world.getCraftServer().getPluginManager().callEvent(event);
|
||||||
+ if (event.isCancelled()) {
|
+ if (event.isCancelled()) {
|
||||||
+ tileentityhopper.setItem(i, itemstack);
|
+ tileentityhopper.setItem(i, original);
|
||||||
+ tileentityhopper.setCooldown(8); // Delay hopper checks
|
+ tileentityhopper.setCooldown(8); // Delay hopper checks
|
||||||
+ return false;
|
+ return false;
|
||||||
+ }
|
+ }
|
||||||
@ -90,12 +91,13 @@
|
|||||||
|
|
||||||
if (itemstack1.isEmpty()) {
|
if (itemstack1.isEmpty()) {
|
||||||
iinventory.setChanged();
|
iinventory.setChanged();
|
||||||
@@ -279,7 +346,33 @@
|
@@ -279,7 +347,34 @@
|
||||||
|
|
||||||
if (!itemstack.isEmpty() && canTakeItemFromContainer(ihopper, iinventory, itemstack, i, enumdirection)) {
|
if (!itemstack.isEmpty() && canTakeItemFromContainer(ihopper, iinventory, itemstack, i, enumdirection)) {
|
||||||
int j = itemstack.getCount();
|
int j = itemstack.getCount();
|
||||||
- ItemStack itemstack1 = addItem(iinventory, ihopper, iinventory.removeItem(i, 1), (EnumDirection) null);
|
- ItemStack itemstack1 = addItem(iinventory, ihopper, iinventory.removeItem(i, 1), (EnumDirection) null);
|
||||||
+ // CraftBukkit start - Call event on collection of items from inventories into the hopper
|
+ // CraftBukkit start - Call event on collection of items from inventories into the hopper
|
||||||
|
+ ItemStack original = itemstack.copy();
|
||||||
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.removeItem(i, 1));
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.removeItem(i, 1));
|
||||||
+
|
+
|
||||||
+ Inventory sourceInventory;
|
+ Inventory sourceInventory;
|
||||||
@ -112,7 +114,7 @@
|
|||||||
+
|
+
|
||||||
+ Bukkit.getServer().getPluginManager().callEvent(event);
|
+ Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
+ if (event.isCancelled()) {
|
+ if (event.isCancelled()) {
|
||||||
+ iinventory.setItem(i, itemstack);
|
+ iinventory.setItem(i, original);
|
||||||
+
|
+
|
||||||
+ if (ihopper instanceof TileEntityHopper) {
|
+ if (ihopper instanceof TileEntityHopper) {
|
||||||
+ ((TileEntityHopper) ihopper).setCooldown(8); // Delay hopper checks
|
+ ((TileEntityHopper) ihopper).setCooldown(8); // Delay hopper checks
|
||||||
@ -125,7 +127,7 @@
|
|||||||
|
|
||||||
if (itemstack1.isEmpty()) {
|
if (itemstack1.isEmpty()) {
|
||||||
iinventory.setChanged();
|
iinventory.setChanged();
|
||||||
@@ -297,13 +390,20 @@
|
@@ -297,13 +392,20 @@
|
||||||
|
|
||||||
public static boolean addItem(IInventory iinventory, EntityItem entityitem) {
|
public static boolean addItem(IInventory iinventory, EntityItem entityitem) {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
@ -147,7 +149,7 @@
|
|||||||
} else {
|
} else {
|
||||||
entityitem.setItem(itemstack1);
|
entityitem.setItem(itemstack1);
|
||||||
}
|
}
|
||||||
@@ -421,14 +521,38 @@
|
@@ -421,14 +523,38 @@
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user