Files
src
build.gradle
settings.gradle
Code
22 1,100
src/main/java/com/churrosmp/churroeconomy/ChurroEconomy.java
package com.churrosmp.churroeconomy;
import com.churrosmp.churroeconomy.command.ChurroCommand;
import com.churrosmp.churroeconomy.economy.EconomyService;
import com.churrosmp.churroeconomy.enderchest.EnderChestService;
import com.churrosmp.churroeconomy.gui.GUIListener;
import com.churrosmp.churroeconomy.gui.GUIManager;
import com.churrosmp.churroeconomy.integration.ChurroPlaceholderExpansion;
import com.churrosmp.churroeconomy.integration.VaultEconomyProvider;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
public final class ChurroEconomy extends JavaPlugin {
private EconomyService economy;
private EnderChestService enderChest;
private GUIManager guiManager;
@Override
public void onEnable() {
saveDefaultConfig();
saveResource("messages.yml", false);
economy = new EconomyService(this);
enderChest = new EnderChestService(this);
guiManager = new GUIManager(this, economy, enderChest);
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
ChurroCommand command = new ChurroCommand(this, economy, guiManager, enderChest);
String[] commands = {"ec", "economy", "eco", "bal", "pay", "baltop", "sell", "ecoreceipt", "sellmaintenance", "shopmaintenance", "economymaintenance"};
for (String name : commands) {
if (getCommand(name) != null) {
getCommand(name).setExecutor(command);
getCommand(name).setTabCompleter(command);
}
}
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, new VaultEconomyProvider(economy), this, ServicePriority.Normal);
}
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) new ChurroPlaceholderExpansion(this, economy).register();
long interval = Math.max(60L, getConfig().getLong("economy.save-interval-seconds", 300L)) * 20L;
Bukkit.getScheduler().runTaskTimer(this, economy::save, interval, interval);
}
@Override
public void onDisable() {
if (guiManager != null) guiManager.closeAll();
if (enderChest != null) enderChest.saveAll();
if (economy != null) economy.save();
}
public String message(String key, String... replacements) {
org.bukkit.configuration.file.FileConfiguration messages = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(new java.io.File(getDataFolder(), "messages.yml"));
String text = messages.getString(key, key);
for (int i = 0; i + 1 < replacements.length; i += 2) text = text.replace("{" + replacements[i] + "}", replacements[i + 1]);
return ChatColor.translateAlternateColorCodes('&', text);
}
public EconomyService getEconomy() { return economy; }
public EnderChestService getEnderChest() { return enderChest; }
public GUIManager getGuiManager() { return guiManager; }
}