Paper/patches/api/0318-Add-PlayerItemFrameChangeEvent.patch

117 lines
3.5 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
2024-02-01 10:15:57 +01:00
index 0000000000000000000000000000000000000000..7bd61b66db42ecc8c9a3a16f563552414488079e
2021-12-04 14:49:34 +01:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerItemFrameChangeEvent.java
2024-02-01 10:15:57 +01:00
@@ -0,0 +1,104 @@
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;
2021-12-04 14:49:34 +01:00
+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 {
+
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
2021-12-04 14:49:34 +01:00
+ 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.
2024-02-01 10:15:57 +01:00
+ *
2021-12-04 14:49:34 +01:00
+ * @return the {@link ItemFrame}
+ */
+ @NotNull
+ 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
+ */
+ @NotNull
+ 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(@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
+ */
+ @NotNull
+ 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(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-12-04 14:49:34 +01:00
+ }
+
+ @NotNull
+ 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
+ }
+}