/
MenuIslandChest.java
107 lines (83 loc) · 4.52 KB
/
MenuIslandChest.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.bgsoftware.superiorskyblock.core.menu.impl;
import com.bgsoftware.common.config.CommentedConfiguration;
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.island.IslandChest;
import com.bgsoftware.superiorskyblock.api.menu.ISuperiorMenu;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.core.SequentialListBuilder;
import com.bgsoftware.superiorskyblock.core.io.MenuParser;
import com.bgsoftware.superiorskyblock.core.logging.Log;
import com.bgsoftware.superiorskyblock.core.menu.MenuParseResult;
import com.bgsoftware.superiorskyblock.core.menu.MenuPatternSlots;
import com.bgsoftware.superiorskyblock.core.menu.PagedSuperiorMenu;
import com.bgsoftware.superiorskyblock.core.menu.SuperiorMenu;
import com.bgsoftware.superiorskyblock.core.menu.button.impl.menu.IslandChestPagedObjectButton;
import com.bgsoftware.superiorskyblock.core.menu.pattern.impl.PagedMenuPattern;
import org.bukkit.configuration.ConfigurationSection;
import java.util.Arrays;
import java.util.List;
public class MenuIslandChest extends PagedSuperiorMenu<MenuIslandChest, IslandChest> {
private static final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin();
private static PagedMenuPattern<MenuIslandChest, IslandChest> menuPattern;
private final Island island;
private MenuIslandChest(SuperiorPlayer superiorPlayer, Island island) {
super(menuPattern, superiorPlayer);
this.island = island;
}
public Island getTargetIsland() {
return island;
}
@Override
public void cloneAndOpen(ISuperiorMenu previousMenu) {
openInventory(inventoryViewer, previousMenu, island);
}
@Override
protected List<IslandChest> requestObjects() {
return new SequentialListBuilder<IslandChest>()
.build(Arrays.asList(island.getChest()));
}
public static void init() {
menuPattern = null;
PagedMenuPattern.Builder<MenuIslandChest, IslandChest> patternBuilder = new PagedMenuPattern.Builder<>();
MenuParseResult menuLoadResult = MenuParser.loadMenu(patternBuilder, "island-chest.yml", null);
if (menuLoadResult == null)
return;
MenuPatternSlots menuPatternSlots = menuLoadResult.getPatternSlots();
CommentedConfiguration cfg = menuLoadResult.getConfig();
if (cfg.isString("slots")) {
for (char slotChar : cfg.getString("slots", "").toCharArray()) {
List<Integer> slots = menuPatternSlots.getSlots(slotChar);
ConfigurationSection validPageSection = cfg.getConfigurationSection("items." + slotChar + ".valid-page");
ConfigurationSection invalidPageSection = cfg.getConfigurationSection("items." + slotChar + ".invalid-page");
if (validPageSection == null) {
Log.warnFromFile("island-chest.yml", "The slot char ", slotChar, " is missing the valid-page section.");
continue;
}
if (invalidPageSection == null) {
Log.warnFromFile("island-chest.yml", "&cThe slot char ", slotChar, " is missing the invalid-page section.");
continue;
}
patternBuilder.mapButtons(slots, new IslandChestPagedObjectButton.Builder()
.setButtonItem(MenuParser.getItemStack("island-chest.yml", validPageSection))
.setNullItem(MenuParser.getItemStack("island-chest.yml", invalidPageSection)));
}
}
menuPattern = patternBuilder
.setPreviousPageSlots(getSlots(cfg, "previous-page", menuPatternSlots))
.setCurrentPageSlots(getSlots(cfg, "current-page", menuPatternSlots))
.setNextPageSlots(getSlots(cfg, "next-page", menuPatternSlots))
.build();
}
public static void openInventory(SuperiorPlayer superiorPlayer, ISuperiorMenu previousMenu, Island island) {
MenuIslandChest menuIslandChest = new MenuIslandChest(superiorPlayer, island);
if (plugin.getSettings().isSkipOneItemMenus() && island.getChest().length == 1) {
island.getChest()[0].openChest(superiorPlayer);
} else {
menuIslandChest.open(previousMenu);
}
}
public static void refreshMenus(Island island) {
SuperiorMenu.refreshMenus(MenuIslandChest.class, superiorMenu -> superiorMenu.island.equals(island));
}
}