package xyz.etztech.minecraftmanager; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import xyz.etztech.core.api.IMinecraftManager; import xyz.etztech.minecraftmanager.command.*; import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener; import xyz.etztech.minecraftmanager.listeners.BlockBreakListener; import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener; import xyz.etztech.minecraftmanager.listeners.SessionListener; import xyz.etztech.minecraftmanager.objects.Application; import xyz.etztech.minecraftmanager.objects.OreAlert; import xyz.etztech.minecraftmanager.objects.Question; import xyz.etztech.minecraftmanager.objects.Rules; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Logger; public class MinecraftManager extends JavaPlugin implements IMinecraftManager { public static MinecraftManager instance; public static FileConfiguration config; private Logger log = Logger.getLogger( "Minecraft" ); private static Map applyMode = new HashMap<>(); private static Map applyQuestion = new HashMap<>(); private static Map applications = new HashMap<>(); private static List diamonds = new ArrayList<>(); private static Rules rules; private static List banOptions; private static OreAlert oreAlert; // API private static boolean logOverride = false; // Report private static boolean reportRunning = false; private static boolean reportStop = false; // Objects that can be reloaded AsyncPlayerChatListener chatListener; CommandRules cmdRules; public void onEnable() { instance = this; saveDefaultConfig(); reloadConfig(); // Create log directory if it doesn't exist new File(getDataFolder().getAbsolutePath() + "/logs/").mkdir(); if (isEnabled()) { // Add Commands CommandMain cmdMain = new CommandMain(this); this.getCommand("minecraftmanager").setExecutor(cmdMain); cmdMain.startThread(); CommandApplication cmdApplication = new CommandApplication(this); this.getCommand("application").setExecutor(cmdApplication); CommandApply cmdApply = new CommandApply(this); this.getCommand("apply").setExecutor(cmdApply); CommandTicket cmdTicket = new CommandTicket(this); this.getCommand("ticket").setExecutor(cmdTicket); CommandWarning cmdWarning = new CommandWarning(this); this.getCommand("warn").setExecutor(cmdWarning); // Rules is optional if (getConfig().getBoolean("rules.enabled")) { cmdRules = new CommandRules(this); this.getCommand("rules").setExecutor(cmdRules); } // Add Listeners chatListener = new AsyncPlayerChatListener(this); getServer().getPluginManager().registerEvents(chatListener, this); SessionListener sessionListener = new SessionListener(this); getServer().getPluginManager().registerEvents(sessionListener, this); BlockBreakListener blockBreakListener = new BlockBreakListener(this); getServer().getPluginManager().registerEvents(blockBreakListener, this); CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this); getServer().getPluginManager().registerEvents(commandPreprocessListener, this); oreAlert = new OreAlert(this); Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully."); } } public void onDisable() { } public void loadConfig() { config = Bukkit.getPluginManager().getPlugin("MinecraftManager").getConfig(); } @Override public void reloadConfig() { super.reloadConfig(); loadConfig(); MCMUtil.init(); if (chatListener != null) { chatListener.reload(); } rules = new Rules(config); banOptions = config.getStringList("ban.options"); } public void log(String message) { log.info( "[MinecraftManager]: " + message ); } public static Boolean inApplyMode(String uuid) { if (applyMode.containsKey(uuid)) { return applyMode.get(uuid); } return false; } public static void setApplyMode(String uuid, Boolean inApplyMode) { applyMode.put(uuid, inApplyMode); } public static Question getApplyQuestion(String uuid) { if (applyQuestion.containsKey(uuid)) { return applyQuestion.get(uuid); } return Question.ONE; } public static void setApplyQuestion(String uuid, Question question) { if (Question.COMPLETE == question) { applyQuestion.remove(uuid); } else { applyQuestion.put(uuid, question); } } public static Application getApplication(String uuid) { if (applications.containsKey(uuid)) { return applications.get(uuid); } return new Application(); } public static void setApplication(String uuid, Application application) { applications.put(uuid, application); } public static boolean addDiamond(String location) { if (diamonds.contains(location)) { return false; } diamonds.add(location); return true; } public static Rules getRules() { return rules; } public static List getBanOptions() { return banOptions; } public static boolean getReportRunning() { return reportRunning; } public static void setReportRunning(boolean reportRunning) { MinecraftManager.reportRunning = reportRunning; } public static boolean getReportStop() { return reportStop; } public static void setReportStop(boolean reportStop) { MinecraftManager.reportStop = reportStop; } public static boolean getLogOverride() { return logOverride; } public OreAlert getOreAlert() { return oreAlert; } @Override public void logOverride(boolean override) { logOverride = override; } @Override public void globalLog(Player player, String message) { MCMUtil.log(MCMUtil.globalLogger, player.getName() + " > " + message); } }