Paper/nms-patches/ItemHanging.patch
2019-04-23 12:00:00 +10:00

33 lines
1.5 KiB
Diff

--- a/net/minecraft/server/ItemHanging.java
+++ b/net/minecraft/server/ItemHanging.java
@@ -1,5 +1,10 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.entity.Player;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+// CraftBukkit end
+
public class ItemHanging extends Item {
private final EntityTypes<? extends EntityHanging> a;
@@ -41,6 +46,18 @@
if (((EntityHanging) object).survives()) {
if (!world.isClientSide) {
+ // CraftBukkit start - fire HangingPlaceEvent
+ Player who = (itemactioncontext.getEntity() == null) ? null : (Player) itemactioncontext.getEntity().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) object).getBukkitEntity(), who, blockClicked, blockFace);
+ world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return EnumInteractionResult.FAIL;
+ }
+ // CraftBukkit end
((EntityHanging) object).playPlaceSound();
world.addEntity((Entity) object);
}