3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/server/0646-Add-PlayerItemFrameChangeEvent.patch

59 Zeilen
3.7 KiB
Diff

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
2024-04-24 18:15:59 +02:00
index 5a0658932cc45c49c9285b1419d574dd83041732..bb22b84c32848869967a47a60f9d8a0629a59e2a 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
2024-04-24 18:15:59 +02:00
@@ -2,6 +2,7 @@ package net.minecraft.world.entity.decoration;
2022-03-01 06:43:03 +01:00
import com.mojang.logging.LogUtils;
2021-12-04 14:49:34 +01:00
import javax.annotation.Nullable;
+import io.papermc.paper.event.player.PlayerItemFrameChangeEvent; // Paper - Add PlayerItemFrameChangeEvent
2021-12-04 14:49:34 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
2024-04-24 18:15:59 +02:00
import net.minecraft.core.component.DataComponents;
@@ -179,6 +180,13 @@ public class ItemFrame extends HangingEntity {
2021-12-04 14:49:34 +01:00
return true;
}
// CraftBukkit end
+ // Paper start - Add PlayerItemFrameChangeEvent
2021-12-04 14:49:34 +01:00
+ 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 - Add PlayerItemFrameChangeEvent
2021-12-04 14:49:34 +01:00
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);
2024-04-24 18:15:59 +02:00
@@ -429,11 +437,24 @@ 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 - Add 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 - Add PlayerItemFrameChangeEvent
this.gameEvent(GameEvent.BLOCK_CHANGE, player);
2024-04-24 18:15:59 +02:00
itemstack.consume(1, player);
2021-12-04 14:49:34 +01:00
}
} else {
+ // Paper start - Add 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 - Add PlayerItemFrameChangeEvent
2021-12-04 14:49:34 +01:00
this.playSound(this.getRotateItemSound(), 1.0F, 1.0F);
this.setRotation(this.getRotation() + 1);
this.gameEvent(GameEvent.BLOCK_CHANGE, player);