PaperMC/patches/api/0313-Add-PlayerItemFrameChangeEvent.patch

112 lines
3.4 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: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..f387477da45a44cc7788ed5342104f535cf3cb98
2021-12-04 14:49:34 +01:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerItemFrameChangeEvent.java
@@ -0,0 +1,99 @@
2021-12-04 14:49:34 +01:00
+package io.papermc.paper.event.player;
+
+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;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
2021-12-04 14:49:34 +01:00
+
+/**
+ * Called when an {@link ItemFrame} is having an item rotated, added, or removed from it.
+ */
+@NullMarked
2021-12-04 14:49:34 +01:00
+public class PlayerItemFrameChangeEvent extends PlayerEvent implements Cancellable {
+
2024-02-01 10:15:57 +01:00
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
2021-12-04 14:49:34 +01:00
+ private final ItemFrame itemFrame;
+ private final ItemFrameChangeAction action;
2024-02-01 10:15:57 +01:00
+ private ItemStack itemStack;
+
+ private boolean cancelled;
2021-12-04 14:49:34 +01:00
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public PlayerItemFrameChangeEvent(final Player player, final ItemFrame itemFrame, final ItemStack itemStack, final ItemFrameChangeAction action) {
2021-12-04 14:49:34 +01:00
+ super(player);
+ this.itemFrame = itemFrame;
+ this.itemStack = itemStack;
+ this.action = action;
+ }
+
+ /**
+ * Gets the {@link ItemFrame} involved in this event.
2024-02-01 10:15:57 +01:00
+ *
2021-12-04 14:49:34 +01:00
+ * @return the {@link ItemFrame}
+ */
+ public ItemFrame getItemFrame() {
2024-02-01 10:15:57 +01:00
+ return this.itemFrame;
2021-12-04 14:49:34 +01:00
+ }
+
+ /**
+ * Gets the {@link ItemStack} involved in this event.
+ * This is the item being added, rotated, or removed from the {@link ItemFrame}.
2024-02-01 10:15:57 +01:00
+ * <p>
+ * If this method returns air, then the resulting item in the ItemFrame will be empty.
+ *
2021-12-04 14:49:34 +01:00
+ * @return the {@link ItemStack} being added, rotated, or removed
+ */
+ public ItemStack getItemStack() {
2024-02-01 10:15:57 +01:00
+ return this.itemStack;
2021-12-04 14:49:34 +01:00
+ }
+
+ /**
+ * Sets the {@link ItemStack} that this {@link ItemFrame} holds.
2024-02-01 10:15:57 +01:00
+ * If {@code null} is provided, the ItemStack will become air and the result in the ItemFrame will be empty.
+ *
2021-12-04 14:49:34 +01:00
+ * @param itemStack {@link ItemFrame} item
+ */
+ public void setItemStack(final @Nullable ItemStack itemStack) {
2024-02-01 10:15:57 +01:00
+ this.itemStack = itemStack == null ? ItemStack.empty() : itemStack;
2021-12-04 14:49:34 +01:00
+ }
+
+ /**
+ * Gets the action that was performed on this {@link ItemFrame}.
2024-02-01 10:15:57 +01:00
+ *
2021-12-04 14:49:34 +01:00
+ * @return action performed on the item frame in this event
+ */
+ public ItemFrameChangeAction getAction() {
2024-02-01 10:15:57 +01:00
+ return this.action;
2021-12-04 14:49:34 +01:00
+ }
+
+ @Override
+ public boolean isCancelled() {
2024-02-01 10:15:57 +01:00
+ return this.cancelled;
2021-12-04 14:49:34 +01:00
+ }
+
+ @Override
+ public void setCancelled(final boolean cancel) {
2021-12-04 14:49:34 +01:00
+ this.cancelled = cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-12-04 14:49:34 +01:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-12-04 14:49:34 +01:00
+ }
+
+ public enum ItemFrameChangeAction {
+ PLACE,
+ REMOVE,
+ ROTATE
+ }
+}