3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/api/0339-Add-PlayerItemFrameChangeEvent.patch
Nassim Jahnke 928bcc8d3a
Updated Upstream (Bukkit/CraftBukkit) (#8430)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
09943450 Update SnakeYAML version
5515734f SPIGOT-7162: Incorrect description for Entity#getVehicle javadoc
6f82b381 PR-788: Add getHand() to all relevant events

CraftBukkit Changes:
aaf484f6f SPIGOT-7163: CraftMerchantRecipe doesn't copy demand and specialPrice from BukkitMerchantRecipe
5329dd6fd PR-1107: Add getHand() to all relevant events
93061706e SPIGOT-7045: Ocelots never spawn with babies with spawn reason OCELOT_BABY
2022-10-02 09:56:36 +02:00

110 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:09:46 +0000
Subject: [PATCH] Add PlayerItemFrameChangeEvent
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerItemFrameChangeEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerItemFrameChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..451fb94a5802755c255e04aebb40f178bbfbf996
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerItemFrameChangeEvent.java
@@ -0,0 +1,97 @@
+package io.papermc.paper.event.player;
+
+import org.bukkit.Material;
+import org.bukkit.entity.ItemFrame;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when an {@link ItemFrame} is having an item rotated, added, or removed from it.
+ */
+public class PlayerItemFrameChangeEvent extends PlayerEvent implements Cancellable {
+
+ private static final HandlerList HANDLERS = new HandlerList();
+ private boolean cancelled;
+ private final ItemFrame itemFrame;
+ private ItemStack itemStack;
+ private final ItemFrameChangeAction action;
+
+ public PlayerItemFrameChangeEvent(@NotNull Player player, @NotNull ItemFrame itemFrame,
+ @NotNull ItemStack itemStack, @NotNull ItemFrameChangeAction action) {
+ super(player);
+ this.itemFrame = itemFrame;
+ this.itemStack = itemStack;
+ this.action = action;
+ }
+
+ /**
+ * Gets the {@link ItemFrame} involved in this event.
+ * @return the {@link ItemFrame}
+ */
+ @NotNull
+ public ItemFrame getItemFrame() {
+ return itemFrame;
+ }
+
+ /**
+ * Gets the {@link ItemStack} involved in this event.
+ * This is the item being added, rotated, or removed from the {@link ItemFrame}.
+ * <p>If this method returns air, then the resulting item in the ItemFrame will be empty.</p>
+ * @return the {@link ItemStack} being added, rotated, or removed
+ */
+ @NotNull
+ public ItemStack getItemStack() {
+ return itemStack;
+ }
+
+ /**
+ * Sets the {@link ItemStack} that this {@link ItemFrame} holds.
+ * If null is provided, the ItemStack will become air and the result in the ItemFrame will be empty.
+ * @param itemStack {@link ItemFrame} item
+ */
+ public void setItemStack(@Nullable ItemStack itemStack) {
+ this.itemStack = itemStack == null ? new ItemStack(Material.AIR) : itemStack;
+ }
+
+ /**
+ * Gets the action that was performed on this {@link ItemFrame}.
+ * @see ItemFrameChangeAction
+ * @return action performed on the item frame in this event
+ */
+ @NotNull
+ public ItemFrameChangeAction getAction() {
+ return action;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
+ return HANDLERS;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLERS;
+ }
+
+ public enum ItemFrameChangeAction {
+ PLACE,
+ REMOVE,
+ ROTATE
+ }
+}