summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemHanging.patch
blob: 4d52a77e13613c04d61fa12799c34958dfb5b467 (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
--- /home/matt/mc-dev-private//net/minecraft/server/ItemHanging.java	2015-02-26 22:40:22.827608137 +0000
+++ src/main/java/net/minecraft/server/ItemHanging.java	2015-02-26 22:40:22.827608137 +0000
@@ -1,5 +1,11 @@
 package net.minecraft.server;
 
+// CraftBukkit start
+import org.bukkit.entity.Player;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+import org.bukkit.event.painting.PaintingPlaceEvent;
+// CraftBukkit end
+
 public class ItemHanging extends Item {
 
     private final Class<? extends EntityHanging> a;
@@ -24,6 +30,26 @@
 
                 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);
+
+                        PaintingPlaceEvent paintingEvent = null;
+                        if (entityhanging instanceof EntityPainting) {
+                            // Fire old painting event until it can be removed
+                            paintingEvent = new PaintingPlaceEvent((org.bukkit.entity.Painting) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
+                            paintingEvent.setCancelled(event.isCancelled());
+                            world.getServer().getPluginManager().callEvent(paintingEvent);
+                        }
+
+                        if (event.isCancelled() || (paintingEvent != null && paintingEvent.isCancelled())) {
+                            return false;
+                        }
+                        // CraftBukkit end
                         world.addEntity(entityhanging);
                     }