Commits

Shreyas Ayyengar authored and md_5 committed 6b3c241bc04
SPIGOT-7783, SPIGOT-7784, #1051: Add Trial Vault & Spawner event API
No tags

src/main/java/org/bukkit/event/block/BlockDispenseLootEvent.java

Added
1 +package org.bukkit.event.block;
2 +
3 +import java.util.ArrayList;
4 +import java.util.List;
5 +import org.bukkit.block.Block;
6 +import org.bukkit.entity.Player;
7 +import org.bukkit.event.Cancellable;
8 +import org.bukkit.event.HandlerList;
9 +import org.bukkit.inventory.ItemStack;
10 +import org.jetbrains.annotations.ApiStatus;
11 +import org.jetbrains.annotations.NotNull;
12 +import org.jetbrains.annotations.Nullable;
13 +
14 +/**
15 + * Called when a block dispenses loot from its designated LootTable. This is not
16 + * to be confused with events like {@link BlockDispenseEvent} which fires when a
17 + * singular item is dispensed from its inventory container.
18 + * <br><br>
19 + * Example: A player unlocks a trial chamber vault and the vault block dispenses
20 + * its loot.
21 + */
22 +@ApiStatus.Experimental
23 +public class BlockDispenseLootEvent extends BlockEvent implements Cancellable {
24 +
25 + private static final HandlerList handlers = new HandlerList();
26 + private final Player player;
27 + private List<ItemStack> dispensedLoot;
28 + private boolean cancelled;
29 +
30 + public BlockDispenseLootEvent(@Nullable Player player, @NotNull Block theBlock, @NotNull List<ItemStack> dispensedLoot) {
31 + super(theBlock);
32 + this.player = player;
33 + this.block = theBlock;
34 + this.dispensedLoot = dispensedLoot;
35 + }
36 +
37 + /**
38 + * Gets the loot that will be dispensed.
39 + *
40 + * @return the loot that will be dispensed
41 + */
42 + @NotNull
43 + public List<ItemStack> getDispensedLoot() {
44 + return dispensedLoot;
45 + }
46 +
47 + /**
48 + * Sets the loot that will be dispensed.
49 + *
50 + * @param dispensedLoot new loot to dispense
51 + */
52 + public void setDispensedLoot(@Nullable List<ItemStack> dispensedLoot) {
53 + this.dispensedLoot = (dispensedLoot == null) ? new ArrayList<>() : dispensedLoot;
54 + }
55 +
56 + /**
57 + * Gets the player associated with this event.
58 + * <br>
59 + * <b>Warning:</b> Some event instances like a
60 + * {@link org.bukkit.block.TrialSpawner} dispensing its reward loot may not
61 + * have a player associated with them and will return null.
62 + *
63 + * @return the player who unlocked the vault
64 + */
65 + @Nullable
66 + public Player getPlayer() {
67 + return player;
68 + }
69 +
70 + @Override
71 + public boolean isCancelled() {
72 + return cancelled;
73 + }
74 +
75 + @Override
76 + public void setCancelled(boolean cancelled) {
77 + this.cancelled = cancelled;
78 + }
79 +
80 + @NotNull
81 + @Override
82 + public HandlerList getHandlers() {
83 + return handlers;
84 + }
85 +
86 + @NotNull
87 + public static HandlerList getHandlerList() {
88 + return handlers;
89 + }
90 +}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut