Paper/patches/server/0758-Add-PlayerItemFrameChangeEvent.patch
Nassim Jahnke d5f1ffc2e6
Remove somewhat broken patch
With the new chunk system it doesn't hurt too much to (temporarily) remove this until implemented in a safer manner
2022-12-19 11:46:55 +01:00

58 Zeilen
3.5 KiB
Diff

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
index 880ca7cb3ebccc16949e24a0230b1f83887b653f..db60d29b051bad8d115b333e6c72287860a73123 100644
--- 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;
import com.mojang.logging.LogUtils;
import java.util.OptionalInt;
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;
@@ -188,6 +189,13 @@ public class ItemFrame extends HangingEntity {
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
+ this.setItem(ItemStack.fromBukkitCopy(event.getItemStack()), false);
+ }
+ // Paper end
this.dropItem(source.getEntity(), false);
this.playSound(this.getRemoveItemSound(), 1.0F, 1.0F);
}
@@ -452,13 +460,22 @@ public class ItemFrame extends HangingEntity {
return InteractionResult.FAIL;
}
}
-
- this.setItem(itemstack);
+ // Paper start - call PlayerItemFrameChangeEvent
+ var 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;
+ this.setItem(ItemStack.fromBukkitCopy(event.getItemStack()));
+ // this.setItem(itemstack);
+ // Paper end
if (!player.getAbilities().instabuild) {
itemstack.shrink(1);
}
}
} else {
+ // Paper start - call PlayerItemFrameChangeEvent
+ var 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;
+ setItem(ItemStack.fromBukkitCopy(event.getItemStack()), false, false);
+ // Paper end
this.playSound(this.getRotateItemSound(), 1.0F, 1.0F);
this.setRotation(this.getRotation() + 1);
}