MinecraftManagerPlugin/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java

213 lines
6.5 KiB
Java
Raw Normal View History

2018-09-12 15:55:10 +00:00
package xyz.etztech.minecraftmanager;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
2018-09-12 15:55:10 +00:00
import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.core.api.IMinecraftManager;
2018-09-12 15:55:10 +00:00
import xyz.etztech.minecraftmanager.command.*;
import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener;
import xyz.etztech.minecraftmanager.listeners.BlockBreakListener;
import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener;
2018-09-12 15:55:10 +00:00
import xyz.etztech.minecraftmanager.listeners.SessionListener;
import xyz.etztech.minecraftmanager.objects.Application;
2018-12-08 05:18:10 +00:00
import xyz.etztech.minecraftmanager.objects.OreAlert;
import xyz.etztech.minecraftmanager.objects.Question;
import xyz.etztech.minecraftmanager.objects.Rules;
2018-09-12 15:55:10 +00:00
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 {
2018-09-12 15:55:10 +00:00
public static MinecraftManager instance;
public static FileConfiguration config;
private Logger log = Logger.getLogger( "Minecraft" );
private static Map<String, Boolean> applyMode = new HashMap<>();
private static Map<String, Question> applyQuestion = new HashMap<>();
private static Map<String, Application> applications = new HashMap<>();
private static List<String> diamonds = new ArrayList<>();
private static Rules rules;
private static List<String> banOptions;
2018-12-08 05:18:10 +00:00
private static OreAlert oreAlert;
// API
private static boolean logOverride = false;
// Report
private static boolean reportRunning = false;
private static boolean reportStop = false;
2018-09-12 15:55:10 +00:00
// Objects that can be reloaded
AsyncPlayerChatListener chatListener;
CommandRules cmdRules;
public void onEnable() {
2018-09-12 15:55:10 +00:00
instance = this;
saveDefaultConfig();
reloadConfig();
2018-09-12 15:55:10 +00:00
// 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);
2018-09-12 15:55:10 +00:00
// 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);
2018-09-12 15:55:10 +00:00
2018-12-08 05:18:10 +00:00
oreAlert = new OreAlert(this);
2018-09-12 15:55:10 +00:00
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
}
}
public void onDisable() {
}
2018-09-12 15:55:10 +00:00
public void loadConfig() {
config = Bukkit.getPluginManager().getPlugin("MinecraftManager").getConfig();
}
@Override
public void reloadConfig() {
super.reloadConfig();
loadConfig();
2018-12-07 23:07:54 +00:00
MCMUtil.init();
2018-09-12 15:55:10 +00:00
if (chatListener != null) {
chatListener.reload();
}
rules = new Rules(config);
banOptions = config.getStringList("ban.options");
2018-09-12 15:55:10 +00:00
}
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<String> 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;
}
2018-12-08 05:18:10 +00:00
public OreAlert getOreAlert() {
return oreAlert;
}
@Override
public void logOverride(boolean override) {
logOverride = override;
}
@Override
public void globalLog(Player player, String message) {
2018-12-07 23:07:54 +00:00
MCMUtil.log(MCMUtil.globalLogger, player.getName() + " > " + message);
}
2018-09-12 15:55:10 +00:00
}