blob: 74085cee3d56d5c0d7a7cb9b0ec16690331be932 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
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
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/block/PlayerShearBlockEvent.java
@@ -0,0 +1,107 @@
+package io.papermc.paper.event.block;
+
+import java.util.List;
+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;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * 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
+public class PlayerShearBlockEvent extends PlayerEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Block block;
+ private final ItemStack item;
+ private final EquipmentSlot hand;
+ private final List<ItemStack> drops;
+
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public PlayerShearBlockEvent(final Player player, final Block block, final ItemStack item, final EquipmentSlot hand, final List<ItemStack> drops) {
+ super(player);
+ 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() {
+ return this.block;
+ }
+
+ /**
+ * Gets the item used to shear the block.
+ *
+ * @return The {@link ItemStack} of the shears.
+ */
+ public ItemStack getItem() {
+ return this.item;
+ }
+
+ /**
+ * Gets the hand used to shear the block.
+ *
+ * @return Either {@link EquipmentSlot#HAND} OR {@link EquipmentSlot#OFF_HAND}.
+ */
+ public EquipmentSlot getHand() {
+ return this.hand;
+ }
+
+ /**
+ * 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.
+ */
+ public List<ItemStack> getDrops() {
+ return this.drops;
+ }
+
+ /**
+ * 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() {
+ return this.cancelled;
+ }
+
+ /**
+ * 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) {
+ this.cancelled = cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}
|