-
Notifications
You must be signed in to change notification settings - Fork 658
Expand file tree
/
Copy pathSlimefunItemSpawnEvent.java
More file actions
131 lines (110 loc) · 3.75 KB
/
Copy pathSlimefunItemSpawnEvent.java
File metadata and controls
131 lines (110 loc) · 3.75 KB
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
package io.github.thebusybiscuit.slimefun4.api.events;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import com.google.common.base.Preconditions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSpawnReason;
/**
* This {@link Event} is fired whenever slimefun drops an {@link ItemStack}.
* Creating a custom {@link Event} for this allows other plugins to provide
* compatibility with auto-pickup options or similar.
*
* @author TheBusyBiscuit
*
* @see ItemSpawnReason
*/
public class SlimefunItemSpawnEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private Location location;
private ItemStack itemStack;
private boolean cancelled;
private final ItemSpawnReason itemSpawnReason;
private final Player player;
@ParametersAreNonnullByDefault
public SlimefunItemSpawnEvent(@Nullable Player player, Location location, ItemStack itemStack, ItemSpawnReason itemSpawnReason) {
this.location = location;
this.itemStack = itemStack;
this.itemSpawnReason = itemSpawnReason;
this.cancelled = false;
this.player = player;
}
@ParametersAreNonnullByDefault
public SlimefunItemSpawnEvent(Location location, ItemStack itemStack, ItemSpawnReason itemSpawnReason) {
this(null, location, itemStack, itemSpawnReason);
}
/**
* Optionally returns the {@link Player} responsible for this spawn reason.
*
* @return The player responsible if applicable.
*/
public @Nonnull Optional<Player> getPlayer() {
return Optional.ofNullable(player);
}
/**
* This returns the {@link ItemSpawnReason} why we dropped an {@link ItemStack}.
*
* @return the {@link ItemSpawnReason}.
*/
public @Nonnull ItemSpawnReason getItemSpawnReason() {
return itemSpawnReason;
}
/**
* This returns the {@link Location} where we will drop the item.
*
* @return The {@link Location} where the item will be dropped
*/
public @Nonnull Location getLocation() {
return location;
}
/**
* This sets the {@link Location} on where to drop this item.
*
* @param location
* The {@link Location} where to drop the {@link ItemStack}
*/
public void setLocation(@Nonnull Location location) {
Preconditions.checkNotNull(location, "The Location cannot be null!");
this.location = location;
}
/**
* This returns the {@link ItemStack} that will be dropped.
*
* @return The {@link ItemStack} that will be dropped
*/
public @Nonnull ItemStack getItemStack() {
return itemStack;
}
/**
* This method sets the {@link ItemStack} that should be dropped.
*
* @param itemStack
* The {@link ItemStack} to drop
*/
public void setItemStack(@Nonnull ItemStack itemStack) {
Preconditions.checkNotNull(itemStack, "Cannot drop null.");
Preconditions.checkArgument(!itemStack.getType().isAir(), "Cannot drop air.");
this.itemStack = itemStack;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public static @Nonnull HandlerList getHandlerList() {
return handlers;
}
@Override
public @Nonnull HandlerList getHandlers() {
return getHandlerList();
}
}