From 45ba9d02c02d63bb0aeb419350d6990c7b70c6f8 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 18 Jan 2018 14:13:44 +0200 Subject: [PATCH] Removed some deprecated PlanPlugin methods --- .../java/com/djrapitops/plan/PlanPlugin.java | 12 ------ .../com/djrapitops/plan/ShutdownHook.java | 41 ++++++++----------- .../commands/manage/ManageHotswapCommand.java | 25 ++++------- .../commands/manage/ManageSetupCommand.java | 6 +-- .../plan/settings/ServerSpecificSettings.java | 16 ++++---- .../djrapitops/plan/system/BukkitSystem.java | 3 ++ .../plan/system/cache/SessionCache.java | 21 +++++++++- .../plan/system/database/BukkitDBSystem.java | 2 +- .../plan/system/database/DBSystem.java | 4 +- .../database/databases/sql/MySQLDB.java | 13 ++++++ .../system/database/databases/sql/SQLDB.java | 1 + .../database/databases/sql/SQLiteDB.java | 7 ++++ .../databases/sql/operation/SQLFetchOps.java | 27 ++++++++++++ .../sql/operation/SQLTransferOps.java | 22 ++++++++++ .../plan/system/info/InfoSystem.java | 20 +-------- .../info/connection/WebExceptionLogger.java | 34 +++++++++++++++ .../request/GenerateAnalysisPageRequest.java | 1 + .../request/GenerateInspectPageRequest.java | 1 + .../listeners/bukkit/DeathEventListener.java | 2 +- .../bukkit/PlayerOnlineListener.java | 22 +++++----- .../system/processing/ProcessingQueue.java | 2 +- .../processing/processors/Processor.java | 4 +- .../processors/player/RegisterProcessor.java | 2 +- .../plan/system/settings/Settings.java | 20 +++++++-- .../system/settings/config/ConfigSystem.java | 10 ++--- .../plan/system/tasks/TPSCountTimer.java | 2 +- .../webapi/bukkit/ConfigurationWebAPI.java | 3 +- .../PostOriginalBukkitSettingsWebAPI.java | 4 +- .../bungee/RequestPluginsTabWebAPI.java | 7 ++-- .../systems/info/parsing/InspectPage.java | 6 ++- .../plan/utilities/ManageUtils.java | 2 +- .../com/djrapitops/plan/SettingsTest.java | 4 +- .../main/java/test/utilities/TestInit.java | 6 +-- 33 files changed, 221 insertions(+), 131 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/info/connection/WebExceptionLogger.java diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java b/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java index 1b39877ae..d8aaa7b2c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java @@ -5,13 +5,10 @@ package com.djrapitops.plan; import com.djrapitops.plan.system.database.databases.Database; -import com.djrapitops.plan.system.processing.ProcessingQueue; -import com.djrapitops.plan.system.processing.processors.Processor; import com.djrapitops.plan.system.webserver.WebServer; import com.djrapitops.plan.systems.info.InformationManager; import com.djrapitops.plugin.IPlugin; import com.djrapitops.plugin.api.Check; -import com.djrapitops.plugin.api.config.Config; import com.djrapitops.plugin.settings.ColorScheme; import java.io.File; @@ -54,17 +51,8 @@ public interface PlanPlugin extends IPlugin { File getDataFolder(); - @Deprecated - ProcessingQueue getProcessingQueue(); - - @Deprecated - void addToProcessQueue(Processor... processors); - InputStream getResource(String resource); - @Deprecated - Config getMainConfig(); - ColorScheme getColorScheme(); boolean isReloading(); diff --git a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java index 3488a297f..59cfc4b8c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java +++ b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java @@ -4,19 +4,19 @@ */ package com.djrapitops.plan; +import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.data.Actions; import com.djrapitops.plan.data.container.Action; import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.system.cache.CacheSystem; import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.SessionCache; -import com.djrapitops.plan.system.database.databases.sql.SQLDB; -import com.djrapitops.plan.system.database.databases.sql.tables.SessionsTable; +import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.api.utility.log.Log; -import java.sql.SQLException; import java.util.Map; import java.util.UUID; @@ -30,64 +30,57 @@ import java.util.UUID; public class ShutdownHook extends Thread { private static boolean active = false; - private static DataCache dataCache; - private static SQLDB db; - public ShutdownHook(Plan plugin) { + public void register() { if (!active) { Runtime.getRuntime().addShutdownHook(this); } active = true; - - db = (SQLDB) plugin.getDB(); - dataCache = plugin.getDataCache(); } @Override public void run() { Log.debug("Shutdown hook triggered."); + + Database db = null; try { Map activeSessions = SessionCache.getActiveSessions(); long now = MiscUtils.getTime(); - if (db == null) { - return; - } + db = Database.getActive(); if (!db.isOpen()) { db.init(); } - saveFirstSessionInformation(now); - saveActiveSessions(activeSessions, now); + saveFirstSessionInformation(db, now); + saveActiveSessions(db, activeSessions, now); } catch (DBInitException e) { Log.toLog(this.getClass().getName(), e); } finally { if (db != null) { try { db.close(); - } catch (SQLException e) { + } catch (DBException e) { Log.toLog(this.getClass().getName(), e); } } - db = null; - dataCache = null; StaticHolder.unRegister(Plan.class); } } - private void saveFirstSessionInformation(long now) { + private void saveFirstSessionInformation(Database db, long now) { + DataCache dataCache = CacheSystem.getInstance().getDataCache(); for (Map.Entry entry : dataCache.getFirstSessionMsgCounts().entrySet()) { try { UUID uuid = entry.getKey(); int messagesSent = entry.getValue(); - db.getActionsTable().insertAction(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent)); - } catch (SQLException e) { + db.save().action(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent)); + } catch (DBException e) { Log.toLog(this.getClass().getName(), e); } } } - private void saveActiveSessions(Map activeSessions, long now) { - SessionsTable sessionsTable = db.getSessionsTable(); + private void saveActiveSessions(Database db, Map activeSessions, long now) { for (Map.Entry entry : activeSessions.entrySet()) { UUID uuid = entry.getKey(); Session session = entry.getValue(); @@ -98,8 +91,8 @@ public class ShutdownHook extends Thread { session.endSession(now); try { Log.debug("Shutdown: Saving a session: " + session.getSessionStart()); - sessionsTable.saveSession(uuid, session); - } catch (SQLException e) { + db.save().session(uuid, session); + } catch (DBException e) { Log.toLog(this.getClass().getName(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java index d19c5a4f1..e66e160f9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java @@ -3,20 +3,17 @@ package com.djrapitops.plan.command.commands.manage; import com.djrapitops.plan.Plan; import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.settings.locale.Msg; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.utilities.Condition; -import com.djrapitops.plan.utilities.ManageUtils; -import com.djrapitops.plugin.api.config.Config; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.utilities.Verify; -import java.io.IOException; - /** * This manage subcommand is used to swap to a different database and reload the * plugin if the connection to the new database can be established. @@ -66,7 +63,7 @@ public class ManageHotswapCommand extends SubCommand { } try { - final Database database = ManageUtils.getDB(dbName); + final Database database = DBSystem.getActiveDatabaseByName(dbName); // If DB is null return if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) { @@ -74,23 +71,19 @@ public class ManageHotswapCommand extends SubCommand { return true; } - assert database != null; - - database.getVersion(); //Test db connection + if (!database.isOpen()) { + return true; + } } catch (Exception e) { Log.toLog(this.getClass().getName(), e); sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString()); return true; } - Config config = plugin.getMainConfig(); - config.set(Settings.DB_TYPE.getPath(), dbName); - try { - config.save(); - plugin.reloadPlugin(true); - } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); - } + Settings.DB_TYPE.set(dbName); + + Settings.save(); + plugin.reloadPlugin(true); return true; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java index e643f326d..b964eeefb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java @@ -9,7 +9,6 @@ import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.webserver.webapi.bungee.RequestSetupWebAPI; import com.djrapitops.plan.utilities.Condition; -import com.djrapitops.plugin.api.config.Config; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.ISender; @@ -65,9 +64,8 @@ public class ManageSetupCommand extends SubCommand { address = address.substring(0, address.length() - 1); } try { - Config config = plugin.getMainConfig(); - config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.getPath(), false); - config.set(Settings.BUNGEE_COPY_CONFIG.getPath(), true); + Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false); + Settings.BUNGEE_COPY_CONFIG.set(true); // plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address); plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address); sender.sendMessage("§eConnection successful, Plan may restart in a few seconds, if it doesn't something has gone wrong."); diff --git a/Plan/src/main/java/com/djrapitops/plan/settings/ServerSpecificSettings.java b/Plan/src/main/java/com/djrapitops/plan/settings/ServerSpecificSettings.java index 3b7760a9f..ce62a2f25 100644 --- a/Plan/src/main/java/com/djrapitops/plan/settings/ServerSpecificSettings.java +++ b/Plan/src/main/java/com/djrapitops/plan/settings/ServerSpecificSettings.java @@ -5,8 +5,8 @@ package com.djrapitops.plan.settings; import com.djrapitops.plan.Plan; -import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plan.system.settings.config.ConfigSystem; import com.djrapitops.plugin.api.config.Config; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.utilities.Verify; @@ -27,7 +27,7 @@ public class ServerSpecificSettings { public static void updateSettings(Plan plugin, Map settings) { Log.debug("Checking new settings.."); - Config config = plugin.getMainConfig(); + Config config = ConfigSystem.getConfig(); boolean changedSomething = false; for (Map.Entry setting : settings.entrySet()) { @@ -77,9 +77,9 @@ public class ServerSpecificSettings { return value; } - public void addOriginalBukkitSettings(PlanBungee plugin, UUID serverUUID, Map settings) { + public void addOriginalBukkitSettings(UUID serverUUID, Map settings) { try { - Config config = plugin.getMainConfig(); + Config config = ConfigSystem.getConfig(); if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) { return; } @@ -111,25 +111,25 @@ public class ServerSpecificSettings { } public boolean getBoolean(UUID serverUUID, Settings setting) { - Config config = PlanBungee.getInstance().getMainConfig(); + Config config = ConfigSystem.getConfig(); String path = getPath(serverUUID, setting); return config.getBoolean(path); } public String getString(UUID serverUUID, Settings setting) { - Config config = PlanBungee.getInstance().getMainConfig(); + Config config = ConfigSystem.getConfig(); String path = getPath(serverUUID, setting); return config.getString(path); } public Integer getInt(UUID serverUUID, Settings setting) { - Config config = PlanBungee.getInstance().getMainConfig(); + Config config = ConfigSystem.getConfig(); String path = getPath(serverUUID, setting); return config.getInt(path); } public void set(UUID serverUUID, Settings setting, Object value) throws IOException { - Config config = PlanBungee.getInstance().getMainConfig(); + Config config = ConfigSystem.getConfig(); String path = getPath(serverUUID, setting); config.set(path, value); config.save(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java index 821fdce1d..248289951 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java @@ -5,6 +5,7 @@ package com.djrapitops.plan.system; import com.djrapitops.plan.Plan; +import com.djrapitops.plan.ShutdownHook; import com.djrapitops.plan.system.database.BukkitDBSystem; import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.listeners.BukkitListenerSystem; @@ -26,6 +27,8 @@ public class BukkitSystem extends PlanSystem { databaseSystem = new BukkitDBSystem(); listenerSystem = new BukkitListenerSystem(plugin); taskSystem = new BukkitTaskSystem(plugin); + + new ShutdownHook().register(); } public static BukkitSystem getInstance() { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java index e799a685d..d42fbe3bd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java @@ -1,11 +1,14 @@ package com.djrapitops.plan.system.cache; +import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.info.connection.WebExceptionLogger; import com.djrapitops.plan.system.processing.processors.Processor; import com.djrapitops.plan.utilities.MiscUtils; +import com.djrapitops.plan.utilities.NullCheck; import com.djrapitops.plugin.api.utility.log.Log; import java.util.HashMap; @@ -32,6 +35,12 @@ public class SessionCache { this.system = system; } + public static SessionCache getInstance() { + DataCache dataCache = CacheSystem.getInstance().getDataCache(); + NullCheck.check(dataCache, new IllegalStateException("Data Cache was not initialized.")); + return dataCache; + } + /** * Used to get the Map of active sessions. *

@@ -52,7 +61,11 @@ public class SessionCache { new Processor(system) { @Override public void process() { - system.getInfoManager().cachePlayer(uuid); + try { + system.getInfoSystem().generateAndCachePlayerPage(uuid); + } catch (WebException e) { + WebExceptionLogger.log(this.getClass(), e); + } } }.queue(); } @@ -69,7 +82,11 @@ public class SessionCache { Log.toLog(this.getClass().getName(), e); } finally { activeSessions.remove(uuid); - system.getInfoManager().cachePlayer(uuid); + try { + system.getInfoSystem().generateAndCachePlayerPage(uuid); + } catch (WebException e) { + WebExceptionLogger.log(this.getClass(), e); + } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/BukkitDBSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/database/BukkitDBSystem.java index 773a7d5d5..9f8d2fd1e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/BukkitDBSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/BukkitDBSystem.java @@ -22,7 +22,7 @@ public class BukkitDBSystem extends DBSystem { databases.add(new SQLiteDB()); String dbType = Settings.DB_TYPE.toString().toLowerCase().trim(); - db = getActiveDatabase(dbType); + db = getActiveDatabaseByName(dbType); db.init(); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java index 655bbf289..cc0de459f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java @@ -79,8 +79,8 @@ public abstract class DBSystem implements SubSystem { return db; } - public Database getActiveDatabase(String dbName) throws DBInitException { - for (Database database : getDatabases()) { + public static Database getActiveDatabaseByName(String dbName) throws DBInitException { + for (Database database : getInstance().getDatabases()) { String dbConfigName = database.getConfigName(); if (Verify.equalsIgnoreCase(dbName, dbConfigName)) { database.init(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java index 136606e66..b1709ac5a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/MySQLDB.java @@ -1,5 +1,7 @@ package com.djrapitops.plan.system.database.databases.sql; +import com.djrapitops.plan.system.database.databases.operation.TransferOperations; +import com.djrapitops.plan.system.database.databases.sql.operation.SQLTransferOps; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plugin.api.utility.log.Log; import org.apache.commons.dbcp2.BasicDataSource; @@ -14,6 +16,17 @@ public class MySQLDB extends SQLDB { private BasicDataSource dataSource; + private final SQLTransferOps transferOps; + + public MySQLDB() { + transferOps = new SQLTransferOps(this); + } + + @Override + public TransferOperations transfer() { + return transferOps; + } + /** * Setups the {@link BasicDataSource} */ diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java index 5e65123ed..ee856d147 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java @@ -79,6 +79,7 @@ public abstract class SQLDB extends Database { countOps = new SQLCountOps(this); searchOps = new SQLSearchOps(this); saveOps = new SQLSaveOps(this); + } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java index e9a1f1fd1..b140d0ceb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java @@ -1,7 +1,9 @@ package com.djrapitops.plan.system.database.databases.sql; import com.djrapitops.plan.PlanPlugin; +import com.djrapitops.plan.api.exceptions.connection.UnsupportedTransferDatabaseException; import com.djrapitops.plan.api.exceptions.database.DBInitException; +import com.djrapitops.plan.system.database.databases.operation.TransferOperations; import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.task.AbsRunnable; @@ -35,6 +37,11 @@ public class SQLiteDB extends SQLDB { this.dbName = dbName; } + @Override + public TransferOperations transfer() throws UnsupportedTransferDatabaseException { + throw new UnsupportedTransferDatabaseException(this); + } + /** * Setups the {@link BasicDataSource} */ diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java index 1905375d8..a7fd8ee75 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java @@ -318,4 +318,31 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { throw ErrorUtil.getExceptionFor(e); } } + + @Override + public String getPlayerName(UUID playerUUID) throws DBException { + try { + return usersTable.getPlayerName(playerUUID); + } catch (SQLException e) { + throw ErrorUtil.getExceptionFor(e); + } + } + + @Override + public Optional getServerName(UUID serverUUID) throws DBException { + try { + return serverTable.getServerName(serverUUID); + } catch (SQLException e) { + throw ErrorUtil.getExceptionFor(e); + } + } + + @Override + public List getNicknames(UUID uuid) throws DBException { + try { + return nicknamesTable.getNicknames(uuid); + } catch (SQLException e) { + throw ErrorUtil.getExceptionFor(e); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java new file mode 100644 index 000000000..e9227ac5e --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java @@ -0,0 +1,22 @@ +/* + * 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 com.djrapitops.plan.system.database.databases.sql.operation; + +import com.djrapitops.plan.system.database.databases.operation.TransferOperations; +import com.djrapitops.plan.system.database.databases.sql.SQLDB; + +/** + * TransferOperations for MySQL Database. + * + * @author Rsl1122 + */ +public class SQLTransferOps extends SQLOps implements TransferOperations { + + public SQLTransferOps(SQLDB db) { + super(db); + } + + // TODO create Transfer table +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java index 07ad5d55c..fb070d5f7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java @@ -6,7 +6,7 @@ package com.djrapitops.plan.system.info; import com.djrapitops.plan.Plan; import com.djrapitops.plan.api.exceptions.EnableException; -import com.djrapitops.plan.api.exceptions.connection.*; +import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem; @@ -14,16 +14,9 @@ import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest; import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest; import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.utilities.NullCheck; -import com.djrapitops.plugin.api.utility.log.Log; import java.util.UUID; -interface ExceptionLoggingAction { - - void performAction() throws WebException; - -} - /** * Information management system. *

@@ -86,15 +79,4 @@ public abstract class InfoSystem implements SubSystem { } public abstract void updateNetworkPage(); - - public void handlePossibleException(ExceptionLoggingAction action) { - try { - action.performAction(); - } catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException - | NotFoundException | NoServersException e) { - Log.warn(e.getMessage()); - } catch (WebException e) { - Log.toLog(this.getClass().getName(), e); - } - } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/WebExceptionLogger.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/WebExceptionLogger.java new file mode 100644 index 000000000..0fff2f658 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/WebExceptionLogger.java @@ -0,0 +1,34 @@ +/* + * 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 com.djrapitops.plan.system.info.connection; + +import com.djrapitops.plan.api.exceptions.connection.*; +import com.djrapitops.plugin.api.utility.log.Log; + +/** + * Class that decides what to do with WebExceptions. + * + * @author Rsl1122 + */ +public class WebExceptionLogger { + + public static void log(Class c, ExceptionLoggingAction action) { + try { + action.performAction(); + } catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException + | NotFoundException | NoServersException e) { + Log.warn(e.getMessage()); + } catch (WebException e) { + Log.toLog(WebExceptionLogger.class, e); + } + } + + public interface ExceptionLoggingAction { + + void performAction() throws WebException; + + } + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java index a54c6d6b3..f7af6e029 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java @@ -22,6 +22,7 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables { @Override public void placeDataToDatabase() { + // No data required in a Generate request } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateInspectPageRequest.java b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateInspectPageRequest.java index 05d2eebf5..2fd168f9a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateInspectPageRequest.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateInspectPageRequest.java @@ -26,6 +26,7 @@ public class GenerateInspectPageRequest extends InfoRequestWithVariables { @Override public void placeDataToDatabase() { + // No data required in a Generate request } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java index 71555aea7..67687c794 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java @@ -46,7 +46,7 @@ public class DeathEventListener implements Listener { LivingEntity dead = event.getEntity(); if (dead instanceof Player) { - plugin.addToProcessQueue(new DeathProcessor(dead.getUniqueId())); + new DeathProcessor(dead.getUniqueId()).queue(); } try { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index 2b5aacc84..dd02bba3b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -3,6 +3,7 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.Plan; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.cache.DataCache; +import com.djrapitops.plan.system.processing.processors.Processor; import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor; import com.djrapitops.plan.system.processing.processors.player.*; import com.djrapitops.plan.system.tasks.TaskSystem; @@ -53,11 +54,8 @@ public class PlayerOnlineListener implements Listener { PlayerLoginEvent.Result result = event.getResult(); UUID uuid = event.getPlayer().getUniqueId(); boolean op = event.getPlayer().isOp(); - if (result == PlayerLoginEvent.Result.KICK_BANNED) { - plugin.addToProcessQueue(new BanAndOpProcessor(uuid, true, op)); - } else { - plugin.addToProcessQueue(new BanAndOpProcessor(uuid, false, op)); - } + boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED; + new BanAndOpProcessor(uuid, banned, op).queue(); } catch (Exception e) { Log.toLog(this.getClass(), e); } @@ -78,7 +76,7 @@ public class PlayerOnlineListener implements Listener { return; } UUID uuid = event.getPlayer().getUniqueId(); - plugin.addToProcessQueue(new KickProcessor(uuid)); + new KickProcessor(uuid).queue(); } catch (Exception e) { Log.toLog(this.getClass(), e); } @@ -111,13 +109,13 @@ public class PlayerOnlineListener implements Listener { int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline(); cache.cacheSession(uuid, Session.start(time, world, gm)); - plugin.addToProcessQueue( + + Processor.queueMany( new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline, new IPUpdateProcessor(uuid, ip, time), new NameProcessor(uuid, playerName, displayName) ), - new NetworkPageUpdateProcessor(plugin.getInfoManager()) - ); + new NetworkPageUpdateProcessor()); } catch (Exception e) { Log.toLog(this.getClass(), e); } @@ -137,15 +135,15 @@ public class PlayerOnlineListener implements Listener { Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); - plugin.addToProcessQueue( + Processor.queueMany( new BanAndOpProcessor(uuid, player.isBanned(), player.isOp()), new EndSessionProcessor(uuid, time), - new NetworkPageUpdateProcessor(plugin.getInfoManager()) + new NetworkPageUpdateProcessor() ); if (cache.isFirstSession(uuid)) { int messagesSent = plugin.getDataCache().getFirstSessionMsgCount(uuid); - plugin.addToProcessQueue(new FirstLeaveProcessor(uuid, time, messagesSent)); + new FirstLeaveProcessor(uuid, time, messagesSent).queue(); } } catch (Exception e) { Log.toLog(this.getClass(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java index 0f8dd49c0..467e8735f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java @@ -72,7 +72,7 @@ public class ProcessingQueue extends Queue implements SubSystem { */ public void queue(Processor processor) { if (!queue.offer(processor)) { - Log.toLog("ProcessingQueue.queue", new IllegalStateException("Processor was not added to Queue")); + Log.toLog(Processor.class, new IllegalStateException("Processor was not added to Queue")); } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processor.java index 8a93a26ac..7c87c8059 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processor.java @@ -18,7 +18,7 @@ public abstract class Processor { this.object = object; } - public static void queue(Processor... processors) { + public static void queueMany(Processor... processors) { ProcessingQueue processingQueue = ProcessingQueue.getInstance(); for (Processor processor : processors) { processingQueue.queue(processor); @@ -32,6 +32,6 @@ public abstract class Processor { } public void queue() { - queue(this); + queueMany(this); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java index 2b8573bff..a77728eb3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java @@ -56,7 +56,7 @@ public class RegisterProcessor extends PlayerProcessor { } catch (DBException e) { Log.toLog(this.getClass().getName(), e); } finally { - Processor.queue(afterProcess); + Processor.queueMany(afterProcess); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java index 5896c2b57..6c9362d39 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/Settings.java @@ -4,7 +4,9 @@ import com.djrapitops.plan.settings.ServerSpecificSettings; import com.djrapitops.plan.system.settings.config.ConfigSystem; import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.config.Config; +import com.djrapitops.plugin.api.utility.log.Log; +import java.io.IOException; import java.util.List; /** @@ -125,8 +127,12 @@ public enum Settings { return !isTrue(); } - public void setValue(Boolean value) { - this.value = value; + public static void save() { + try { + ConfigSystem.getConfig().save(); + } catch (IOException e) { + Log.toLog(Settings.class, e); + } } /** @@ -162,7 +168,15 @@ public enum Settings { return configPath; } + public void setTemporaryValue(Boolean value) { + this.value = value; + } + + public void set(Object value) { + getConfig().set(getPath(), value); + } + private Config getConfig() { - return ConfigSystem.getInstance().getConfig(); + return ConfigSystem.getConfig(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java index a35dad71b..347b33441 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ConfigSystem.java @@ -39,12 +39,12 @@ public abstract class ConfigSystem implements SubSystem { return configSystem; } - public Theme getThemeSystem() { - return theme; + public static Config getConfig() { + return getInstance().config; } - public Config getConfig() { - return config; + public Theme getThemeSystem() { + return getInstance().theme; } @Override @@ -81,6 +81,6 @@ public abstract class ConfigSystem implements SubSystem { } public Locale getLocale() { - return locale; + return getInstance().locale; } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java index d1d0b7b02..a162d42db 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java @@ -36,7 +36,7 @@ public abstract class TPSCountTimer extends AbsRunnable { addNewTPSEntry(nanoTime, now); if (history.size() >= 60) { - plugin.addToProcessQueue(new TPSInsertProcessor(new ArrayList<>(history))); + new TPSInsertProcessor(new ArrayList<>(history)).queue(); history.clear(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bukkit/ConfigurationWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bukkit/ConfigurationWebAPI.java index efe6f06fa..bf2028abe 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bukkit/ConfigurationWebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bukkit/ConfigurationWebAPI.java @@ -10,6 +10,7 @@ import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.settings.ServerSpecificSettings; import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plan.system.settings.config.ConfigSystem; import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.webapi.WebAPI; import com.djrapitops.plugin.api.Check; @@ -33,7 +34,7 @@ public class ConfigurationWebAPI extends WebAPI { } if (Settings.BUNGEE_COPY_CONFIG.isFalse() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) { Log.info("Bungee Config settings overridden on this server."); - Log.debug(plugin.getMainConfig().getConfigNode("Plugin.Bungee-Override").getChildren().toString()); + Log.debug(ConfigSystem.getConfig().getConfigNode("Plugin.Bungee-Override").getChildren().toString()); return success(); } ServerSpecificSettings.updateSettings((Plan) plugin, variables); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/PostOriginalBukkitSettingsWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/PostOriginalBukkitSettingsWebAPI.java index 502d30bfb..cb6115685 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/PostOriginalBukkitSettingsWebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/PostOriginalBukkitSettingsWebAPI.java @@ -4,8 +4,6 @@ */ package com.djrapitops.plan.system.webserver.webapi.bungee; - -import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.system.settings.Settings; @@ -43,7 +41,7 @@ public class PostOriginalBukkitSettingsWebAPI extends WebAPI { settings.put("WebServerPort", webServerPort); settings.put("ServerName", serverName); settings.put("ThemeBase", themeBase); - Settings.serverSpecific().addOriginalBukkitSettings((PlanBungee) plugin, UUID.fromString(variables.get("sender")), settings); + Settings.serverSpecific().addOriginalBukkitSettings(UUID.fromString(variables.get("sender")), settings); return success(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/RequestPluginsTabWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/RequestPluginsTabWebAPI.java index 4f1090206..e26295e99 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/RequestPluginsTabWebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/webapi/bungee/RequestPluginsTabWebAPI.java @@ -4,14 +4,13 @@ */ package com.djrapitops.plan.system.webserver.webapi.bungee; - import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.api.exceptions.connection.WebException; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.processors.Processor; import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.webapi.WebAPI; import com.djrapitops.plan.system.webserver.webapi.bukkit.RequestInspectPluginsTabBukkitWebAPI; -import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.utility.log.Log; @@ -59,7 +58,7 @@ public class RequestPluginsTabWebAPI extends WebAPI { } public void sendRequestsToBukkitServers(PlanPlugin plugin, UUID uuid) { - plugin.addToProcessQueue(new Processor(uuid) { + new Processor(uuid) { @Override public void process() { try { @@ -76,6 +75,6 @@ public class RequestPluginsTabWebAPI extends WebAPI { Log.toLog(this.getClass().getName(), e); } } - }); + }.queue(); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPage.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPage.java index 36608b4ee..e8785e160 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPage.java @@ -13,7 +13,9 @@ import com.djrapitops.plan.data.element.ActivityIndex; import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.ThemeVal; +import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plan.utilities.MiscUtils; @@ -85,7 +87,7 @@ public class InspectPage extends Page { addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); String online = "Offline"; - Optional activeSession = plugin.getInfoManager().getDataCache().getCachedSession(uuid); + Optional activeSession = SessionCache.getInstance().getCachedSession(uuid); if (activeSession.isPresent()) { Session session = activeSession.get(); session.setSessionID(Integer.MAX_VALUE); @@ -234,7 +236,7 @@ public class InspectPage extends Page { addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp())); - if (!plugin.getInfoManager().isUsingAnotherWebServer()) { + if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable()) { addValue("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_")); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java index 0e773927b..c3a6d0a60 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java @@ -78,6 +78,6 @@ public class ManageUtils { @Deprecated public static Database getDB(String dbName) throws DBInitException { - return DBSystem.getInstance().getActiveDatabase(dbName); + return DBSystem.getActiveDatabaseByName(dbName); } } diff --git a/Plan/test/main/java/com/djrapitops/plan/SettingsTest.java b/Plan/test/main/java/com/djrapitops/plan/SettingsTest.java index f152fe19f..0eddb3446 100644 --- a/Plan/test/main/java/com/djrapitops/plan/SettingsTest.java +++ b/Plan/test/main/java/com/djrapitops/plan/SettingsTest.java @@ -40,10 +40,10 @@ public class SettingsTest { public void testSetValue() { Settings gatherCommands = Settings.LOG_UNKNOWN_COMMANDS; - gatherCommands.setValue(false); + gatherCommands.setTemporaryValue(false); assertFalse(gatherCommands.isTrue()); - gatherCommands.setValue(true); + gatherCommands.setTemporaryValue(true); assertTrue(gatherCommands.isTrue()); } diff --git a/Plan/test/main/java/test/utilities/TestInit.java b/Plan/test/main/java/test/utilities/TestInit.java index 9bda23bdb..d2731611a 100644 --- a/Plan/test/main/java/test/utilities/TestInit.java +++ b/Plan/test/main/java/test/utilities/TestInit.java @@ -4,8 +4,8 @@ import com.djrapitops.plan.Plan; import com.djrapitops.plan.ServerVariableHolder; import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.system.cache.DataCache; -import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.info.server.BukkitServerInfoManager; +import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.utilities.file.FileUtil; import com.djrapitops.plugin.IPlugin; import com.djrapitops.plugin.StaticHolder; @@ -111,15 +111,13 @@ public class TestInit { public void save() { } }; - when(planMock.getMainConfig()).thenReturn(iConfig); - Server mockServer = mockServer(); when(planMock.getServer()).thenReturn(mockServer); // Test log settings when(planMock.getLogger()).thenReturn(Logger.getGlobal()); - Settings.DEBUG.setValue(true); + Settings.DEBUG.setTemporaryValue(true); ServerVariableHolder serverVariableHolder = new ServerVariableHolder(mockServer);