PaperMC/paper-server/nms-patches/net/minecraft/world/item/ItemHanging.patch
CraftBukkit/Spigot 43702a9e10 Update to Minecraft 1.18-pre5
By: md_5 <git@md-5.net>
2021-11-22 09:00:00 +11:00

33 lines
1.7 KiB
Diff

--- a/net/minecraft/world/item/ItemHanging.java
+++ b/net/minecraft/world/item/ItemHanging.java
@@ -15,6 +15,11 @@
import net.minecraft.world.level.World;
import net.minecraft.world.level.gameevent.GameEvent;
+// 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> type;
@@ -58,6 +63,18 @@
if (((EntityHanging) object).survives()) {
if (!world.isClientSide) {
+ // CraftBukkit start - fire HangingPlaceEvent
+ Player who = (itemactioncontext.getPlayer() == null) ? null : (Player) itemactioncontext.getPlayer().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, org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack));
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return EnumInteractionResult.FAIL;
+ }
+ // CraftBukkit end
((EntityHanging) object).playPlacementSound();
world.gameEvent(entityhuman, GameEvent.ENTITY_PLACE, blockposition);
world.addFreshEntity((Entity) object);