2018-09-12 15:55:10 +00:00
|
|
|
package xyz.etztech.minecraftmanager;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
2018-09-12 16:03:59 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2018-09-12 15:55:10 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2018-09-12 16:03:59 +00:00
|
|
|
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;
|
2018-09-12 16:03:59 +00:00
|
|
|
import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener;
|
2018-09-12 15:55:10 +00:00
|
|
|
import xyz.etztech.minecraftmanager.listeners.SessionListener;
|
2018-09-12 16:03:59 +00:00
|
|
|
import xyz.etztech.minecraftmanager.objects.Application;
|
|
|
|
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;
|
|
|
|
|
2018-10-21 04:01:00 +00:00
|
|
|
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<>();
|
2018-09-12 16:03:59 +00:00
|
|
|
private static Rules rules;
|
|
|
|
private static List<String> banOptions;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-21 04:01:00 +00:00
|
|
|
public void onEnable() {
|
2018-09-12 15:55:10 +00:00
|
|
|
|
|
|
|
instance = this;
|
|
|
|
saveDefaultConfig();
|
2018-09-12 16:03:59 +00:00
|
|
|
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);
|
2018-09-12 16:03:59 +00:00
|
|
|
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);
|
2018-09-12 16:03:59 +00:00
|
|
|
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
|
2018-09-12 15:55:10 +00:00
|
|
|
|
|
|
|
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 04:01:00 +00:00
|
|
|
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();
|
|
|
|
if (chatListener != null) {
|
|
|
|
chatListener.reload();
|
|
|
|
}
|
2018-09-12 16:03:59 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-09-12 16:03:59 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void logOverride(boolean override) {
|
|
|
|
logOverride = override;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void globalLog(Player player, String message) {
|
|
|
|
MCMUtil.log(MCMUtil.globalLog, player.getName() + " > " + message);
|
|
|
|
}
|
|
|
|
|
2018-09-12 15:55:10 +00:00
|
|
|
}
|
|
|
|
|