0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-22 04:16:17 +00:00
craftbukkit/nms-patches/net/minecraft/world/item/ItemHanging.patch
2024-10-23 02:15:00 +11:00

44 lines
2.6 KiB
Diff

--- a/net/minecraft/world/item/ItemHanging.java
+++ b/net/minecraft/world/item/ItemHanging.java
@@ -25,6 +25,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 static final IChatBaseComponent TOOLTIP_RANDOM_VARIANT = IChatBaseComponent.translatable("painting.random").withStyle(EnumChatFormat.GRAY);
@@ -75,6 +80,19 @@
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);
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(itemactioncontext.getHand());
+
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) ((EntityHanging) object).getBukkitEntity(), who, blockClicked, blockFace, hand, 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((Entity) entityhuman, (Holder) GameEvent.ENTITY_PLACE, ((EntityHanging) object).position());
world.addFreshEntity((Entity) object);
@@ -102,7 +120,7 @@
if (!customdata.isEmpty()) {
customdata.read(holderlookup_a.createSerializationContext(DynamicOpsNBT.INSTANCE), EntityPainting.VARIANT_MAP_CODEC).result().ifPresentOrElse((holder) -> {
- Optional optional = ((PaintingVariant) holder.value()).title();
+ Optional<IChatBaseComponent> optional = ((PaintingVariant) holder.value()).title(); // CraftBukkit - decompile error
Objects.requireNonNull(list);
optional.ifPresent(list::add);