Skip to content

Commit f3a3c8e

Browse files
authored
Merge pull request #329 from BetterGUI-MC/up
2 parents 91c0501 + aafca1b commit f3a3c8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+576
-847
lines changed

pom.xml

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
<properties>
1717
<java.version>1.8</java.version>
18-
<core.version>4.3.30</core.version>
18+
<core.version>4.5.3</core.version>
19+
<minelib.version>1.2.2</minelib.version>
1920
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2021
</properties>
2122

@@ -60,6 +61,12 @@
6061
<shadedPattern>me.hsgamer.bettergui.lib.core</shadedPattern>
6162
</relocation>
6263

64+
<!-- MineLib -->
65+
<relocation>
66+
<pattern>io.github.projectunified.minelib</pattern>
67+
<shadedPattern>me.hsgamer.bettergui.lib.minelib</shadedPattern>
68+
</relocation>
69+
6370
<!-- bStats -->
6471
<relocation>
6572
<pattern>org.bstats</pattern>
@@ -77,6 +84,7 @@
7784
<configuration>
7885
<links>
7986
<link>https://hsgamer.github.io/HSCore/</link>
87+
<link>https://projectunified.github.io/MineLib/</link>
8088
</links>
8189
</configuration>
8290
<executions>
@@ -161,11 +169,6 @@
161169
</dependency>
162170

163171
<!-- HSCore -->
164-
<dependency>
165-
<groupId>me.hsgamer</groupId>
166-
<artifactId>hscore-bukkit-baseplugin</artifactId>
167-
<version>${core.version}</version>
168-
</dependency>
169172
<dependency>
170173
<groupId>me.hsgamer</groupId>
171174
<artifactId>hscore-bukkit-utils</artifactId>
@@ -201,6 +204,11 @@
201204
<artifactId>hscore-bukkit-variable</artifactId>
202205
<version>${core.version}</version>
203206
</dependency>
207+
<dependency>
208+
<groupId>me.hsgamer</groupId>
209+
<artifactId>hscore-bukkit-action-builder</artifactId>
210+
<version>${core.version}</version>
211+
</dependency>
204212
<dependency>
205213
<groupId>me.hsgamer</groupId>
206214
<artifactId>hscore-config-proxy</artifactId>
@@ -274,6 +282,43 @@
274282
<version>${core.version}</version>
275283
</dependency>
276284

285+
<!-- MineLib -->
286+
<dependency>
287+
<groupId>io.github.projectunified</groupId>
288+
<artifactId>minelib-plugin-base</artifactId>
289+
<version>${minelib.version}</version>
290+
</dependency>
291+
<dependency>
292+
<groupId>io.github.projectunified</groupId>
293+
<artifactId>minelib-plugin-command</artifactId>
294+
<version>${minelib.version}</version>
295+
</dependency>
296+
<dependency>
297+
<groupId>io.github.projectunified</groupId>
298+
<artifactId>minelib-plugin-permission</artifactId>
299+
<version>${minelib.version}</version>
300+
</dependency>
301+
<dependency>
302+
<groupId>io.github.projectunified</groupId>
303+
<artifactId>minelib-plugin-postenable</artifactId>
304+
<version>${minelib.version}</version>
305+
</dependency>
306+
<dependency>
307+
<groupId>io.github.projectunified</groupId>
308+
<artifactId>minelib-scheduler-global</artifactId>
309+
<version>${minelib.version}</version>
310+
</dependency>
311+
<dependency>
312+
<groupId>io.github.projectunified</groupId>
313+
<artifactId>minelib-scheduler-async</artifactId>
314+
<version>${minelib.version}</version>
315+
</dependency>
316+
<dependency>
317+
<groupId>io.github.projectunified</groupId>
318+
<artifactId>minelib-scheduler-entity</artifactId>
319+
<version>${minelib.version}</version>
320+
</dependency>
321+
277322
<!-- Annotations -->
278323
<dependency>
279324
<groupId>org.jetbrains</groupId>
Lines changed: 51 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package me.hsgamer.bettergui;
22

3-
import me.hsgamer.bettergui.api.addon.PostEnable;
3+
import io.github.projectunified.minelib.plugin.base.BasePlugin;
4+
import io.github.projectunified.minelib.plugin.command.CommandComponent;
5+
import io.github.projectunified.minelib.plugin.postenable.PostEnable;
6+
import io.github.projectunified.minelib.plugin.postenable.PostEnableComponent;
47
import me.hsgamer.bettergui.api.menu.Menu;
58
import me.hsgamer.bettergui.builder.*;
69
import me.hsgamer.bettergui.command.*;
@@ -13,7 +16,6 @@
1316
import me.hsgamer.bettergui.manager.MenuManager;
1417
import me.hsgamer.bettergui.papi.ExtraPlaceholderExpansion;
1518
import me.hsgamer.bettergui.util.StringReplacerApplier;
16-
import me.hsgamer.hscore.bukkit.baseplugin.BasePlugin;
1719
import me.hsgamer.hscore.bukkit.config.BukkitConfig;
1820
import me.hsgamer.hscore.bukkit.gui.BukkitGUIListener;
1921
import me.hsgamer.hscore.bukkit.utils.MessageUtils;
@@ -30,24 +32,13 @@
3032
import org.bukkit.Bukkit;
3133
import org.bukkit.plugin.java.JavaPlugin;
3234

33-
import java.util.Collections;
34-
import java.util.HashMap;
35-
import java.util.List;
36-
import java.util.Map;
35+
import java.util.*;
3736

3837
/**
3938
* The main class of the plugin
4039
*/
41-
public final class BetterGUI extends BasePlugin {
40+
public final class BetterGUI extends BasePlugin implements PostEnable {
4241
private static final CachedValue<BetterGUI> INSTANCE_CACHE = CachedValue.of(() -> JavaPlugin.getPlugin(BetterGUI.class));
43-
private final MainConfig mainConfig = ConfigGenerator.newInstance(MainConfig.class, new BukkitConfig(this, "config.yml"));
44-
private final MessageConfig messageConfig = ConfigGenerator.newInstance(MessageConfig.class, new BukkitConfig(this, "messages.yml"));
45-
private final TemplateConfig templateButtonConfig = new TemplateConfig(this);
46-
private final MenuManager menuManager = new MenuManager(this);
47-
private final MenuCommandManager menuCommandManager = new MenuCommandManager(this);
48-
private final AddonManager addonManager = new AddonManager(this);
49-
private final AddonDownloader addonDownloader = new AddonDownloader(this);
50-
private final VariableBundle variableBundle = new VariableBundle();
5142

5243
/**
5344
* Get the instance of the plugin
@@ -59,59 +50,78 @@ public static BetterGUI getInstance() {
5950
}
6051

6152
@Override
62-
public void load() {
63-
MessageUtils.setPrefix(messageConfig::getPrefix);
64-
53+
protected List<Object> getComponents() {
54+
VariableBundle variableBundle = new VariableBundle();
6555
CommonVariableBundle.registerVariables(variableBundle);
6656
BukkitVariableBundle.registerVariables(variableBundle);
6757
variableBundle.register("menu_", StringReplacer.of((original, uuid) -> {
6858
String[] split = original.split("_", 2);
6959
String menuName = split[0].trim();
7060
String variable = split.length > 1 ? split[1].trim() : "";
71-
Menu menu = menuManager.getMenu(menuName);
61+
Menu menu = get(MenuManager.class).getMenu(menuName);
7262
if (menu == null) {
7363
return null;
7464
}
7565
return menu.getVariableManager().setVariables(StringReplacerApplier.normalizeQuery(variable), uuid);
7666
}));
77-
}
7867

79-
@Override
80-
public void enable() {
81-
BukkitGUIListener.init(this);
68+
AddonManager addonManager = new AddonManager(this);
69+
AddonDownloader addonDownloader = new AddonDownloader(this, addonManager);
70+
71+
List<Object> components = new ArrayList<>(Arrays.asList(
72+
variableBundle,
73+
74+
new PostEnableComponent(this),
75+
76+
new Permissions(this),
77+
new CommandComponent(this,
78+
new OpenCommand(this),
79+
new MainCommand(this),
80+
new GetAddonsCommand(this),
81+
new ReloadCommand(this),
82+
new GetVariablesCommand(this),
83+
new GetTemplateButtonsCommand(this)
84+
),
8285

83-
addonManager.loadExpansions();
86+
ConfigGenerator.newInstance(MainConfig.class, new BukkitConfig(this, "config.yml")),
87+
ConfigGenerator.newInstance(MessageConfig.class, new BukkitConfig(this, "messages.yml")),
88+
new TemplateConfig(this),
8489

85-
registerCommand(new OpenCommand(this));
86-
registerCommand(new MainCommand(this));
87-
registerCommand(new GetAddonsCommand(this));
88-
registerCommand(new ReloadCommand(this));
89-
registerCommand(new GetVariablesCommand(this));
90-
registerCommand(new GetTemplateButtonsCommand(this));
90+
addonManager,
91+
new MenuManager(this),
92+
new MenuCommandManager(this),
93+
addonDownloader
94+
));
9195

9296
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
93-
ExtraPlaceholderExpansion expansion = new ExtraPlaceholderExpansion(this);
94-
expansion.register();
95-
addDisableFunction(expansion::unregister);
97+
components.add(new ExtraPlaceholderExpansion(this));
9698
}
99+
100+
return components;
101+
}
102+
103+
@Override
104+
public void load() {
105+
MessageUtils.setPrefix(() -> get(MessageConfig.class).getPrefix());
106+
}
107+
108+
@Override
109+
public void enable() {
110+
BukkitGUIListener.init(this);
97111
}
98112

99113
@Override
100114
public void postEnable() {
101-
addonManager.enableExpansions();
102-
addonDownloader.setup();
103-
templateButtonConfig.setup();
104-
menuManager.loadMenuConfig();
105-
addonManager.call(PostEnable.class, PostEnable::onPostEnable);
115+
get(AddonManager.class).call(me.hsgamer.bettergui.api.addon.PostEnable.class, me.hsgamer.bettergui.api.addon.PostEnable::onPostEnable);
106116

107117
Metrics metrics = new Metrics(this, 6609);
108118
metrics.addCustomChart(new DrilldownPie("addon", () -> {
109119
Map<String, Map<String, Integer>> map = new HashMap<>();
110-
Map<String, Integer> addons = addonManager.getExpansionCount();
120+
Map<String, Integer> addons = get(AddonManager.class).getExpansionCount();
111121
map.put(String.valueOf(addons.size()), addons);
112122
return map;
113123
}));
114-
metrics.addCustomChart(new AdvancedPie("addon_count", addonManager::getExpansionCount));
124+
metrics.addCustomChart(new AdvancedPie("addon_count", get(AddonManager.class)::getExpansionCount));
115125

116126
if (getDescription().getVersion().contains("SNAPSHOT")) {
117127
getLogger().warning("You are using the development version");
@@ -133,98 +143,12 @@ public void postEnable() {
133143

134144
@Override
135145
public void disable() {
136-
menuCommandManager.clearMenuCommand();
137-
menuManager.clear();
138-
templateButtonConfig.clear();
139-
addonManager.disableExpansions();
140-
addonManager.clearExpansions();
141-
}
142-
143-
@Override
144-
public void postDisable() {
145146
ActionBuilder.INSTANCE.clear();
146147
ButtonBuilder.INSTANCE.clear();
147148
ItemModifierBuilder.INSTANCE.clear();
148149
MenuBuilder.INSTANCE.clear();
149150
RequirementBuilder.INSTANCE.clear();
150-
variableBundle.unregisterAll();
151+
get(VariableBundle.class).unregisterAll();
151152
INSTANCE_CACHE.clearCache();
152153
}
153-
154-
@Override
155-
protected List<Class<?>> getPermissionClasses() {
156-
return Collections.singletonList(Permissions.class);
157-
}
158-
159-
/**
160-
* Get the main config
161-
*
162-
* @return the main config
163-
*/
164-
public MainConfig getMainConfig() {
165-
return mainConfig;
166-
}
167-
168-
/**
169-
* Get the message config
170-
*
171-
* @return the message config
172-
*/
173-
public MessageConfig getMessageConfig() {
174-
return messageConfig;
175-
}
176-
177-
/**
178-
* Get the template button config
179-
*
180-
* @return the template button config
181-
*/
182-
public TemplateConfig getTemplateButtonConfig() {
183-
return templateButtonConfig;
184-
}
185-
186-
/**
187-
* Get the menu manager
188-
*
189-
* @return the menu manager
190-
*/
191-
public MenuManager getMenuManager() {
192-
return menuManager;
193-
}
194-
195-
/**
196-
* Get the menu command manager
197-
*
198-
* @return the menu command manager
199-
*/
200-
public MenuCommandManager getMenuCommandManager() {
201-
return menuCommandManager;
202-
}
203-
204-
/**
205-
* Get the addon manager
206-
*
207-
* @return the addon manager
208-
*/
209-
public AddonManager getAddonManager() {
210-
return addonManager;
211-
}
212-
213-
/**
214-
* Get the addon downloader
215-
*
216-
* @return the addon downloader
217-
*/
218-
public AddonDownloader getAddonDownloader() {
219-
return addonDownloader;
220-
}
221-
222-
/**
223-
* Get the variable bundle
224-
*
225-
* @return the variable bundle
226-
*/
227-
public VariableBundle getVariableBundle() {
228-
return variableBundle;
229-
}
230154
}

src/main/java/me/hsgamer/bettergui/Permissions.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package me.hsgamer.bettergui;
22

3+
import io.github.projectunified.minelib.plugin.base.BasePlugin;
4+
import io.github.projectunified.minelib.plugin.permission.PermissionComponent;
35
import org.bukkit.permissions.Permission;
46
import org.bukkit.permissions.PermissionDefault;
57

6-
public final class Permissions {
8+
public final class Permissions extends PermissionComponent {
79

810
public static final String PREFIX = "bettergui";
911

@@ -15,7 +17,7 @@ public final class Permissions {
1517
public static final Permission TEMPLATE_BUTTON = new Permission(PREFIX + ".templatebuttons", PermissionDefault.OP);
1618
public static final Permission OPEN_MENU_BYPASS = new Permission(PREFIX + ".openmenu.bypass", PermissionDefault.OP);
1719

18-
private Permissions() {
19-
20+
public Permissions(BasePlugin plugin) {
21+
super(plugin);
2022
}
2123
}

0 commit comments

Comments
 (0)