summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockDropper.patch
blob: 07c21cb4dd3aeae128f73aa0c2a7fd22f6a14845 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--- a/net/minecraft/server/BlockDropper.java
+++ b/net/minecraft/server/BlockDropper.java
@@ -1,5 +1,10 @@
 package net.minecraft.server;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+// CraftBukkit end
+
 public class BlockDropper extends BlockDispenser {
 
     private final IDispenseBehavior e = new DispenseBehaviorItem();
@@ -35,8 +40,25 @@
                     if (iinventory == null) {
                         itemstack1 = this.e.a(sourceblock, itemstack);
                     } else {
-                        itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, itemstack.cloneItemStack().cloneAndSubtract(1), enumdirection.opposite());
-                        if (itemstack1.isEmpty()) {
+                        // CraftBukkit start - Fire event when pushing items into other inventories
+                        CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.cloneItemStack().cloneAndSubtract(1));
+
+                        org.bukkit.inventory.Inventory destinationInventory;
+                        // Have to special case large chests as they work oddly
+                        if (iinventory instanceof InventoryLargeChest) {
+                            destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
+                        } else {
+                            destinationInventory = iinventory.getOwner().getInventory();
+                        }
+
+                        InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentitydispenser.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
+                        world.getServer().getPluginManager().callEvent(event);
+                        if (event.isCancelled()) {
+                            return;
+                        }
+                        itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection.opposite());
+                        if (event.getItem().equals(oitemstack) && itemstack1.isEmpty()) {
+                            // CraftBukkit end
                             itemstack1 = itemstack.cloneItemStack();
                             itemstack1.subtract(1);
                         } else {