PaperMC/paper-server/patches/sources/net/minecraft/world/item/HangingEntityItem.java.patch

23 lines
1.5 KiB
Diff
Raw Normal View History

2024-12-14 21:50:20 +01:00
--- a/net/minecraft/world/item/HangingEntityItem.java
+++ b/net/minecraft/world/item/HangingEntityItem.java
@@ -66,6 +_,19 @@
if (hangingEntity.survives()) {
if (!level.isClientSide) {
+ // CraftBukkit start - fire HangingPlaceEvent
2024-12-15 15:55:13 +01:00
+ org.bukkit.entity.Player who = player == null ? null : (org.bukkit.entity.Player) player.getBukkitEntity();
+ org.bukkit.block.Block blockClicked = org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPos);
2024-12-14 21:50:20 +01:00
+ org.bukkit.block.BlockFace blockFace = org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(clickedFace);
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(context.getHand());
+
+ org.bukkit.event.hanging.HangingPlaceEvent event = new org.bukkit.event.hanging.HangingPlaceEvent((org.bukkit.entity.Hanging) hangingEntity.getBukkitEntity(), who, blockClicked, blockFace, hand, org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemInHand));
+ level.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return InteractionResult.FAIL;
+ }
+ // CraftBukkit end
hangingEntity.playPlacementSound();
level.gameEvent(player, GameEvent.ENTITY_PLACE, hangingEntity.position());
level.addFreshEntity(hangingEntity);