-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathButtonWarp.java
More file actions
54 lines (43 loc) · 1.75 KB
/
Copy pathButtonWarp.java
File metadata and controls
54 lines (43 loc) · 1.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
package fr.maxlego08.essentials.buttons;
import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.user.User;
import fr.maxlego08.essentials.api.utils.Warp;
import fr.maxlego08.essentials.module.modules.WarpModule;
import fr.maxlego08.menu.api.utils.Placeholders;
import fr.maxlego08.menu.api.button.Button;
import fr.maxlego08.menu.api.engine.InventoryEngine;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import java.util.Optional;
public class ButtonWarp extends Button {
private final EssentialsPlugin plugin;
private final String warpName;
public ButtonWarp(EssentialsPlugin plugin, String warpName) {
this.plugin = plugin;
this.warpName = warpName;
}
@Override
public void onClick(Player player, InventoryClickEvent event, InventoryEngine inventory, int slot, Placeholders placeholders) {
super.onClick(player, event, inventory, slot, placeholders);
WarpModule module = this.plugin.getModuleManager().getModule(WarpModule.class);
User user = this.plugin.getStorageManager().getStorage().getUser(player.getUniqueId());
if (user == null) return;
module.teleport(user, this.warpName);
}
@Override
public boolean closeInventory() {
return true;
}
@Override
public boolean hasPermission() {
return true;
}
@Override
public boolean checkPermission(Player player, InventoryEngine inventory, Placeholders placeholders) {
Optional<Warp> optional = plugin.getWarp(this.warpName);
if (optional.isEmpty() || !optional.get().hasPermission(player)) {
return false;
}
return super.checkPermission(player, inventory, placeholders);
}
}