-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathInventoryConfigGUI.java
51 lines (40 loc) · 1.58 KB
/
InventoryConfigGUI.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
package com.iridium.iridiumteams.gui;
import com.iridium.iridiumcore.gui.GUI;
import com.iridium.iridiumcore.utils.InventoryUtils;
import com.iridium.iridiumcore.utils.ItemStackUtils;
import com.iridium.iridiumcore.utils.StringUtils;
import com.iridium.iridiumteams.configs.inventories.InventoryConfig;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryConfigGUI implements GUI {
private final InventoryConfig inventoryConfig;
public InventoryConfigGUI(InventoryConfig inventoryConfig) {
this.inventoryConfig = inventoryConfig;
}
@NotNull
@Override
public Inventory getInventory() {
Inventory inventory = Bukkit.createInventory(this, inventoryConfig.size, StringUtils.color(inventoryConfig.title));
addContent(inventory);
return inventory;
}
@Override
public void addContent(Inventory inventory) {
InventoryUtils.fillInventory(inventory, inventoryConfig.background);
inventoryConfig.items.values().forEach(item -> {
if(item.slot >= 0) {
inventory.setItem(item.slot, ItemStackUtils.makeItem(item));
}
});
}
@Override
public void onInventoryClick(InventoryClickEvent event) {
for (String command : inventoryConfig.items.keySet()) {
if (inventoryConfig.items.get(command).slot == event.getSlot()) {
Bukkit.getServer().dispatchCommand(event.getWhoClicked(), command);
}
}
}
}