-
Notifications
You must be signed in to change notification settings - Fork 16
/
AsyncPlayerTreeFallEvent.java
92 lines (71 loc) · 2.39 KB
/
AsyncPlayerTreeFallEvent.java
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
package com.syntaxphoenix.spigot.smoothtimber.event;
import java.util.EnumMap;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import com.syntaxphoenix.spigot.smoothtimber.version.manager.VersionChanger;
import com.syntaxphoenix.spigot.smoothtimber.version.manager.WoodType;
public class AsyncPlayerTreeFallEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final EnumMap<WoodType, Integer> chopped = new EnumMap<>(WoodType.class);
private final Player player;
private final Location treeLocation;
private final VersionChanger versionChange;
private final ItemStack toolStack;
private boolean locked = false;
private int amount = 0;
public AsyncPlayerTreeFallEvent(final Player player, final Location treeLocation, final VersionChanger version, final ItemStack tool) {
super(true);
this.player = player;
this.treeLocation = treeLocation;
this.versionChange = version;
this.toolStack = tool.clone();
}
public final boolean add(final WoodType type) {
if (locked || type == null || !versionChange.isSupported(type)) {
return false;
}
chopped.put(type, chopped.getOrDefault(type, 0) + 1);
return true;
}
public final AsyncPlayerTreeFallEvent lock() {
if (!locked) {
locked = true;
amount = 0;
for (final Integer current : chopped.values()) {
amount += current;
}
}
return this;
}
public final Player getPlayer() {
return player;
}
public final int getTotalAmount() {
return amount;
}
public final int getAmount(final WoodType type) {
return chopped.getOrDefault(type, 0);
}
public final WoodType[] getTypes() {
return chopped.keySet().toArray(new WoodType[0]);
}
public final ItemStack getToolStack() {
return toolStack;
}
public final Location getTreeLocation() {
return treeLocation;
}
public final VersionChanger getVersionUtil() {
return versionChange;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}