2022-04-16 23:49:42 +00:00
|
|
|
package moe.oko.opennaw;
|
|
|
|
|
2022-04-23 01:09:49 +00:00
|
|
|
import moe.oko.opennaw.command.CityCommand;
|
2022-05-06 19:08:34 +00:00
|
|
|
import moe.oko.opennaw.command.GateCommand;
|
2022-04-16 23:49:42 +00:00
|
|
|
import moe.oko.opennaw.command.NationCommand;
|
2022-04-24 09:28:50 +00:00
|
|
|
import moe.oko.opennaw.listener.ActionListener;
|
2022-05-06 19:08:34 +00:00
|
|
|
import moe.oko.opennaw.listener.GateListener;
|
2022-05-02 20:50:20 +00:00
|
|
|
import moe.oko.opennaw.storage.NAWDatabase;
|
2022-04-24 07:19:28 +00:00
|
|
|
import moe.oko.opennaw.util.*;
|
2022-04-16 23:49:42 +00:00
|
|
|
import net.luckperms.api.LuckPerms;
|
2022-04-24 07:19:28 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2022-05-05 19:22:21 +00:00
|
|
|
import org.bukkit.conversations.ConversationFactory;
|
2022-04-16 23:49:42 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2022-05-04 21:09:41 +00:00
|
|
|
import java.io.File;
|
|
|
|
|
2022-04-16 23:49:42 +00:00
|
|
|
import static moe.oko.opennaw.util.CommandHelper.info;
|
|
|
|
|
|
|
|
public final class OpenNAW extends JavaPlugin {
|
|
|
|
|
|
|
|
public static OpenNAW instance;
|
|
|
|
public NationHandler nationHandler;
|
2022-04-24 09:28:50 +00:00
|
|
|
|
|
|
|
public ActionLogger actionLogger;
|
|
|
|
|
2022-04-22 03:48:33 +00:00
|
|
|
public CityHandler cityHandler;
|
2022-04-24 09:28:50 +00:00
|
|
|
|
2022-05-06 19:08:34 +00:00
|
|
|
public GateHandler gateHandler;
|
|
|
|
|
|
|
|
public TNTHandler tntHandler;
|
|
|
|
|
2022-05-02 20:50:20 +00:00
|
|
|
public NAWDatabase database;
|
|
|
|
|
2022-04-24 09:28:50 +00:00
|
|
|
public ConfigHelper configHelper;
|
|
|
|
|
2022-04-16 23:49:42 +00:00
|
|
|
public GroupHandler groupHandler;
|
|
|
|
private LuckPerms luckPerms;
|
|
|
|
|
2022-04-24 07:19:28 +00:00
|
|
|
private DynmapHandler dynmapHandler;
|
|
|
|
|
|
|
|
private boolean dynmapEnabled;
|
|
|
|
|
2022-04-16 23:49:42 +00:00
|
|
|
public static OpenNAW getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public NationHandler getNationHandler() {
|
|
|
|
return nationHandler;
|
|
|
|
}
|
2022-04-22 03:48:33 +00:00
|
|
|
public CityHandler getCityHandler(){ return cityHandler; }
|
2022-04-16 23:49:42 +00:00
|
|
|
public GroupHandler getGroupHandler() { return groupHandler; }
|
|
|
|
|
2022-05-06 19:08:34 +00:00
|
|
|
public GateHandler getGateHandler() { return gateHandler; }
|
|
|
|
|
|
|
|
public TNTHandler getTntHandler() {
|
|
|
|
return tntHandler;
|
|
|
|
}
|
|
|
|
|
2022-04-16 23:49:42 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
// Initialize internals
|
|
|
|
instance = this;
|
2022-05-04 21:09:41 +00:00
|
|
|
if(!new File(getDataFolder().getAbsolutePath() + "/config.yml").exists()) {
|
|
|
|
saveDefaultConfig(); //Default if non existent.
|
|
|
|
} else {
|
|
|
|
saveConfig(); //Save cfg on start
|
|
|
|
}
|
2022-04-24 09:28:50 +00:00
|
|
|
configHelper = new ConfigHelper(this.getConfig());
|
2022-04-16 23:49:42 +00:00
|
|
|
this.luckPerms = getServer().getServicesManager().load(LuckPerms.class);
|
2022-04-24 09:28:50 +00:00
|
|
|
actionLogger = new ActionLogger();
|
2022-04-16 23:49:42 +00:00
|
|
|
nationHandler = new NationHandler();
|
2022-04-23 01:09:49 +00:00
|
|
|
cityHandler = new CityHandler();
|
2022-05-06 19:08:34 +00:00
|
|
|
gateHandler = new GateHandler();
|
2022-04-16 23:49:42 +00:00
|
|
|
groupHandler = new GroupHandler(this.luckPerms);
|
2022-05-06 19:08:34 +00:00
|
|
|
tntHandler = new TNTHandler();
|
2022-04-16 23:49:42 +00:00
|
|
|
|
2022-05-02 20:50:20 +00:00
|
|
|
info("OpenNAW is initialized.");
|
|
|
|
info("Starting database load.");
|
|
|
|
database = configHelper.fetchDatabase();
|
|
|
|
info("Database initialized. Starting to fetch all values");
|
|
|
|
nationHandler.loadNationList(database.loadNations());
|
|
|
|
database.loadPlayers();
|
|
|
|
cityHandler.loadCityList(database.loadCities());
|
2022-05-06 19:08:34 +00:00
|
|
|
database.loadGates();
|
2022-05-02 20:50:20 +00:00
|
|
|
//Do not change above load order.
|
2022-04-16 23:49:42 +00:00
|
|
|
|
2022-04-22 00:56:50 +00:00
|
|
|
// Register Commands & Events
|
2022-04-16 23:49:42 +00:00
|
|
|
this.getCommand("nation").setExecutor(new NationCommand());
|
2022-04-23 01:09:49 +00:00
|
|
|
this.getCommand("city").setExecutor(new CityCommand());
|
2022-05-06 19:08:34 +00:00
|
|
|
this.getCommand("gate").setExecutor(new GateCommand());
|
2022-04-22 00:56:50 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
|
2022-04-24 09:28:50 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new ActionListener(), this);
|
2022-05-06 19:08:34 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new GateListener(), this);
|
2022-04-24 07:19:28 +00:00
|
|
|
|
|
|
|
if(Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
|
|
|
|
this.dynmapEnabled = true;
|
|
|
|
//Only initialize if dyn is loaded.
|
|
|
|
dynmapHandler = new DynmapHandler();
|
|
|
|
}
|
2022-04-16 23:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2022-05-06 19:08:34 +00:00
|
|
|
gateHandler.closeAllGates(); //Close gates before stopping.
|
|
|
|
tntHandler.shutdown();
|
2022-05-03 19:43:44 +00:00
|
|
|
info("Starting persistence save.");
|
2022-05-06 19:08:34 +00:00
|
|
|
gateHandler.saveGates();
|
2022-05-03 19:43:44 +00:00
|
|
|
cityHandler.saveCities();
|
|
|
|
nationHandler.saveNations();
|
2022-04-16 23:49:42 +00:00
|
|
|
info("OpenNAW is disabled!");
|
|
|
|
}
|
|
|
|
|
2022-04-24 07:19:28 +00:00
|
|
|
public boolean isDynmapEnabled() {
|
|
|
|
return dynmapEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DynmapHandler getDynmapHandler() {
|
|
|
|
return dynmapHandler;
|
|
|
|
}
|
2022-04-24 09:28:50 +00:00
|
|
|
|
2022-05-03 19:43:44 +00:00
|
|
|
public NAWDatabase getDatabase() { return database; }
|
|
|
|
|
2022-04-24 09:28:50 +00:00
|
|
|
public ActionLogger getActionLogger() {
|
|
|
|
return actionLogger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConfigHelper getConfigHelper() {
|
|
|
|
return configHelper;
|
|
|
|
}
|
2022-04-16 23:49:42 +00:00
|
|
|
}
|