Skip to content

Commit

Permalink
Merge pull request #329 from BetterGUI-MC/up
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer authored Jun 29, 2024
2 parents 91c0501 + aafca1b commit f3a3c8e
Show file tree
Hide file tree
Showing 54 changed files with 576 additions and 847 deletions.
57 changes: 51 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

<properties>
<java.version>1.8</java.version>
<core.version>4.3.30</core.version>
<core.version>4.5.3</core.version>
<minelib.version>1.2.2</minelib.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -60,6 +61,12 @@
<shadedPattern>me.hsgamer.bettergui.lib.core</shadedPattern>
</relocation>

<!-- MineLib -->
<relocation>
<pattern>io.github.projectunified.minelib</pattern>
<shadedPattern>me.hsgamer.bettergui.lib.minelib</shadedPattern>
</relocation>

<!-- bStats -->
<relocation>
<pattern>org.bstats</pattern>
Expand All @@ -77,6 +84,7 @@
<configuration>
<links>
<link>https://hsgamer.github.io/HSCore/</link>
<link>https://projectunified.github.io/MineLib/</link>
</links>
</configuration>
<executions>
Expand Down Expand Up @@ -161,11 +169,6 @@
</dependency>

<!-- HSCore -->
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>hscore-bukkit-baseplugin</artifactId>
<version>${core.version}</version>
</dependency>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>hscore-bukkit-utils</artifactId>
Expand Down Expand Up @@ -201,6 +204,11 @@
<artifactId>hscore-bukkit-variable</artifactId>
<version>${core.version}</version>
</dependency>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>hscore-bukkit-action-builder</artifactId>
<version>${core.version}</version>
</dependency>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>hscore-config-proxy</artifactId>
Expand Down Expand Up @@ -274,6 +282,43 @@
<version>${core.version}</version>
</dependency>

<!-- MineLib -->
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-plugin-base</artifactId>
<version>${minelib.version}</version>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-plugin-command</artifactId>
<version>${minelib.version}</version>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-plugin-permission</artifactId>
<version>${minelib.version}</version>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-plugin-postenable</artifactId>
<version>${minelib.version}</version>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-global</artifactId>
<version>${minelib.version}</version>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-async</artifactId>
<version>${minelib.version}</version>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-entity</artifactId>
<version>${minelib.version}</version>
</dependency>

<!-- Annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down
178 changes: 51 additions & 127 deletions src/main/java/me/hsgamer/bettergui/BetterGUI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package me.hsgamer.bettergui;

import me.hsgamer.bettergui.api.addon.PostEnable;
import io.github.projectunified.minelib.plugin.base.BasePlugin;
import io.github.projectunified.minelib.plugin.command.CommandComponent;
import io.github.projectunified.minelib.plugin.postenable.PostEnable;
import io.github.projectunified.minelib.plugin.postenable.PostEnableComponent;
import me.hsgamer.bettergui.api.menu.Menu;
import me.hsgamer.bettergui.builder.*;
import me.hsgamer.bettergui.command.*;
Expand All @@ -13,7 +16,6 @@
import me.hsgamer.bettergui.manager.MenuManager;
import me.hsgamer.bettergui.papi.ExtraPlaceholderExpansion;
import me.hsgamer.bettergui.util.StringReplacerApplier;
import me.hsgamer.hscore.bukkit.baseplugin.BasePlugin;
import me.hsgamer.hscore.bukkit.config.BukkitConfig;
import me.hsgamer.hscore.bukkit.gui.BukkitGUIListener;
import me.hsgamer.hscore.bukkit.utils.MessageUtils;
Expand All @@ -30,24 +32,13 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* The main class of the plugin
*/
public final class BetterGUI extends BasePlugin {
public final class BetterGUI extends BasePlugin implements PostEnable {
private static final CachedValue<BetterGUI> INSTANCE_CACHE = CachedValue.of(() -> JavaPlugin.getPlugin(BetterGUI.class));
private final MainConfig mainConfig = ConfigGenerator.newInstance(MainConfig.class, new BukkitConfig(this, "config.yml"));
private final MessageConfig messageConfig = ConfigGenerator.newInstance(MessageConfig.class, new BukkitConfig(this, "messages.yml"));
private final TemplateConfig templateButtonConfig = new TemplateConfig(this);
private final MenuManager menuManager = new MenuManager(this);
private final MenuCommandManager menuCommandManager = new MenuCommandManager(this);
private final AddonManager addonManager = new AddonManager(this);
private final AddonDownloader addonDownloader = new AddonDownloader(this);
private final VariableBundle variableBundle = new VariableBundle();

/**
* Get the instance of the plugin
Expand All @@ -59,59 +50,78 @@ public static BetterGUI getInstance() {
}

@Override
public void load() {
MessageUtils.setPrefix(messageConfig::getPrefix);

protected List<Object> getComponents() {
VariableBundle variableBundle = new VariableBundle();
CommonVariableBundle.registerVariables(variableBundle);
BukkitVariableBundle.registerVariables(variableBundle);
variableBundle.register("menu_", StringReplacer.of((original, uuid) -> {
String[] split = original.split("_", 2);
String menuName = split[0].trim();
String variable = split.length > 1 ? split[1].trim() : "";
Menu menu = menuManager.getMenu(menuName);
Menu menu = get(MenuManager.class).getMenu(menuName);
if (menu == null) {
return null;
}
return menu.getVariableManager().setVariables(StringReplacerApplier.normalizeQuery(variable), uuid);
}));
}

@Override
public void enable() {
BukkitGUIListener.init(this);
AddonManager addonManager = new AddonManager(this);
AddonDownloader addonDownloader = new AddonDownloader(this, addonManager);

List<Object> components = new ArrayList<>(Arrays.asList(
variableBundle,

new PostEnableComponent(this),

new Permissions(this),
new CommandComponent(this,
new OpenCommand(this),
new MainCommand(this),
new GetAddonsCommand(this),
new ReloadCommand(this),
new GetVariablesCommand(this),
new GetTemplateButtonsCommand(this)
),

addonManager.loadExpansions();
ConfigGenerator.newInstance(MainConfig.class, new BukkitConfig(this, "config.yml")),
ConfigGenerator.newInstance(MessageConfig.class, new BukkitConfig(this, "messages.yml")),
new TemplateConfig(this),

registerCommand(new OpenCommand(this));
registerCommand(new MainCommand(this));
registerCommand(new GetAddonsCommand(this));
registerCommand(new ReloadCommand(this));
registerCommand(new GetVariablesCommand(this));
registerCommand(new GetTemplateButtonsCommand(this));
addonManager,
new MenuManager(this),
new MenuCommandManager(this),
addonDownloader
));

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
ExtraPlaceholderExpansion expansion = new ExtraPlaceholderExpansion(this);
expansion.register();
addDisableFunction(expansion::unregister);
components.add(new ExtraPlaceholderExpansion(this));
}

return components;
}

@Override
public void load() {
MessageUtils.setPrefix(() -> get(MessageConfig.class).getPrefix());
}

@Override
public void enable() {
BukkitGUIListener.init(this);
}

@Override
public void postEnable() {
addonManager.enableExpansions();
addonDownloader.setup();
templateButtonConfig.setup();
menuManager.loadMenuConfig();
addonManager.call(PostEnable.class, PostEnable::onPostEnable);
get(AddonManager.class).call(me.hsgamer.bettergui.api.addon.PostEnable.class, me.hsgamer.bettergui.api.addon.PostEnable::onPostEnable);

Metrics metrics = new Metrics(this, 6609);
metrics.addCustomChart(new DrilldownPie("addon", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();
Map<String, Integer> addons = addonManager.getExpansionCount();
Map<String, Integer> addons = get(AddonManager.class).getExpansionCount();
map.put(String.valueOf(addons.size()), addons);
return map;
}));
metrics.addCustomChart(new AdvancedPie("addon_count", addonManager::getExpansionCount));
metrics.addCustomChart(new AdvancedPie("addon_count", get(AddonManager.class)::getExpansionCount));

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

@Override
public void disable() {
menuCommandManager.clearMenuCommand();
menuManager.clear();
templateButtonConfig.clear();
addonManager.disableExpansions();
addonManager.clearExpansions();
}

@Override
public void postDisable() {
ActionBuilder.INSTANCE.clear();
ButtonBuilder.INSTANCE.clear();
ItemModifierBuilder.INSTANCE.clear();
MenuBuilder.INSTANCE.clear();
RequirementBuilder.INSTANCE.clear();
variableBundle.unregisterAll();
get(VariableBundle.class).unregisterAll();
INSTANCE_CACHE.clearCache();
}

@Override
protected List<Class<?>> getPermissionClasses() {
return Collections.singletonList(Permissions.class);
}

/**
* Get the main config
*
* @return the main config
*/
public MainConfig getMainConfig() {
return mainConfig;
}

/**
* Get the message config
*
* @return the message config
*/
public MessageConfig getMessageConfig() {
return messageConfig;
}

/**
* Get the template button config
*
* @return the template button config
*/
public TemplateConfig getTemplateButtonConfig() {
return templateButtonConfig;
}

/**
* Get the menu manager
*
* @return the menu manager
*/
public MenuManager getMenuManager() {
return menuManager;
}

/**
* Get the menu command manager
*
* @return the menu command manager
*/
public MenuCommandManager getMenuCommandManager() {
return menuCommandManager;
}

/**
* Get the addon manager
*
* @return the addon manager
*/
public AddonManager getAddonManager() {
return addonManager;
}

/**
* Get the addon downloader
*
* @return the addon downloader
*/
public AddonDownloader getAddonDownloader() {
return addonDownloader;
}

/**
* Get the variable bundle
*
* @return the variable bundle
*/
public VariableBundle getVariableBundle() {
return variableBundle;
}
}
8 changes: 5 additions & 3 deletions src/main/java/me/hsgamer/bettergui/Permissions.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package me.hsgamer.bettergui;

import io.github.projectunified.minelib.plugin.base.BasePlugin;
import io.github.projectunified.minelib.plugin.permission.PermissionComponent;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;

public final class Permissions {
public final class Permissions extends PermissionComponent {

public static final String PREFIX = "bettergui";

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

private Permissions() {

public Permissions(BasePlugin plugin) {
super(plugin);
}
}
Loading

0 comments on commit f3a3c8e

Please sign in to comment.