-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathZKit.java
More file actions
207 lines (171 loc) · 5.76 KB
/
Copy pathZKit.java
File metadata and controls
207 lines (171 loc) · 5.76 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
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
package fr.maxlego08.essentials.module.modules.kit;
import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.api.kit.Kit;
import fr.maxlego08.essentials.zutils.utils.ZUtils;
import fr.maxlego08.menu.api.MenuItemStack;
import fr.maxlego08.menu.api.requirement.Action;
import fr.maxlego08.menu.api.utils.Placeholders;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.permissions.Permissible;
import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class ZKit extends ZUtils implements Kit {
private final EssentialsPlugin plugin;
private final String displayName;
private final String name;
private final String permission;
private final String category;
private final String subCategory;
private final long cooldown;
private final Map<String, Long> permissionCooldowns;
private final List<Action> actions;
private final File file;
private List<MenuItemStack> menuItemStacks;
private MenuItemStack helmet;
private MenuItemStack chestplate;
private MenuItemStack leggings;
private MenuItemStack boots;
public ZKit(EssentialsPlugin plugin, String displayName, String name, String category, String subCategory, long cooldown, Map<String, Long> permissionCooldowns, List<MenuItemStack> menuItemStacks, List<Action> actions, String permission, File file) {
this.plugin = plugin;
this.displayName = displayName;
this.name = name;
this.category = category;
this.subCategory = subCategory;
this.cooldown = cooldown;
this.permissionCooldowns = permissionCooldowns;
this.menuItemStacks = menuItemStacks;
this.actions = actions;
this.permission = permission;
this.file = file;
}
@Override
public long getCooldown(Permissible permissible) {
long currentCooldown = this.cooldown;
for (Map.Entry<String, Long> entry : this.permissionCooldowns.entrySet()) {
if (permissible.hasPermission(entry.getKey())) {
currentCooldown = Math.min(currentCooldown, entry.getValue());
}
}
return currentCooldown;
}
@Override
public long getCooldown() {
return cooldown;
}
@Override
public Map<String, Long> getPermissionCooldowns() {
return permissionCooldowns;
}
@Override
public String getName() {
return name;
}
@Override
public String getDisplayName() {
return this.displayName;
}
@Override
public List<MenuItemStack> getMenuItemStacks() {
return menuItemStacks;
}
public void setMenuItemStacks(List<MenuItemStack> menuItemStacks) {
this.menuItemStacks = menuItemStacks;
}
@Override
public void give(Player player) {
this.menuItemStacks.forEach(menuItemStack -> this.plugin.give(player, menuItemStack.build(player, false)));
var fakeInventory = this.plugin.getInventoryManager().getFakeInventory();
actions.forEach(action -> action.preExecute(player, null, fakeInventory, new Placeholders()));
this.equip(player, helmet, EquipmentSlot.HEAD);
this.equip(player, chestplate, EquipmentSlot.CHEST);
this.equip(player, leggings, EquipmentSlot.LEGS);
this.equip(player, boots, EquipmentSlot.FEET);
}
private void equip(Player player, MenuItemStack menuItemStack, EquipmentSlot equipmentSlot) {
if (menuItemStack == null) return;
var itemStack = menuItemStack.build(player, false);
var inventory = player.getInventory();
if (inventory.getItem(equipmentSlot).getType().isAir()) {
inventory.setItem(equipmentSlot, itemStack);
} else {
plugin.give(player, itemStack);
}
}
@Override
public void setItems(List<MenuItemStack> menuItemStacks) {
this.menuItemStacks = menuItemStacks;
}
@Override
public List<Action> getActions() {
return actions;
}
@Override
public boolean hasPermission(Permissible permissible) {
if (this.permission == null || this.permission.isEmpty()) {
return true;
}
if (permissible.hasPermission(Permission.ESSENTIALS_KIT.asPermission())) {
return true;
}
if (permissible.hasPermission(this.permission)) {
return true;
}
return permissible.hasPermission(Permission.ESSENTIALS_KIT_.asPermission(this.name.toLowerCase(Locale.ROOT)));
}
@Override
public String getPermission() {
return this.permission;
}
@Override
public File getFile() {
return this.file;
}
@Override
public MenuItemStack getHelmet() {
return helmet;
}
public void setHelmet(MenuItemStack helmet) {
this.helmet = helmet;
}
@Override
public MenuItemStack getChestplate() {
return chestplate;
}
public void setChestplate(MenuItemStack chestplate) {
this.chestplate = chestplate;
}
@Override
public MenuItemStack getLeggings() {
return leggings;
}
public void setLeggings(MenuItemStack leggings) {
this.leggings = leggings;
}
@Override
public MenuItemStack getBoots() {
return boots;
}
public void setBoots(MenuItemStack boots) {
this.boots = boots;
}
@Override
public String getCategory() {
return this.category;
}
@Override
public String getSubCategory() {
return this.subCategory;
}
@Override
public boolean hasCategory() {
return this.category != null;
}
@Override
public boolean hasSubCategory() {
return this.subCategory != null;
}
}