aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0214-Add-PrepareResultEvent-PrepareGrindstoneEvent.patch
blob: 5dc61d601d07c987cd012ff7b76d7ba7bc73dc34 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Fri, 3 Jul 2020 11:58:56 -0500
Subject: [PATCH] Add PrepareResultEvent / PrepareGrindstoneEvent

Adds a new event for all crafting stations that generate a result slot item

Anvil, Grindstone and Smithing now extend this event

Grindstone is a backwards compat from a previous PrepareGrindstoneEvent

diff --git a/src/main/java/com/destroystokyo/paper/event/inventory/PrepareGrindstoneEvent.java b/src/main/java/com/destroystokyo/paper/event/inventory/PrepareGrindstoneEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..449e8c06f8434b59d49a76481fa60c5c49e80579
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/inventory/PrepareGrindstoneEvent.java
@@ -0,0 +1,28 @@
+package com.destroystokyo.paper.event.inventory;
+
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.inventory.InventoryEvent;
+import org.bukkit.inventory.GrindstoneInventory;
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when an item is put in a slot for grinding in a Grindstone
+ * @see com.destroystokyo.paper.event.inventory.PrepareResultEvent
+ */
+@Deprecated
+public class PrepareGrindstoneEvent extends PrepareResultEvent {
+
+    public PrepareGrindstoneEvent(@NotNull InventoryView inventory, @Nullable ItemStack result) {
+        super(inventory, result);
+    }
+
+    @NotNull
+    @Override
+    public GrindstoneInventory getInventory() {
+        return (GrindstoneInventory) super.getInventory();
+    }
+
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/inventory/PrepareResultEvent.java b/src/main/java/com/destroystokyo/paper/event/inventory/PrepareResultEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..045ce9ec3c9134aced5f5235b760ac85599d16c6
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/inventory/PrepareResultEvent.java
@@ -0,0 +1,48 @@
+package com.destroystokyo.paper.event.inventory;
+
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.inventory.InventoryEvent;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when an item is put in an inventory containing a result slot
+ */
+public class PrepareResultEvent extends InventoryEvent {
+
+    private static final HandlerList handlers = new HandlerList();
+    private ItemStack result;
+
+    public PrepareResultEvent(@NotNull InventoryView inventory, @Nullable ItemStack result) {
+        super(inventory);
+        this.result = result;
+    }
+
+    /**
+     * Get result item, may be null.
+     *
+     * @return result item
+     */
+    @Nullable
+    public ItemStack getResult() {
+        return result;
+    }
+
+    public void setResult(@Nullable ItemStack result) {
+        this.result = result;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return handlers;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return handlers;
+    }
+}
diff --git a/src/main/java/org/bukkit/event/inventory/PrepareAnvilEvent.java b/src/main/java/org/bukkit/event/inventory/PrepareAnvilEvent.java
index 77109a07f07aa6985106dc1a9ad5218f6c7f360f..f1f6f4ab4f81a3f21e757fef4a30b00e94371f8d 100644
--- a/src/main/java/org/bukkit/event/inventory/PrepareAnvilEvent.java
+++ b/src/main/java/org/bukkit/event/inventory/PrepareAnvilEvent.java
@@ -1,5 +1,6 @@
 package org.bukkit.event.inventory;
 
+import com.destroystokyo.paper.event.inventory.PrepareResultEvent;
 import org.bukkit.event.HandlerList;
 import org.bukkit.inventory.AnvilInventory;
 import org.bukkit.inventory.InventoryView;
@@ -10,14 +11,16 @@ import org.jetbrains.annotations.Nullable;
 /**
  * Called when an item is put in a slot for repair by an anvil.
  */
-public class PrepareAnvilEvent extends InventoryEvent {
+// Paper start - extend PrepareResultEvent
+public class PrepareAnvilEvent extends PrepareResultEvent {
 
-    private static final HandlerList handlers = new HandlerList();
-    private ItemStack result;
+    //private static final HandlerList handlers = new HandlerList();
+    //private ItemStack result;
 
     public PrepareAnvilEvent(@NotNull InventoryView inventory, @Nullable ItemStack result) {
-        super(inventory);
-        this.result = result;
+        super(inventory, result);
+        //this.result = result;
+        // Paper end
     }
 
     @NotNull
@@ -33,13 +36,14 @@ public class PrepareAnvilEvent extends InventoryEvent {
      */
     @Nullable
     public ItemStack getResult() {
-        return result;
+        return super.getResult(); // Paper
     }
 
     public void setResult(@Nullable ItemStack result) {
-        this.result = result;
+        super.setResult(result); // Paper
     }
 
+    /* // Paper - comment out
     @NotNull
     @Override
     public HandlerList getHandlers() {
@@ -50,4 +54,5 @@ public class PrepareAnvilEvent extends InventoryEvent {
     public static HandlerList getHandlerList() {
         return handlers;
     }
+    */ // Paper
 }
diff --git a/src/main/java/org/bukkit/event/inventory/PrepareSmithingEvent.java b/src/main/java/org/bukkit/event/inventory/PrepareSmithingEvent.java
index 99af1540324c4d68c5890ac40b591c5cbdd2e870..0bc0ca4f96c800e9c46c61710f44446691d8b93f 100644
--- a/src/main/java/org/bukkit/event/inventory/PrepareSmithingEvent.java
+++ b/src/main/java/org/bukkit/event/inventory/PrepareSmithingEvent.java
@@ -1,5 +1,6 @@
 package org.bukkit.event.inventory;
 
+import com.destroystokyo.paper.event.inventory.PrepareResultEvent;
 import org.bukkit.event.HandlerList;
 import org.bukkit.inventory.InventoryView;
 import org.bukkit.inventory.ItemStack;
@@ -10,14 +11,16 @@ import org.jetbrains.annotations.Nullable;
 /**
  * Called when an item is put in a slot for upgrade by a Smithing Table.
  */
-public class PrepareSmithingEvent extends InventoryEvent {
+// Paper start - extend PrepareResultEvent
+public class PrepareSmithingEvent extends PrepareResultEvent {
 
-    private static final HandlerList handlers = new HandlerList();
-    private ItemStack result;
+    //private static final HandlerList handlers = new HandlerList();
+    //private ItemStack result;
 
     public PrepareSmithingEvent(@NotNull InventoryView inventory, @Nullable ItemStack result) {
-        super(inventory);
-        this.result = result;
+        super(inventory, result);
+        //this.result = result;
+        // Paper end
     }
 
     @NotNull
@@ -33,13 +36,14 @@ public class PrepareSmithingEvent extends InventoryEvent {
      */
     @Nullable
     public ItemStack getResult() {
-        return result;
+        return super.getResult(); // Paper
     }
 
     public void setResult(@Nullable ItemStack result) {
-        this.result = result;
+        super.setResult(result); // Paper
     }
 
+    /* // Paper - comment out
     @NotNull
     @Override
     public HandlerList getHandlers() {
@@ -50,4 +54,5 @@ public class PrepareSmithingEvent extends InventoryEvent {
     public static HandlerList getHandlerList() {
         return handlers;
     }
+    */ // Paper
 }