3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-14 20:10:05 +01:00
Paper/patches/api/0218-Add-PlayerShearBlockEvent.patch

120 Zeilen
3.6 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JRoy <joshroy126@gmail.com>
Date: Thu, 27 Aug 2020 12:32:35 -0400
Subject: [PATCH] Add PlayerShearBlockEvent
diff --git a/src/main/java/io/papermc/paper/event/block/PlayerShearBlockEvent.java b/src/main/java/io/papermc/paper/event/block/PlayerShearBlockEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..33c6e1868e1bad4802bcadecebc2b46633690fce
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/block/PlayerShearBlockEvent.java
@@ -0,0 +1,107 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.event.block;
+
+import java.util.List;
2021-06-11 14:02:28 +02:00
+import org.bukkit.block.Block;
+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.EquipmentSlot;
+import org.bukkit.inventory.ItemStack;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Called when a player uses sheers on a block.
+ * <p>
+ * This event is <b>not</b> called when breaking blocks with shears but instead only when a
+ * player uses the sheer item on a block to garner drops from said block and/or change its state.
+ * <p>
+ * Examples include shearing a pumpkin to turn it into a carved pumpkin or shearing a beehive to get honeycomb.
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class PlayerShearBlockEvent extends PlayerEvent implements Cancellable {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
2021-06-11 14:02:28 +02:00
+ private final Block block;
+ private final ItemStack item;
+ private final EquipmentSlot hand;
+ private final List<ItemStack> drops;
+
2024-02-01 10:15:57 +01:00
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public PlayerShearBlockEvent(final Player player, final Block block, final ItemStack item, final EquipmentSlot hand, final List<ItemStack> drops) {
2024-02-01 10:15:57 +01:00
+ super(player);
2021-06-11 14:02:28 +02:00
+ this.block = block;
+ this.item = item;
+ this.hand = hand;
+ this.drops = drops;
+ }
+
+ /**
+ * Gets the block being sheared in this event.
+ *
+ * @return The {@link Block} which block is being sheared in this event.
+ */
+ public Block getBlock() {
2024-02-01 10:15:57 +01:00
+ return this.block;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets the item used to shear the block.
+ *
+ * @return The {@link ItemStack} of the shears.
+ */
+ public ItemStack getItem() {
2024-02-01 10:15:57 +01:00
+ return this.item;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets the hand used to shear the block.
+ *
+ * @return Either {@link EquipmentSlot#HAND} OR {@link EquipmentSlot#OFF_HAND}.
+ */
+ public EquipmentSlot getHand() {
2024-02-01 10:15:57 +01:00
+ return this.hand;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets the resulting drops of this event.
+ *
+ * @return A mutable {@link List list} of {@link ItemStack items} that will be dropped as result of this event.
2021-06-11 14:02:28 +02:00
+ */
+ public List<ItemStack> getDrops() {
2024-02-01 10:15:57 +01:00
+ return this.drops;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets whether the shearing of the block should be cancelled or not.
+ *
+ * @return Whether the shearing of the block should be cancelled or not.
+ */
+ @Override
+ public boolean isCancelled() {
2024-02-01 10:15:57 +01:00
+ return this.cancelled;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Sets whether the shearing of the block should be cancelled or not.
+ *
+ * @param cancel whether the shearing of the block should be cancelled or not.
+ */
+ @Override
+ public void setCancelled(final boolean cancel) {
2021-06-11 14:02:28 +02:00
+ this.cancelled = cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}