Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics

This commit is contained in:
Fuzzlemann 2017-08-28 17:03:11 +02:00
commit f2a534417d
49 changed files with 558 additions and 311 deletions

View File

@ -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);
}
}
}

View File

@ -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;
@ -151,12 +151,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");
@ -208,7 +203,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();
}
}
@ -317,7 +312,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));
@ -332,12 +327,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();
}
/**

View File

@ -40,7 +40,7 @@ public class ServerVariableHolder {
public ServerVariableHolder(net.md_5.bungee.api.ProxyServer server) {
ip = Settings.BUNGEE_IP.toString();
name = "BungeeCord";
port = Settings.BUNGEE_PORT.getNumber();
port = -1;
version = server.getVersion();
implVersion = server.getVersion();
usingPaper = false;

View File

@ -87,8 +87,7 @@ public enum Settings {
HIDE_TOWNS("Plugins.Towny.HideTowns"),
//
// Bungee
BUNGEE_IP("Server.IP"),
BUNGEE_PORT("Server.Port")
BUNGEE_IP("Server.IP")
;

View File

@ -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;
/**
* Thrown when something goes wrong in the database, generic exception.
*
* @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);
}
}

View File

@ -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;
/**
* Thrown when something goes wrong with Database#init.
*
* @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);
}
}

View File

@ -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;
/**
* Thrown when something goes wrong with creating tables with Table#createTable.
*
* @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);
}
}

View File

@ -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;
/**
* Thrown when something goes wrong with Plan initialization.
*
* @author Rsl1122
*/
public class PlanEnableException extends Exception {
public PlanEnableException(String message, Throwable cause) {
super(message, cause);
}
public PlanEnableException(String message) {
super(message);
}
}

View File

@ -8,8 +8,14 @@ import com.djrapitops.plugin.BungeePlugin;
import com.djrapitops.plugin.settings.ColorScheme;
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;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfoManager;
import main.java.com.djrapitops.plan.systems.processing.Processor;
@ -41,34 +47,58 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
@Override
public void onEnable() {
super.setInstance(this);
try {
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/");
super.copyDefaultConfig("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md");
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/");
super.onEnableDefaultTasks();
super.copyDefaultConfig("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md");
variableHolder = new ServerVariableHolder(getProxy());
super.onEnableDefaultTasks();
Benchmark.start("WebServer Initialization");
webServer = new WebServer(this);
webServer.initServer();
variableHolder = new ServerVariableHolder(getProxy());
if (!webServer.isEnabled()) {
Log.error("WebServer was not successfully initialized.");
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();
}
serverInfoManager = new ServerInfoManager(this);
infoManager = new InformationManager(this);
webServer.setInfoManager(infoManager);
Benchmark.stop("Enable", "WebServer Initialization");
processingQueue = new ProcessingQueue();
}
public static PlanBungee getInstance() {
@ -82,6 +112,12 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
for (Processor processor : processors) {
processor.process();
}
Log.info(Locale.get(Msg.DISABLED).toString());
}
private void initDatabase() throws DatabaseInitException {
db = new MySQLDB(this);
db.init();
}
@Override

View File

@ -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));
}
}

View File

@ -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);
}
}
}

View File

@ -8,6 +8,7 @@ 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.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
@ -60,7 +61,7 @@ public class ManageBackupCommand extends SubCommand {
}
runBackupTask(sender, args, database);
} catch (NullPointerException e) {
} catch (DatabaseInitException | NullPointerException e) {
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
}
return true;

View File

@ -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();
}
}

View File

@ -5,14 +5,12 @@ 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.
@ -62,15 +60,16 @@ public class ManageClearCommand extends SubCommand {
return true;
}
final Database database = ManageUtils.getDB(plugin, dbName);
// TODO CLEAR COMMAND
// 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;
// }
// 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;
}
runClearTask(sender, database);
// runClearTask(sender, database);
return true;
}

View File

@ -61,17 +61,18 @@ public class ManageHotswapCommand extends SubCommand {
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;
}
assert database != null;
try {
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;
}
assert database != null;
database.getVersion(); //Test db connection
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);

View File

@ -72,21 +72,22 @@ public class ManageMoveCommand extends SubCommand {
return true;
}
final Database fromDatabase = ManageUtils.getDB(plugin, fromDB);
// TODO Move command.
// final Database fromDatabase = ManageUtils.getDB(plugin, fromDB);
if (!Check.isTrue(Verify.notNull(fromDatabase), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
Log.error(fromDB + " was null!");
return true;
}
// if (!Check.isTrue(Verify.notNull(fromDatabase), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
// Log.error(fromDB + " was null!");
// return true;
// }
final Database toDatabase = ManageUtils.getDB(plugin, toDB);
// final Database toDatabase = ManageUtils.getDB(plugin, toDB);
if (!Check.isTrue(Verify.notNull(toDatabase), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
Log.error(toDB + " was null!");
return true;
}
// if (!Check.isTrue(Verify.notNull(toDatabase), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
// Log.error(toDB + " was null!");
// return true;
// }
runMoveTask(fromDatabase, toDatabase, sender);
// runMoveTask(fromDatabase, toDatabase, sender);
return true;
}

View File

@ -61,14 +61,15 @@ public class ManageRestoreCommand extends SubCommand {
return true;
}
final Database database = ManageUtils.getDB(plugin, db);
if (!Check.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
Log.error(db + " was null!");
return true;
}
runRestoreTask(args, sender, database);
// TODO Restore command
// final Database database = ManageUtils.getDB(plugin, db);
//
// if (!Check.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
// Log.error(db + " was null!");
// return true;
// }
//
// runRestoreTask(args, sender, database);
return true;
}
@ -90,10 +91,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());

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.database;
import main.java.com.djrapitops.plan.Plan;
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;
@ -22,7 +23,7 @@ public abstract class Database {
/**
* Instance of Plan used with this database.
*/
protected final Plan plugin;
protected final IPlan plugin;
/**
* Table representing plan_users in the database.
@ -109,7 +110,7 @@ public abstract class Database {
*
* @param plugin current instance of Plan.
*/
public Database(Plan plugin) {
public Database(IPlan plugin) {
this.plugin = plugin;
}
@ -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>

View File

@ -1,8 +1,11 @@
package main.java.com.djrapitops.plan.database.databases;
import main.java.com.djrapitops.plan.Plan;
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 org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException;
/**
* @author Rsl1122
@ -14,7 +17,7 @@ public class MySQLDB extends SQLDB {
*
* @param plugin Current instance of Plan
*/
public MySQLDB(Plan plugin) {
public MySQLDB(IPlan plugin) {
super(plugin);
}
@ -22,14 +25,19 @@ public class MySQLDB extends SQLDB {
* Setups the {@link BasicDataSource}
*/
@Override
public void setupDataSource() {
FileConfiguration config = plugin.getConfig();
public void setupDataSource() throws DatabaseInitException {
IFileConfig config = null;
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");
String host = config.getString("Database.MySQL.Host");
String port = config.getString("Database.MySQL.Port");
String port = config.getInt("Database.MySQL.Port").toString();
String database = config.getString("Database.MySQL.Database");
dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + database + "?rewriteBatchedStatements=true");

View File

@ -1,7 +1,8 @@
package main.java.com.djrapitops.plan.database.databases;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
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.*;
@ -10,7 +11,6 @@ import org.apache.commons.dbcp2.BasicDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -29,7 +29,7 @@ public abstract class SQLDB extends Database {
/**
* @param plugin
*/
public SQLDB(Plan plugin) {
public SQLDB(IPlan plugin) {
super(plugin);
usingMySQL = getName().equals("MySQL");
@ -62,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 (SQLException e) {
Log.toLog(this.getClass().getName(), e);
return false;
} finally {
Benchmark.stop("Database", benchName);
Log.logDebug("Database");
@ -89,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);
}
}
/**
@ -132,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;
}
/**
@ -174,7 +151,7 @@ public abstract class SQLDB extends Database {
/**
* Setups the {@link BasicDataSource}
*/
public abstract void setupDataSource();
public abstract void setupDataSource() throws DatabaseInitException;
/**
* @throws SQLException
@ -257,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);
}
}

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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;
@ -46,8 +47,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))

View File

@ -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()

View File

@ -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()

View File

@ -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);
}
}

View File

@ -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)

View File

@ -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.*;
@ -34,8 +35,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()

View File

@ -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()
);

View File

@ -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;
@ -39,8 +40,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)

View File

@ -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()

View File

@ -12,7 +12,6 @@ import main.java.com.djrapitops.plan.utilities.comparators.LocaleEntryComparator
import main.java.com.djrapitops.plan.utilities.comparators.StringLengthComparator;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import main.java.com.djrapitops.plan.utilities.html.Html;
import org.bukkit.ChatColor;
import java.io.File;
import java.io.FileNotFoundException;
@ -112,9 +111,9 @@ public class Locale {
private void loadDefault() {
String analysis = "Analysis | ";
String prefix = "[Plan] ";
String green = ChatColor.GREEN.toString();
String yellow = ChatColor.YELLOW.toString();
String red = ChatColor.RED.toString();
String green = "§a";
String yellow = "§e";
String red = "§c";
String arrowsRight = DefaultMessages.ARROWS_RIGHT.parse();
ColorScheme cs = plugin.getColorScheme();
String mCol = cs.getMainColor();

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.locale;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang.text.StrSubstitutor;
import org.apache.commons.lang3.text.StrSubstitutor;
import java.io.Serializable;
import java.util.HashMap;

View File

@ -8,7 +8,6 @@ import com.djrapitops.plugin.config.BukkitConfig;
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Plan;
import org.bukkit.configuration.InvalidConfigurationException;
import java.io.IOException;
import java.io.Serializable;
@ -26,8 +25,8 @@ import java.util.UUID;
* @author Rsl1122
*/
public class ServerInfoFile extends BukkitConfig {
public ServerInfoFile(Plan plugin) throws IOException, InvalidConfigurationException {
super(plugin, "ServerInfoFile");
public ServerInfoFile(Plan plugin) throws IOException {
super(plugin, "ServerInfoFile.yml");
IFileConfig config = super.getConfig();
config.copyDefaults();
config.addDefault("Server.UUID", "");

View File

@ -5,15 +5,14 @@
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;
import org.bukkit.configuration.InvalidConfigurationException;
import java.io.IOException;
import java.sql.SQLException;
@ -34,17 +33,15 @@ 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();
try {
serverInfoFile = new ServerInfoFile(plugin);
} catch (IOException | InvalidConfigurationException e) {
Log.toLog(this.getClass().getName(), e);
Log.error("Failed to read server info from local file, disabling plugin.");
plugin.disablePlugin();
} catch (IOException e) {
throw new PlanEnableException("Failed to read ServerInfoFile.yml", e);
}
Optional<UUID> serverUUID = serverInfoFile.getUUID();
@ -55,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);
}
}

View File

@ -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);

View File

@ -1,6 +1,9 @@
package main.java.com.djrapitops.plan.systems.queue;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.bungee.PlanBungee;
/**
* Abstract representation of a queue setup.
@ -24,7 +27,7 @@ public abstract class Setup<T> {
public void go() {
for (Consumer<T> consumer : consumers) {
Plan.getInstance().getRunnableFactory().createNew(consumer).runTaskAsynchronously();
getRunnableFactory().createNew(consumer).runTaskAsynchronously();
}
}
@ -33,4 +36,12 @@ public abstract class Setup<T> {
consumer.stop();
}
}
private RunnableFactory getRunnableFactory() {
if (Compatibility.isBukkitAvailable()) {
return Plan.getInstance().getRunnableFactory();
} else {
return PlanBungee.getInstance().getRunnableFactory();
}
}
}

View File

@ -25,7 +25,6 @@ import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.ChatColor;
import javax.net.ssl.*;
import java.io.*;
@ -95,7 +94,7 @@ public class WebServer {
Log.debug(usingHttps ? "Https Start Successful." : "Https Start Failed.");
if (!usingHttps) {
Log.infoColor(ChatColor.YELLOW + "User Authorization Disabled! (Not possible over http)");
Log.infoColor("§eUser Authorization Disabled! (Not possible over http)");
server = HttpServer.create(new InetSocketAddress(port), 10);
}
@ -273,7 +272,7 @@ public class WebServer {
Log.error("WebServer: SSL Context Initialization Failed.");
Log.toLog(this.getClass().getName(), e);
} catch (FileNotFoundException e) {
Log.infoColor(ChatColor.YELLOW + "WebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
Log.infoColor("§eWebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
Log.info("No Certificate -> Using Http server for Visualization.");
} catch (IOException e) {
Log.error("WebServer: " + e);

View File

@ -1,7 +1,10 @@
package main.java.com.djrapitops.plan.utilities;
import com.djrapitops.plugin.utilities.BenchUtil;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.bungee.PlanBungee;
/**
* @author Rsl1122
@ -19,7 +22,7 @@ public class Benchmark {
* @param source
*/
public static void start(String source) {
Plan.getInstance().benchmark().start(source);
getBenchUtil().start(source);
}
/**
@ -27,7 +30,7 @@ public class Benchmark {
* @return
*/
public static long stop(String source) {
long ms = Plan.getInstance().benchmark().stop(source);
long ms = getBenchUtil().stop(source);
if (ms != -1) {
Log.debug(source + " took " + ms + " ms");
}
@ -42,6 +45,14 @@ public class Benchmark {
* @return Execution time in ms.
*/
public static long stop(String task, String source) {
return Plan.getInstance().benchmark().stop(task, source);
return getBenchUtil().stop(task, source);
}
private static BenchUtil getBenchUtil() {
if (Compatibility.isBukkitAvailable()) {
return Plan.getInstance().benchmark();
} else {
return PlanBungee.getInstance().benchmark();
}
}
}

View File

@ -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;
}
}

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.utilities.html;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang.text.StrSubstitutor;
import org.apache.commons.lang3.text.StrSubstitutor;
import java.io.Serializable;
import java.util.HashMap;

View File

@ -0,0 +1,97 @@
Server:
IP: 0.0.0.0
Plugin:
Debug: 'false'
Locale: default
WriteNewLocaleFileOnEnable: false
WebServer:
Port: 8804
InternalIP: 0.0.0.0
Security:
SSL-Certificate:
KeyStorePath: 'SSLCertificate.keystore'
KeyPass: 'default'
StorePass: 'default'
Alias: 'alias'
Servers:
TODO: TODO AUTO GENERATE
Server1:
Port: 8805
Server2:
Port: 8806
Database:
MySQL:
Host: localhost
Port: 3306
User: root
Password: minecraft
Database: Plan
Commands:
AlternativeIP:
Enabled: false
Link: your.domain.here:%port%
Colors:
Main: '&2'
Secondary: '&7'
Highlight: '&f'
Analysis:
AutoRefreshPeriod: 60
Export:
Enabled: false
ExternalWebServerLinkProtocol: http
DestinationFolder: 'Analysis Results'
Data:
Commands:
LogUnknownCommands: false
CombineCommandAliases: true
Customization:
Formatting:
DecimalPoints: '#.##'
TimeAmount:
Year: '1 year, '
Years: '%years% years, '
Month: '1 month, '
Months: '%months% months, '
Day: '1d '
Days: '%days%d '
Hours: '%hours%h '
Minutes: '%minutes%m '
Seconds: '%seconds%s'
Theme:
Base: Default
Font:
FontStyleSheet: https://fonts.googleapis.com/css?family=Quicksand:300,400
FontFamily: "'Quicksand', sans-serif"
Color:
Dark: Base
Light: Base
Colors:
Main: Base
Main-Dark: Base
Secondary: Base
Secondary-Dark: Base
Tertiary: Base
Background: Base
Table-Light: Base
Table-Dark: Base
Graphs:
PunchCard: Base
PlayersOnline: Base
TPS:
High-Threshold: 18
Medium-Threshold: 10
High: Base
Medium: Base
Low: Base
CPU: Base
RAM: Base
Chunks: Base
Entities: Base

View File

@ -6,7 +6,6 @@ import main.java.com.djrapitops.plan.data.WebUser;
import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import org.bukkit.plugin.java.JavaPlugin;
import org.junit.After;
@ -66,7 +65,7 @@ public class DatabaseCommitTest {
}
@Test
public void testNoExceptionWhenCommitEmpty() throws SQLException {
public void testNoExceptionWhenCommitEmpty() throws Exception {
db.init();
db.commit(db.getConnection());
@ -76,13 +75,13 @@ public class DatabaseCommitTest {
@Ignore("//TODO")
@Test
public void testCommitToDBFile() throws SQLException {
public void testCommitToDBFile() throws Exception {
db.init();
}
@Ignore("//TODO")
@Test
public void testCommitToDBFile2() throws SQLException {
public void testCommitToDBFile2() throws Exception {
db.init();
List<TPS> tps = RandomData.randomTPS();
// db.getTpsTable().saveTPSData(tps);
@ -94,7 +93,7 @@ public class DatabaseCommitTest {
// TODO Commit tests for new Login save features.
@Test
public void testCommitToDBFile5() throws SQLException, PassEncryptUtil.CannotPerformOperationException {
public void testCommitToDBFile5() throws Exception {
db.init();
WebUser webUser = new WebUser("Test", "SHA1:rioegnorgiengoieng:oiegnoeigneo:352", 0);
db.getSecurityTable().addNewUser(webUser);

View File

@ -6,6 +6,7 @@
package test.java.main.java.com.djrapitops.plan.database;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.data.*;
import main.java.com.djrapitops.plan.data.time.GMTimes;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
@ -84,8 +85,8 @@ public class DatabaseTest {
}
@Test
public void testInit() {
assertTrue("Database failed to init.", db.init());
public void testInit() throws DatabaseInitException {
db.init();
}
@Test
@ -176,8 +177,7 @@ public class DatabaseTest {
}
@Test
public void testTPSSaving() throws SQLException {
db.init();
public void testTPSSaving() throws Exception {
TPSTable tpsTable = db.getTpsTable();
Random r = new Random();

View File

@ -6,7 +6,7 @@ import main.java.com.djrapitops.plan.data.UserInfo;
import main.java.com.djrapitops.plan.data.WebUser;
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
import main.java.com.djrapitops.plan.utilities.analysis.Point;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.RandomStringUtils;
import java.util.ArrayList;
import java.util.List;