summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemHanging.patch
blob: 89b547f8ff73c8a9bdbd77b1096b856d3eff870b (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
--- a/net/minecraft/server/ItemHanging.java
+++ b/net/minecraft/server/ItemHanging.java
@@ -1,6 +1,10 @@
 package net.minecraft.server;
 
 import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.entity.Player;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+// CraftBukkit end
 
 public class ItemHanging extends Item {
 
@@ -20,6 +24,18 @@
 
             if (entityhanging != null && entityhanging.survives()) {
                 if (!world.isClientSide) {
+                    // CraftBukkit start - fire HangingPlaceEvent
+                    Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
+                    org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+                    org.bukkit.block.BlockFace blockFace = org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection);
+
+                    HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
+                    world.getServer().getPluginManager().callEvent(event);
+
+                    if (event.isCancelled()) {
+                        return EnumInteractionResult.FAIL;
+                    }
+                    // CraftBukkit end
                     entityhanging.o();
                     world.addEntity(entityhanging);
                 }