aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0038-LootTable-API.patch
blob: 761cdb732abe02902817ae00633b6a38ba15ed52 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
From 2b1c15d0ea5602d9281d1306e0596a5a7f2d85e2 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 1 May 2016 15:19:49 -0400
Subject: [PATCH] LootTable API

Provides API to control what Loot Table an object uses.

Also provides an Event to control if a lootable inventory should
auto replenish for a player.

Provides methods to determine players looted state for an object

diff --git a/src/main/java/com/destroystokyo/paper/loottable/Lootable.java b/src/main/java/com/destroystokyo/paper/loottable/Lootable.java
new file mode 100644
index 0000000..d962a0c
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/Lootable.java
@@ -0,0 +1,78 @@
+package com.destroystokyo.paper.loottable;
+
+/**
+ * Defines an object that has a Loot Table and seed associated with it.
+ *
+ * How the Loot Table and seed are used may vary based on Minecraft Versions
+ * and what type of object is using the Loot Table
+ */
+public interface Lootable {
+
+    /**
+     * Gets the name of the Loot Table to be used in the World Folder
+     * @return The name, or null if no loot table exists
+     */
+    String getLootTableName();
+
+    /**
+     * Returns whether or not this object has a Loot Table
+     * @return Has a loot table
+     */
+    default boolean hasLootTable() {
+        return getLootTableName() != null;
+    }
+
+    /**
+     * Sets the name of the Loot Table to be used in the World Folder
+     * Will use a random seed (0)
+     *
+     * @param name name in either foo or minecraft:foo format
+     * @return The previous Loot Table before the change
+     */
+    default String setLootTable(String name) {
+        return setLootTable(name, 0);
+    }
+
+    /**
+     * Sets the name of the Loot Table to be used in the World Folder
+     * Uses supplied Seed
+     *
+     * @param name name in either foo or minecraft:foo format
+     * @param seed seed for the loot table. If 0, seed will be random
+     * @return The previous Loot Table before the change
+     */
+    String setLootTable(String name, long seed);
+
+    /**
+     * Gets the current seed associated to the Loot Table on this object
+     *
+     * @return The seed, or 0 for random
+     */
+    long getLootTableSeed();
+
+    /**
+     * Changes the current seed associated with the Loot Table on this object.
+     *
+     * The seed will have no affect if this object does not have a Loot Table
+     * associated with it.
+     *
+     * @throws IllegalStateException If called when this object does not have a loot table
+     * @param seed The seed to use, or 0 for random
+     * @return The previous seed
+     */
+    default long setLootTableSeed(long seed) {
+        final String lootTableName = getLootTableName();
+        if (lootTableName == null) {
+            throw new IllegalStateException("This object does not currently have a Loot Table.");
+        }
+
+        long prev = getLootTableSeed();
+        setLootTable(lootTableName, seed);
+        return prev;
+    }
+
+    /**
+     * Clears the associated Loot Table to this object
+     */
+    void clearLootTable();
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/LootableBlockInventory.java b/src/main/java/com/destroystokyo/paper/loottable/LootableBlockInventory.java
new file mode 100644
index 0000000..5e93e7e
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/LootableBlockInventory.java
@@ -0,0 +1,12 @@
+package com.destroystokyo.paper.loottable;
+
+import org.bukkit.block.Block;
+
+public interface LootableBlockInventory extends LootableInventory {
+
+    /**
+     * Gets the block that is lootable
+     * @return The Block
+     */
+    Block getBlock();
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/LootableEntityInventory.java b/src/main/java/com/destroystokyo/paper/loottable/LootableEntityInventory.java
new file mode 100644
index 0000000..8bebf07
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/LootableEntityInventory.java
@@ -0,0 +1,12 @@
+package com.destroystokyo.paper.loottable;
+
+import org.bukkit.entity.Entity;
+
+public interface LootableEntityInventory extends LootableInventory {
+
+    /**
+     * Gets the entity that is lootable
+     * @return The Entity
+     */
+    Entity getEntity();
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/LootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/LootableInventory.java
new file mode 100644
index 0000000..cde999e
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/LootableInventory.java
@@ -0,0 +1,111 @@
+package com.destroystokyo.paper.loottable;
+
+import org.bukkit.entity.Player;
+
+import java.util.UUID;
+
+/**
+ * Represents an Inventory that contains a Loot Table associated to it that will
+ * automatically fill on first open.
+ *
+ * A new feature and API is provided to support automatically refreshing the contents
+ * of the inventory based on that Loot Table after a configurable amount of time has passed.
+ *
+ * The behavior of how the Inventory is filled based on the loot table may vary based
+ * on Minecraft versions and the Loot Table feature.
+ */
+public interface LootableInventory extends Lootable {
+
+    /**
+     * Server owners have to enable whether or not an object in a world should refill
+     *
+     * @return If the world this inventory is currently in has Replenishable Lootables enabled
+     */
+    boolean isRefillEnabled();
+
+    /**
+     * Whether or not this object has ever been filled
+     * @return Has ever been filled
+     */
+    boolean hasBeenFilled();
+
+    /**
+     * Has this player ever looted this block
+     * @param player The player to check
+     * @return Whether or not this player has looted this block
+     */
+    default boolean hasPlayerLooted(Player player) {
+        return hasPlayerLooted(player.getUniqueId());
+    }
+
+    /**
+     * Has this player ever looted this block
+     * @param player The player to check
+     * @return Whether or not this player has looted this block
+     */
+    boolean hasPlayerLooted(UUID player);
+
+    /**
+     * Gets the timestamp, in milliseconds, of when the player last looted this object
+     *
+     * @param player The player to check
+     * @return Timestamp last looted, or null if player has not looted this object
+     */
+    default Long getLastLooted(Player player) {
+        return getLastLooted(player.getUniqueId());
+    }
+
+    /**
+     * Gets the timestamp, in milliseconds, of when the player last looted this object
+     *
+     * @param player The player to check
+     * @return Timestamp last looted, or null if player has not looted this object
+     */
+    Long getLastLooted(UUID player);
+
+    /**
+     * Change the state of whether or not a player has looted this block
+     * @param player The player to change state for
+     * @param looted true to add player to looted list, false to remove
+     * @return The previous state of whether the player had looted this or not
+     */
+    default boolean setHasPlayerLooted(Player player, boolean looted) {
+        return setHasPlayerLooted(player.getUniqueId(), looted);
+    }
+
+    /**
+     * Change the state of whether or not a player has looted this block
+     * @param player The player to change state for
+     * @param looted true to add player to looted list, false to remove
+     * @return The previous state of whether the player had looted this or not
+     */
+    boolean setHasPlayerLooted(UUID player, boolean looted);
+
+    /**
+     * Returns Whether or not this object has been filled and now has a pending refill
+     * @return Has pending refill
+     */
+    boolean hasPendingRefill();
+
+    /**
+     * Gets the timestamp in milliseconds that the Lootable object was last refilled
+     *
+     * @return -1 if it was never refilled, or timestamp in milliseconds
+     */
+    long getLastFilled();
+
+    /**
+     * Gets the timestamp in milliseconds that the Lootable object will refill
+     *
+     * @return -1 if it is not scheduled for refill, or timestamp in milliseconds
+     */
+    long getNextRefill();
+
+    /**
+     * Sets the timestamp in milliseconds of the next refill for this object
+     *
+     * @param refillAt timestamp in milliseconds. -1 to clear next refill
+     * @return The previous scheduled time to refill, or -1 if was not scheduled
+     */
+    long setNextRefill(long refillAt);
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/LootableInventoryReplenishEvent.java b/src/main/java/com/destroystokyo/paper/loottable/LootableInventoryReplenishEvent.java
new file mode 100644
index 0000000..2169493
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/LootableInventoryReplenishEvent.java
@@ -0,0 +1,41 @@
+package com.destroystokyo.paper.loottable;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+
+public class LootableInventoryReplenishEvent extends PlayerEvent implements Cancellable {
+    private final LootableInventory inventory;
+
+    public LootableInventoryReplenishEvent(Player player, LootableInventory inventory) {
+        super(player);
+        this.inventory = inventory;
+    }
+
+    public LootableInventory getInventory() {
+        return inventory;
+    }
+
+    private static final HandlerList handlers = new HandlerList();
+
+    public HandlerList getHandlers() {
+        return handlers;
+    }
+
+    public static HandlerList getHandlerList() {
+        return handlers;
+    }
+
+    private boolean cancelled = false;
+
+    @Override
+    public boolean isCancelled() {
+        return cancelled;
+    }
+
+    @Override
+    public void setCancelled(boolean cancel) {
+        cancelled = cancel;
+    }
+}
diff --git a/src/main/java/org/bukkit/block/Chest.java b/src/main/java/org/bukkit/block/Chest.java
index ee95841..25dfc5f 100644
--- a/src/main/java/org/bukkit/block/Chest.java
+++ b/src/main/java/org/bukkit/block/Chest.java
@@ -1,12 +1,13 @@
 package org.bukkit.block;
 
+import com.destroystokyo.paper.loottable.LootableInventory; // Paper
 import org.bukkit.inventory.Inventory;
 import org.bukkit.inventory.InventoryHolder;
 
 /**
  * Represents a chest.
  */
-public interface Chest extends BlockState, InventoryHolder {
+public interface Chest extends BlockState, InventoryHolder, LootableInventory { // Paper
 
     /**
      * Returns the chest's inventory. If this is a double chest, it returns
diff --git a/src/main/java/org/bukkit/block/Dispenser.java b/src/main/java/org/bukkit/block/Dispenser.java
index 4e6b349..3aa0a81 100644
--- a/src/main/java/org/bukkit/block/Dispenser.java
+++ b/src/main/java/org/bukkit/block/Dispenser.java
@@ -1,12 +1,13 @@
 package org.bukkit.block;
 
+import com.destroystokyo.paper.loottable.LootableInventory; // Paper
 import org.bukkit.inventory.InventoryHolder;
 import org.bukkit.projectiles.BlockProjectileSource;
 
 /**
  * Represents a dispenser.
  */
-public interface Dispenser extends BlockState, InventoryHolder {
+public interface Dispenser extends BlockState, InventoryHolder, LootableInventory { // Paper
 
     /**
      * Gets the BlockProjectileSource object for this dispenser.
diff --git a/src/main/java/org/bukkit/block/Hopper.java b/src/main/java/org/bukkit/block/Hopper.java
index e097157..26aff5a 100644
--- a/src/main/java/org/bukkit/block/Hopper.java
+++ b/src/main/java/org/bukkit/block/Hopper.java
@@ -1,10 +1,11 @@
 package org.bukkit.block;
 
+import com.destroystokyo.paper.loottable.LootableInventory; // Paper
 import org.bukkit.inventory.InventoryHolder;
 
 /**
  * Represents a hopper.
  */
-public interface Hopper extends BlockState, InventoryHolder {
+public interface Hopper extends BlockState, InventoryHolder, LootableInventory { // Paper
 
 }
-- 
2.9.2.windows.1