PaperMC/patches/server/0718-Add-PlayerItemFrameChangeEvent.patch

61 lines
3.7 KiB
Diff
Raw Normal View History

2021-12-04 14:49:34 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: SamB440 <sam@islandearth.net>
Date: Mon, 15 Nov 2021 18:10:10 +0000
Subject: [PATCH] Add PlayerItemFrameChangeEvent
diff --git a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
2023-12-06 16:17:00 +01:00
index 8289ea080aa297f75cdbc8d591d6efa6a0def0ea..63ef00eb6f93a471de1e9c2355099d9dd3a71dd9 100644
2021-12-04 14:49:34 +01:00
--- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
@@ -3,6 +3,7 @@ package net.minecraft.world.entity.decoration;
2022-03-01 06:43:03 +01:00
import com.mojang.logging.LogUtils;
import java.util.OptionalInt;
2021-12-04 14:49:34 +01:00
import javax.annotation.Nullable;
+import io.papermc.paper.event.player.PlayerItemFrameChangeEvent; // Paper
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
2023-12-06 16:17:00 +01:00
@@ -185,6 +186,13 @@ public class ItemFrame extends HangingEntity {
2021-12-04 14:49:34 +01:00
return true;
}
// CraftBukkit end
+ // Paper start - call PlayerItemFrameChangeEvent
+ if (source.getEntity() instanceof Player player) {
+ var event = new PlayerItemFrameChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.ItemFrame) this.getBukkitEntity(), this.getItem().asBukkitCopy(), PlayerItemFrameChangeEvent.ItemFrameChangeAction.REMOVE);
+ if (!event.callEvent()) return true; // return true here because you aren't cancelling the damage, just the change
2021-12-04 14:49:34 +01:00
+ this.setItem(ItemStack.fromBukkitCopy(event.getItemStack()), false);
+ }
+ // Paper end
this.dropItem(source.getEntity(), false);
this.gameEvent(GameEvent.BLOCK_CHANGE, source.getEntity());
2021-12-04 14:49:34 +01:00
this.playSound(this.getRemoveItemSound(), 1.0F, 1.0F);
2023-12-06 16:17:00 +01:00
@@ -451,13 +459,26 @@ public class ItemFrame extends HangingEntity {
2021-12-04 14:49:34 +01:00
}
}
2021-12-04 14:49:34 +01:00
- this.setItem(itemstack);
+ // Paper start - call PlayerItemFrameChangeEvent
+ PlayerItemFrameChangeEvent event = new PlayerItemFrameChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.ItemFrame) this.getBukkitEntity(), itemstack.asBukkitCopy(), PlayerItemFrameChangeEvent.ItemFrameChangeAction.PLACE);
+ if (!event.callEvent()) {
+ return InteractionResult.FAIL;
+ }
2021-12-04 14:49:34 +01:00
+ this.setItem(ItemStack.fromBukkitCopy(event.getItemStack()));
+ // Paper end
this.gameEvent(GameEvent.BLOCK_CHANGE, player);
2021-12-04 14:49:34 +01:00
if (!player.getAbilities().instabuild) {
itemstack.shrink(1);
}
}
} else {
+ // Paper start - call PlayerItemFrameChangeEvent
+ PlayerItemFrameChangeEvent event = new PlayerItemFrameChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.ItemFrame) this.getBukkitEntity(), this.getItem().asBukkitCopy(), PlayerItemFrameChangeEvent.ItemFrameChangeAction.ROTATE);
+ if (!event.callEvent()) {
+ return InteractionResult.FAIL;
+ }
2021-12-04 14:49:34 +01:00
+ setItem(ItemStack.fromBukkitCopy(event.getItemStack()), false, false);
+ // Paper end
this.playSound(this.getRotateItemSound(), 1.0F, 1.0F);
this.setRotation(this.getRotation() + 1);
this.gameEvent(GameEvent.BLOCK_CHANGE, player);