Files
MaxShopGUI-1.5.8-source
Code
20 3,109
MaxShopGUI-1.5.8-source/MaxShopGUI-1.5.8/src/main/java/com/maxpro/maxshopgui/MaxShopGUI.java
package com.maxpro.maxshopgui;
import com.maxpro.maxshopgui.command.AdminCommand;
import com.maxpro.maxshopgui.command.BalanceCommand;
import com.maxpro.maxshopgui.command.PayCommand;
import com.maxpro.maxshopgui.command.SellCommand;
import com.maxpro.maxshopgui.command.SpawnerGiveCommand;
import com.maxpro.maxshopgui.command.ShopCommand;
import com.maxpro.maxshopgui.economy.EconomyManager;
import com.maxpro.maxshopgui.gui.GUIListener;
import com.maxpro.maxshopgui.shop.ShopManager;
import com.maxpro.maxshopgui.spawner.MoneySpawnerManager;
import com.maxpro.maxshopgui.spawner.SpawnerListener;
import com.maxpro.maxshopgui.spawner.SpawnerLootManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
public final class MaxShopGUI extends JavaPlugin {
private EconomyManager economy;
private ShopManager shop;
private MoneySpawnerManager spawners;
private SpawnerLootManager spawnerLoot;
@Override
public void onEnable() {
saveDefaultConfig();
mergeMissingDefaults();
economy = new EconomyManager(this);
shop = new ShopManager(this);
spawnerLoot = new SpawnerLootManager(this);
spawners = new MoneySpawnerManager(this);
getCommand("shop").setExecutor(new ShopCommand(this));
getCommand("sell").setExecutor(new SellCommand(this));
getCommand("balance").setExecutor(new BalanceCommand(this));
getCommand("pay").setExecutor(new PayCommand(this));
getCommand("maxshop").setExecutor(new AdminCommand(this));
getCommand("give").setExecutor(new SpawnerGiveCommand(this));
getCommand("give").setTabCompleter(new SpawnerGiveCommand(this));
getServer().getPluginManager().registerEvents(new GUIListener(this), this);
getServer().getPluginManager().registerEvents(new SpawnerListener(this), this);
getLogger().info("MaxShopGUI 1.5.8 enabled.");
}
/** Adds new shop/spawner settings from the bundled config without deleting existing server prices. */
private void mergeMissingDefaults() {
if (getResource("config.yml") == null) return;
YamlConfiguration defaults = YamlConfiguration.loadConfiguration(
new java.io.InputStreamReader(getResource("config.yml"), java.nio.charset.StandardCharsets.UTF_8));
mergeSection(defaults, defaults.getKeys(false), "");
saveConfig();
}
private void mergeSection(YamlConfiguration defaults, java.util.Set<String> keys, String path) {
for (String key : keys) {
String child = path.isEmpty() ? key : path + "." + key;
ConfigurationSection childSection = defaults.getConfigurationSection(child);
if (childSection != null) {
mergeSection(defaults, childSection.getKeys(false), child);
} else if (!getConfig().contains(child)) {
getConfig().set(child, defaults.get(child));
}
}
}
@Override
public void onDisable() {
if (spawners != null) spawners.stop();
if (spawnerLoot != null) spawnerLoot.save();
if (economy != null) economy.save();
}
public EconomyManager economy() { return economy; }
public ShopManager shop() { return shop; }
public MoneySpawnerManager spawners() { return spawners; }
public SpawnerLootManager spawnerLoot() { return spawnerLoot; }
}