mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-29 19:41:35 +01:00
Improved system init
This commit is contained in:
parent
71c61cb469
commit
a469a09943
@ -45,6 +45,7 @@ import main.java.com.djrapitops.plan.settings.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.settings.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.settings.theme.Theme;
|
||||
import main.java.com.djrapitops.plan.systems.DatabaseSystem;
|
||||
import main.java.com.djrapitops.plan.systems.FileSystem;
|
||||
import main.java.com.djrapitops.plan.systems.Systems;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;
|
||||
@ -65,7 +66,6 @@ import main.java.com.djrapitops.plan.utilities.metrics.BStats;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
@ -143,10 +143,10 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
try {
|
||||
File dataFolder = getDataFolder();
|
||||
dataFolder.mkdirs();
|
||||
File configFile = new File(dataFolder, "config.yml");
|
||||
config = new Config(configFile);
|
||||
systems = new Systems(this);
|
||||
FileSystem.getInstance().init();
|
||||
|
||||
config = new Config(FileSystem.getConfigFile());
|
||||
config.copyDefaults(FileUtil.lines(this, "config.yml"));
|
||||
config.save();
|
||||
|
||||
@ -186,8 +186,7 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
serverVariableHolder = new ServerVariableHolder(getServer());
|
||||
Benchmark.stop("Enable", "Reading server variables");
|
||||
|
||||
systems = new Systems();
|
||||
systems.init();
|
||||
DatabaseSystem.getInstance().init();
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
webServer = new WebServer(this);
|
||||
@ -344,6 +343,9 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L);
|
||||
}
|
||||
}
|
||||
|
||||
systems.close();
|
||||
|
||||
Log.info(Locale.get(Msg.DISABLED).toString());
|
||||
Benchmark.pluginDisabled(Plan.class);
|
||||
DebugLog.pluginDisabled(Plan.class);
|
||||
|
@ -17,14 +17,15 @@ import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.command.PlanBungeeCommand;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import main.java.com.djrapitops.plan.settings.Settings;
|
||||
import main.java.com.djrapitops.plan.settings.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.settings.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.settings.theme.Theme;
|
||||
import main.java.com.djrapitops.plan.systems.DatabaseSystem;
|
||||
import main.java.com.djrapitops.plan.systems.FileSystem;
|
||||
import main.java.com.djrapitops.plan.systems.Systems;
|
||||
import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.BungeeServerInfoManager;
|
||||
@ -37,10 +38,8 @@ import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import main.java.com.djrapitops.plan.utilities.file.export.HtmlExport;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -53,8 +52,9 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
private Config config;
|
||||
private Theme theme;
|
||||
|
||||
private Systems systems;
|
||||
|
||||
private WebServer webServer;
|
||||
private Database db;
|
||||
private BungeeServerInfoManager serverInfoManager;
|
||||
private BungeeInformationManager infoManager;
|
||||
private ServerVariableHolder variableHolder;
|
||||
@ -65,8 +65,10 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
try {
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
config = new Config(configFile);
|
||||
systems = new Systems(this);
|
||||
FileSystem.getInstance().init();
|
||||
|
||||
config = new Config(FileSystem.getConfigFile());
|
||||
config.copyDefaults(FileUtil.lines(this, "bungeeconfig.yml"));
|
||||
config.save();
|
||||
|
||||
@ -93,8 +95,7 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
|
||||
theme = new Theme();
|
||||
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||
initDatabase();
|
||||
DatabaseSystem.getInstance().init();
|
||||
|
||||
registerCommand("planbungee", new PlanBungeeCommand(this));
|
||||
|
||||
@ -168,13 +169,7 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
if (webServer != null) {
|
||||
webServer.stop();
|
||||
}
|
||||
if (db != null) {
|
||||
try {
|
||||
db.close();
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
systems.close();
|
||||
Log.info(Locale.get(Msg.DISABLED).toString());
|
||||
super.onDisable();
|
||||
}
|
||||
@ -193,14 +188,10 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
}
|
||||
}
|
||||
|
||||
private void initDatabase() throws DatabaseInitException {
|
||||
db = new MySQLDB();
|
||||
db.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Database getDB() {
|
||||
return db;
|
||||
return DatabaseSystem.getInstance().getActiveDatabase();
|
||||
}
|
||||
|
||||
public BungeeServerInfoManager getServerInfoManager() {
|
||||
|
@ -4,8 +4,11 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems;
|
||||
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
@ -13,9 +16,29 @@ import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
|
||||
*/
|
||||
public class FileSystem implements SubSystem {
|
||||
|
||||
private final File dataFolder;
|
||||
private File configFile;
|
||||
|
||||
public FileSystem(IPlan plugin) {
|
||||
dataFolder = plugin.getDataFolder();
|
||||
}
|
||||
|
||||
public static FileSystem getInstance() {
|
||||
return Systems.getInstance().fileSystem;
|
||||
}
|
||||
|
||||
public static File getDataFolder() {
|
||||
return getInstance().dataFolder;
|
||||
}
|
||||
|
||||
public static File getConfigFile() {
|
||||
return getInstance().configFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws PlanEnableException {
|
||||
|
||||
dataFolder.mkdirs();
|
||||
configFile = new File(dataFolder, "config.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,37 +5,35 @@
|
||||
package main.java.com.djrapitops.plan.systems;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
/**
|
||||
* Layer for reducing
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Systems implements SubSystem {
|
||||
public class Systems {
|
||||
|
||||
FileSystem fileSystem;
|
||||
DatabaseSystem databaseSystem;
|
||||
|
||||
public Systems() {
|
||||
this.databaseSystem = new DatabaseSystem();
|
||||
public Systems(IPlan plugin) {
|
||||
databaseSystem = new DatabaseSystem();
|
||||
fileSystem = new FileSystem(plugin);
|
||||
}
|
||||
|
||||
private SubSystem[] getSubSystems() {
|
||||
return new SubSystem[]{
|
||||
databaseSystem
|
||||
databaseSystem,
|
||||
fileSystem
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws PlanEnableException {
|
||||
for (SubSystem subSystem : getSubSystems()) {
|
||||
subSystem.init();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
for (SubSystem subSystem : getSubSystems()) {
|
||||
SubSystem[] subSystems = getSubSystems();
|
||||
ArrayUtils.reverse(subSystems);
|
||||
for (SubSystem subSystem : subSystems) {
|
||||
subSystem.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user