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

149 lines
4.5 KiB
Java

package xyz.etztech.minecraftmanager;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.minecraftmanager.command.*;
import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener;
import xyz.etztech.minecraftmanager.listeners.BlockBreakListener;
import xyz.etztech.minecraftmanager.listeners.SessionListener;
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 {
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<>();
// Objects that can be reloaded
AsyncPlayerChatListener chatListener;
CommandRules cmdRules;
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
loadConfig();
// 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);
// 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);
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
}
}
@Override
public void onDisable() {
}
public void loadConfig() {
config = Bukkit.getPluginManager().getPlugin("MinecraftManager").getConfig();
}
@Override
public void reloadConfig() {
super.reloadConfig();
loadConfig();
if (chatListener != null) {
chatListener.reload();
}
if (cmdRules != null) {
cmdRules.reload();
}
}
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;
}
}