mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 02:57:52 +01:00
Better Error communication with Exceptions instead of boolean. Bungee Player Listener, Database#clean made private in SQLDB
This commit is contained in:
parent
a731db656c
commit
92626b2220
@ -145,4 +145,26 @@ public class Log {
|
||||
return PlanBungee.getInstance().getPluginLogger();
|
||||
}
|
||||
}
|
||||
|
||||
public static void logStackTrace(Throwable e) {
|
||||
error(e.toString());
|
||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||
error(" " + stackTraceElement);
|
||||
}
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null) {
|
||||
logCause(cause);
|
||||
}
|
||||
}
|
||||
|
||||
private static void logCause(Throwable e) {
|
||||
error("caused by: " + e.toString());
|
||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||
error(" " + stackTraceElement);
|
||||
}
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null) {
|
||||
logCause(cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.api.API;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.command.PlanCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.RegisterCommandFilter;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
@ -47,7 +48,6 @@ import main.java.com.djrapitops.plan.systems.tasks.PeriodicDBCommitTask;
|
||||
import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@ -147,12 +147,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
|
||||
Benchmark.start("Init Database");
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||
if (Check.errorIfFalse(initDatabase(), Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString())) {
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName()));
|
||||
} else {
|
||||
disablePlugin();
|
||||
return;
|
||||
}
|
||||
initDatabase();
|
||||
Benchmark.stop("Enable", "Init Database");
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
@ -204,7 +199,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
Log.info(Locale.get(Msg.ENABLED).toString());
|
||||
} catch (Exception e) {
|
||||
Log.error("Plugin Failed to Initialize Correctly.");
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
Log.logStackTrace(e);
|
||||
disablePlugin();
|
||||
}
|
||||
}
|
||||
@ -313,7 +308,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
*
|
||||
* @return true if init was successful, false if not.
|
||||
*/
|
||||
private boolean initDatabase() {
|
||||
private void initDatabase() throws DatabaseInitException {
|
||||
databases = new HashSet<>();
|
||||
databases.add(new MySQLDB(this));
|
||||
databases.add(new SQLiteDB(this));
|
||||
@ -328,12 +323,11 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
}
|
||||
}
|
||||
|
||||
if (!Verify.notNull(db)) {
|
||||
Log.info(Locale.get(Msg.ENABLE_FAIL_WRONG_DB).toString() + " " + dbType);
|
||||
return false;
|
||||
if (db == null) {
|
||||
throw new DatabaseInitException(Locale.get(Msg.ENABLE_FAIL_WRONG_DB).toString() + " " + dbType);
|
||||
}
|
||||
|
||||
return Check.errorIfFalse(db.init(), Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString());
|
||||
db.init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.api.exceptions;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DatabaseException extends Exception {
|
||||
|
||||
public DatabaseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DatabaseException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public DatabaseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.api.exceptions;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DatabaseInitException extends DatabaseException {
|
||||
public DatabaseInitException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DatabaseInitException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public DatabaseInitException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.api.exceptions;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DbCreateTableException extends DatabaseInitException {
|
||||
|
||||
public DbCreateTableException(String tableName, String message, Throwable cause) {
|
||||
super(tableName + ": " + message, cause);
|
||||
}
|
||||
|
||||
public DbCreateTableException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.api.exceptions;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlanEnableException extends Exception {
|
||||
public PlanEnableException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PlanEnableException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.ServerVariableHolder;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.bungee.systems.BungeePlayerListener;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import main.java.com.djrapitops.plan.locale.Locale;
|
||||
@ -20,7 +22,6 @@ import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.InputStream;
|
||||
@ -46,51 +47,58 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.setInstance(this);
|
||||
super.setDebugMode(Settings.DEBUG.toString());
|
||||
super.getPluginLogger().setFolder(getDataFolder());
|
||||
super.setColorScheme(new ColorScheme(ChatColor.GREEN, ChatColor.GRAY, ChatColor.WHITE));
|
||||
super.setLogPrefix("[Plan]");
|
||||
super.setUpdateCheckUrl("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml");
|
||||
super.setUpdateUrl("https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
try {
|
||||
|
||||
super.copyDefaultConfig("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md");
|
||||
|
||||
super.onEnableDefaultTasks();
|
||||
super.setInstance(this);
|
||||
super.setDebugMode(Settings.DEBUG.toString());
|
||||
super.getPluginLogger().setFolder(getDataFolder());
|
||||
super.setColorScheme(new ColorScheme(ChatColor.GREEN, ChatColor.GRAY, ChatColor.WHITE));
|
||||
super.setLogPrefix("[Plan]");
|
||||
super.setUpdateCheckUrl("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml");
|
||||
super.setUpdateUrl("https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
|
||||
variableHolder = new ServerVariableHolder(getProxy());
|
||||
super.copyDefaultConfig("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md");
|
||||
|
||||
new Locale(this).loadLocale();
|
||||
super.onEnableDefaultTasks();
|
||||
|
||||
processingQueue = new ProcessingQueue();
|
||||
variableHolder = new ServerVariableHolder(getProxy());
|
||||
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||
if (!initDatabase()) {
|
||||
new Locale(this).loadLocale();
|
||||
|
||||
processingQueue = new ProcessingQueue();
|
||||
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||
initDatabase();
|
||||
|
||||
String ip = variableHolder.getIp();
|
||||
if ("0.0.0.0".equals(ip)) {
|
||||
Log.error("IP setting still 0.0.0.0 - Set up AlternativeIP/IP that connects to the Proxy server.");
|
||||
}
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
webServer = new WebServer(this);
|
||||
webServer.initServer();
|
||||
|
||||
if (!webServer.isEnabled()) {
|
||||
Log.error("WebServer was not successfully initialized.");
|
||||
disablePlugin();
|
||||
return;
|
||||
}
|
||||
|
||||
serverInfoManager = new ServerInfoManager(this);
|
||||
infoManager = new InformationManager(this);
|
||||
webServer.setInfoManager(infoManager);
|
||||
|
||||
registerListener(new BungeePlayerListener(this));
|
||||
|
||||
Benchmark.stop("Enable", "WebServer Initialization");
|
||||
Log.info(Locale.get(Msg.ENABLED).toString());
|
||||
} catch (Exception e) {
|
||||
Log.error("Plugin Failed to Initialize Correctly.");
|
||||
Log.logStackTrace(e);
|
||||
disablePlugin();
|
||||
return;
|
||||
}
|
||||
|
||||
String ip = variableHolder.getIp();
|
||||
if ("0.0.0.0".equals(ip)) {
|
||||
Log.error("IP setting still 0.0.0.0 - Set up AlternativeIP/IP that connects to the Proxy server.");
|
||||
}
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
webServer = new WebServer(this);
|
||||
webServer.initServer();
|
||||
|
||||
if (!webServer.isEnabled()) {
|
||||
Log.error("WebServer was not successfully initialized.");
|
||||
disablePlugin();
|
||||
return;
|
||||
}
|
||||
|
||||
serverInfoManager = new ServerInfoManager(this);
|
||||
infoManager = new InformationManager(this);
|
||||
webServer.setInfoManager(infoManager);
|
||||
|
||||
Benchmark.stop("Enable", "WebServer Initialization");
|
||||
Log.info(Locale.get(Msg.ENABLED).toString());
|
||||
}
|
||||
|
||||
public static PlanBungee getInstance() {
|
||||
@ -107,9 +115,9 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
|
||||
Log.info(Locale.get(Msg.DISABLED).toString());
|
||||
}
|
||||
|
||||
private boolean initDatabase() {
|
||||
private void initDatabase() throws DatabaseInitException {
|
||||
db = new MySQLDB(this);
|
||||
return Check.errorIfFalse(db.init(), Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString());
|
||||
db.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.bungee.systems;
|
||||
|
||||
import main.java.com.djrapitops.plan.bungee.PlanBungee;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Player Join listener for Bungee.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BungeePlayerListener implements Listener {
|
||||
|
||||
private final PlanBungee plugin;
|
||||
|
||||
public BungeePlayerListener(PlanBungee plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
String name = player.getName();
|
||||
long now = MiscUtils.getTime();
|
||||
|
||||
plugin.getProcessingQueue().addToQueue(new BungeePlayerRegisterProcessor(uuid, name, now));
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.bungee.systems;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.bungee.PlanBungee;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.systems.processing.player.PlayerProcessor;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Processor that registers a new User for all servers to use as UUID - ID reference.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BungeePlayerRegisterProcessor extends PlayerProcessor {
|
||||
|
||||
private final String name;
|
||||
private final long registered;
|
||||
|
||||
public BungeePlayerRegisterProcessor(UUID uuid, String name, long registered) {
|
||||
super(uuid);
|
||||
this.name = name;
|
||||
this.registered = registered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
UsersTable usersTable = PlanBungee.getInstance().getDB().getUsersTable();
|
||||
try {
|
||||
if (usersTable.isRegistered(uuid)) {
|
||||
return;
|
||||
}
|
||||
usersTable.registerUser(uuid, registered, name);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.SubCommand;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to clear a database of all data.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class ManageCleanCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageCleanCommand(Plan plugin) {
|
||||
super("clean",
|
||||
CommandType.CONSOLE_WITH_ARGUMENTS,
|
||||
Permissions.MANAGE.getPermission(),
|
||||
Locale.get(Msg.CMD_USG_MANAGE_CLEAN).toString(),
|
||||
"<DB>");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.isTrue(args.length != 0, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String dbName = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
|
||||
if (!Check.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database database = ManageUtils.getDB(plugin, dbName);
|
||||
|
||||
// If DB is null return
|
||||
if (!Check.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
|
||||
Log.error(dbName + " was null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
runCleanTask(sender, database);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runCleanTask(ISender sender, final Database database) {
|
||||
plugin.getRunnableFactory().createNew(new AbsRunnable("DBCleanTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
|
||||
database.clean();
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_SUCCESS).toString());
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
@ -90,10 +90,7 @@ public class ManageRestoreCommand extends SubCommand {
|
||||
}
|
||||
|
||||
SQLiteDB backupDB = new SQLiteDB(plugin, backupDBName);
|
||||
if (!backupDB.init()) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
|
||||
return;
|
||||
}
|
||||
backupDB.init();
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database;
|
||||
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
@ -120,8 +121,7 @@ public abstract class Database {
|
||||
*
|
||||
* @return Was the initiation successful?
|
||||
*/
|
||||
public boolean init() {
|
||||
return false;
|
||||
public void init() throws DatabaseInitException {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,11 +143,6 @@ public abstract class Database {
|
||||
*/
|
||||
public abstract boolean wasSeenBefore(UUID uuid);
|
||||
|
||||
/**
|
||||
* Cleans the database of excess data.
|
||||
*/
|
||||
public abstract void clean();
|
||||
|
||||
/**
|
||||
* Used to get the name of the database type.
|
||||
* <p>
|
||||
|
@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.database.databases;
|
||||
|
||||
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -24,9 +25,13 @@ public class MySQLDB extends SQLDB {
|
||||
* Setups the {@link BasicDataSource}
|
||||
*/
|
||||
@Override
|
||||
public void setupDataSource() throws IOException {
|
||||
public void setupDataSource() throws DatabaseInitException {
|
||||
IFileConfig config = null;
|
||||
config = plugin.getIConfig().getConfig();
|
||||
try {
|
||||
config = plugin.getIConfig().getConfig();
|
||||
} catch (IOException e) {
|
||||
throw new DatabaseInitException("Failed to read config.", e);
|
||||
}
|
||||
|
||||
dataSource = new BasicDataSource();
|
||||
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
|
@ -2,16 +2,15 @@ package main.java.com.djrapitops.plan.database.databases;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -63,22 +62,14 @@ public abstract class SQLDB extends Database {
|
||||
* @return Was the Initialization successful.
|
||||
*/
|
||||
@Override
|
||||
public boolean init() {
|
||||
public void init() throws DatabaseInitException {
|
||||
setStatus("Init");
|
||||
String benchName = "Init " + getConfigName();
|
||||
Benchmark.start(benchName);
|
||||
try {
|
||||
setupDataSource();
|
||||
|
||||
if (!setupDatabase()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setupDatabase();
|
||||
clean();
|
||||
return true;
|
||||
} catch (IOException | SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
return false;
|
||||
} finally {
|
||||
Benchmark.stop("Database", benchName);
|
||||
Log.logDebug("Database");
|
||||
@ -90,40 +81,29 @@ public abstract class SQLDB extends Database {
|
||||
* <p>
|
||||
* Updates to latest schema.
|
||||
*
|
||||
* @return Is the connection usable?
|
||||
* @throws SQLException
|
||||
* @throws DatabaseInitException if something goes wrong.
|
||||
*/
|
||||
public boolean setupDatabase() throws SQLException {
|
||||
boolean newDatabase = isNewDatabase();
|
||||
public void setupDatabase() throws DatabaseInitException {
|
||||
try {
|
||||
boolean newDatabase = isNewDatabase();
|
||||
|
||||
if (!versionTable.createTable()) {
|
||||
Log.error("Failed to create table: " + versionTable.getTableName());
|
||||
return false;
|
||||
}
|
||||
versionTable.createTable();
|
||||
createTables();
|
||||
|
||||
if (newDatabase) {
|
||||
Log.info("New Database created.");
|
||||
}
|
||||
|
||||
if (!createTables()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int version = getVersion();
|
||||
boolean newVersion = version < 8;
|
||||
|
||||
if (newDatabase || newVersion) {
|
||||
setVersion(8);
|
||||
}
|
||||
|
||||
if (newVersion) {
|
||||
try (Statement statement = getConnection().createStatement()) {
|
||||
statement.execute("DROP TABLE IF EXISTS plan_locations");
|
||||
endTransaction(statement.getConnection());
|
||||
if (newDatabase) {
|
||||
Log.info("New Database created.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
int version = getVersion();
|
||||
boolean newVersion = version < 8;
|
||||
|
||||
if (newDatabase || newVersion) {
|
||||
setVersion(8);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseInitException("Failed to set-up Database", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,16 +113,12 @@ public abstract class SQLDB extends Database {
|
||||
*
|
||||
* @return true if successful.
|
||||
*/
|
||||
private boolean createTables() {
|
||||
private void createTables() throws DatabaseInitException {
|
||||
Benchmark.start("Create tables");
|
||||
for (Table table : getAllTables()) {
|
||||
if (!table.createTable()) {
|
||||
Log.error("Failed to create table: " + table.getTableName());
|
||||
return false;
|
||||
}
|
||||
table.createTable();
|
||||
}
|
||||
Benchmark.stop("Database", "Create tables");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,7 +151,7 @@ public abstract class SQLDB extends Database {
|
||||
/**
|
||||
* Setups the {@link BasicDataSource}
|
||||
*/
|
||||
public abstract void setupDataSource() throws IOException;
|
||||
public abstract void setupDataSource() throws DatabaseInitException;
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
@ -258,17 +234,13 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void clean() {
|
||||
private void clean() throws DatabaseInitException {
|
||||
Log.info("Cleaning the database.");
|
||||
try {
|
||||
tpsTable.clean();
|
||||
Log.info("Clean complete.");
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
throw new DatabaseInitException("Database Clean failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.Action;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
@ -47,9 +48,9 @@ public class ActionsTable extends UserIDTable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
public void createTable() throws DbCreateTableException {
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnServerID, Sql.INT).notNull()
|
||||
.column(columnDate, Sql.LONG).notNull()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
@ -40,9 +41,9 @@ public class CommandUseTable extends Table {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
public void createTable() throws DbCreateTableException {
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnCommandId)
|
||||
.column(columnCommand, Sql.varchar(20)).notNull()
|
||||
.column(columnTimesUsed, Sql.INT).notNull()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
@ -32,8 +33,8 @@ public class IPsTable extends UserIDTable {
|
||||
* @return if the table was created successfully
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnIP, Sql.varchar(20)).notNull()
|
||||
.column(columnGeolocation, Sql.varchar(50)).notNull()
|
||||
|
@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.PlayerKill;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
@ -41,8 +42,8 @@ public class KillsTable extends UserIDTable {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnKillerUserID, Sql.INT).notNull()
|
||||
.column(columnVictimUserID, Sql.INT).notNull()
|
||||
.column(columnWeapon, Sql.varchar(30)).notNull()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
@ -35,8 +36,8 @@ public class NicknamesTable extends UserIDTable {
|
||||
* @return if the table was created successfully
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnNick, Sql.varchar(75)).notNull()
|
||||
.column(columnServerID, Sql.INT).notNull()
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Insert;
|
||||
@ -33,8 +34,8 @@ public class SecurityTable extends Table {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnUser, Sql.varchar(100)).notNull().unique()
|
||||
.column(columnSaltedHash, Sql.varchar(100)).notNull().unique()
|
||||
.column(columnPermLevel, Sql.INT).notNull()
|
||||
@ -74,7 +75,7 @@ public class SecurityTable extends Table {
|
||||
statement.setString(2, saltPassHash);
|
||||
statement.setInt(3, permLevel);
|
||||
statement.execute();
|
||||
|
||||
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
|
@ -5,6 +5,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.*;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
||||
@ -47,8 +48,8 @@ public class ServerTable extends Table {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnServerID)
|
||||
.column(columnServerUUID, Sql.varchar(36)).notNull().unique()
|
||||
.column(columnServerName, Sql.varchar(100))
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
@ -43,8 +44,8 @@ public class SessionsTable extends UserIDTable {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(this.tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(this.tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnID)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnServerID, Sql.INT).notNull()
|
||||
|
@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
@ -45,8 +46,8 @@ public class TPSTable extends Table {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnServerID, Sql.INT).notNull()
|
||||
.column(columnDate, Sql.LONG).notNull()
|
||||
.column(columnTPS, Sql.DOUBLE).notNull()
|
||||
|
@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
@ -48,15 +49,13 @@ public abstract class Table {
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean createTable();
|
||||
public abstract void createTable() throws DbCreateTableException;
|
||||
|
||||
protected boolean createTable(String sql) {
|
||||
protected void createTable(String sql) throws DbCreateTableException {
|
||||
try {
|
||||
execute(sql);
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
throw new DbCreateTableException(tableName, "Failed to create table", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
@ -40,8 +41,8 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnRegistered, Sql.LONG).notNull()
|
||||
.column(columnOP, Sql.BOOL).notNull().defaultValue(false)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.*;
|
||||
|
||||
@ -35,8 +36,8 @@ public class UsersTable extends UserIDTable {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnID)
|
||||
.column(columnUUID, Sql.varchar(36)).notNull().unique()
|
||||
.column(columnRegistered, Sql.LONG).notNull()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
@ -26,8 +27,8 @@ public class VersionTable extends Table {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column("version", Sql.INT).notNull()
|
||||
.toString()
|
||||
);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
@ -40,8 +41,8 @@ public class WorldTable extends Table {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnWorldId)
|
||||
.column(columnWorldName, Sql.varchar(100)).notNull()
|
||||
.primaryKey(usingMySQL, columnWorldId)
|
||||
|
@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DbCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
@ -48,8 +49,8 @@ public class WorldTimesTable extends UserIDTable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
public void createTable() throws DbCreateTableException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnWorldId, Sql.INT).notNull()
|
||||
.column(columnSessionID, Sql.INT).notNull()
|
||||
|
@ -26,7 +26,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class ServerInfoFile extends BukkitConfig {
|
||||
public ServerInfoFile(Plan plugin) throws IOException {
|
||||
super(plugin, "ServerInfoFile");
|
||||
super(plugin, "ServerInfoFile.yml");
|
||||
IFileConfig config = super.getConfig();
|
||||
config.copyDefaults();
|
||||
config.addDefault("Server.UUID", "");
|
||||
|
@ -5,11 +5,11 @@
|
||||
package main.java.com.djrapitops.plan.systems.info.server;
|
||||
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.ServerVariableHolder;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
|
||||
import main.java.com.djrapitops.plan.bungee.PlanBungee;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.ServerTable;
|
||||
@ -33,7 +33,7 @@ public class ServerInfoManager {
|
||||
private ServerInfoFile serverInfoFile;
|
||||
private final ServerTable serverTable;
|
||||
|
||||
public ServerInfoManager(Plan plugin) {
|
||||
public ServerInfoManager(Plan plugin) throws PlanEnableException {
|
||||
this.plugin = plugin;
|
||||
Database db = plugin.getDB();
|
||||
serverTable = db.getServerTable();
|
||||
@ -41,9 +41,7 @@ public class ServerInfoManager {
|
||||
try {
|
||||
serverInfoFile = new ServerInfoFile(plugin);
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
Log.error("Failed to read server info from local file, disabling plugin.");
|
||||
plugin.disablePlugin();
|
||||
throw new PlanEnableException("Failed to read ServerInfoFile.yml", e);
|
||||
}
|
||||
|
||||
Optional<UUID> serverUUID = serverInfoFile.getUUID();
|
||||
@ -54,10 +52,10 @@ public class ServerInfoManager {
|
||||
} else {
|
||||
registerServer();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
Log.error("Failed to register server info to database, disabling plugin.");
|
||||
plugin.disablePlugin();
|
||||
} catch (SQLException e) {
|
||||
throw new PlanEnableException("Failed to update Database server info", e);
|
||||
} catch (IOException e) {
|
||||
throw new PlanEnableException("Failed to write to ServerInfoFile.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.Action;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.Actions;
|
||||
import main.java.com.djrapitops.plan.database.tables.UserInfoTable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
@ -38,12 +39,13 @@ public class RegisterProcessor extends PlayerProcessor {
|
||||
UUID uuid = getUUID();
|
||||
Plan plugin = Plan.getInstance();
|
||||
Database db = plugin.getDB();
|
||||
if (db.wasSeenBefore(uuid)) {
|
||||
return;
|
||||
}
|
||||
plugin.getDataCache().markFirstSession(uuid);
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
try {
|
||||
db.getUserInfoTable().registerUserInfo(uuid, registered);
|
||||
if (userInfoTable.isRegistered(uuid)) {
|
||||
return;
|
||||
}
|
||||
plugin.getDataCache().markFirstSession(uuid);
|
||||
userInfoTable.registerUserInfo(uuid, registered);
|
||||
db.getActionsTable().insertAction(uuid, new Action(time, Actions.FIRST_SESSION, "Online: " + playersOnline + " Players"));
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
|
@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.utilities;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
|
||||
@ -28,7 +29,7 @@ public class ManageUtils {
|
||||
* @param copyFromDB Database you want to backup.
|
||||
* @return success?
|
||||
*/
|
||||
public static boolean backup(String dbName, Database copyFromDB) {
|
||||
public static boolean backup(String dbName, Database copyFromDB) throws DatabaseInitException {
|
||||
Plan plugin = Plan.getInstance();
|
||||
String timeStamp = new Date().toString().substring(4, 10).replace(" ", "-");
|
||||
String fileName = dbName + "-backup-" + timeStamp;
|
||||
@ -79,15 +80,13 @@ public class ManageUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Database getDB(Plan plugin, String dbName) {
|
||||
public static Database getDB(Plan plugin, String dbName) throws DatabaseInitException {
|
||||
Database database = null;
|
||||
for (Database sqldb : plugin.getDatabases()) {
|
||||
String dbConfigName = sqldb.getConfigName();
|
||||
if (Verify.equalsIgnoreCase(dbName, dbConfigName)) {
|
||||
database = sqldb;
|
||||
if (!database.init()) {
|
||||
return null;
|
||||
}
|
||||
database.init();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user