From 55c49bd220803839fbde79480794119161a1275f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 13 Oct 2018 12:19:36 +0300 Subject: [PATCH] [Test] Fixed BukkitSystemTest This test was tougher than usual to fix, since Database could not be provided during object construction due to config setting default not being loaded. This would have lead to new installs not functioning. Fixed by replacing all Database injections with DBSystem --- .../java/com/djrapitops/plan/PlanBungee.java | 2 +- .../java/com/djrapitops/plan/PlanSponge.java | 2 +- .../com/djrapitops/plan/ShutdownHook.java | 10 ++++--- .../com/djrapitops/plan/api/ProxyAPI.java | 12 ++++---- .../com/djrapitops/plan/api/ServerAPI.java | 12 ++++---- .../plan/command/commands/AnalyzeCommand.java | 12 ++++---- .../plan/command/commands/InfoCommand.java | 10 +++---- .../plan/command/commands/InspectCommand.java | 12 ++++---- .../command/commands/ListServersCommand.java | 15 ++++++---- .../command/commands/QInspectCommand.java | 10 +++---- .../command/commands/RegisterCommand.java | 11 ++++--- .../plan/command/commands/SearchCommand.java | 10 +++---- .../manage/ManageConDebugCommand.java | 10 +++---- .../commands/manage/ManageHotSwapCommand.java | 2 +- .../commands/manage/ManageMoveCommand.java | 2 +- .../commands/manage/ManageRemoveCommand.java | 20 ++++++++----- .../manage/ManageUninstalledCommand.java | 12 ++++---- .../commands/webuser/WebCheckCommand.java | 15 ++++++---- .../commands/webuser/WebDeleteCommand.java | 12 ++++---- .../commands/webuser/WebListUsersCommand.java | 10 +++---- .../store/containers/AnalysisContainer.java | 18 +++++------ .../store/containers/NetworkContainer.java | 18 +++++------ .../modules/SystemObjectBindingModule.java | 8 ----- .../plan/system/cache/DataCache.java | 14 ++++----- .../plan/system/cache/ProxyDataCache.java | 6 ++-- .../plan/system/cache/SessionCache.java | 10 +++---- .../plan/system/database/BukkitDBSystem.java | 19 ++++++++++-- .../plan/system/database/DBSystem.java | 2 +- .../plan/system/database/ProxyDBSystem.java | 9 ++++-- .../system/importing/importers/Importer.java | 18 ++++++----- .../importers/OfflinePlayerImporter.java | 6 ++-- .../connection/InfoRequestPageHandler.java | 10 +++---- .../connection/ProxyConnectionSystem.java | 10 +++---- .../connection/ServerConnectionSystem.java | 16 +++++----- .../system/info/server/BukkitServerInfo.java | 16 +++++----- .../system/info/server/BungeeServerInfo.java | 8 +++-- .../system/info/server/SpongeServerInfo.java | 6 ++-- .../info/server/VelocityServerInfo.java | 8 +++-- .../processing/processors/Processors.java | 12 ++++---- .../processors/player/PlayerProcessors.java | 22 +++++++------- .../settings/network/NetworkSettings.java | 14 ++++----- .../plan/system/webserver/RequestHandler.java | 10 +++---- .../webserver/pages/PlayerPageHandler.java | 10 +++---- .../webserver/pages/ServerPageHandler.java | 10 +++---- .../webserver/response/ResponseFactory.java | 12 ++++---- .../utilities/file/export/HtmlExport.java | 16 +++++----- .../utilities/html/pages/PageFactory.java | 22 +++++++------- .../plan/utilities/metrics/BStatsBukkit.java | 2 +- .../plan/utilities/uuid/UUIDUtility.java | 10 +++---- .../plan/{system => }/BukkitSystemTest.java | 24 ++++++++------- .../BungeeBukkitConnectionTest.java | 5 ++-- .../plan/{system => }/BungeeSystemTest.java | 4 +-- .../plan/{system => }/SpongeSystemTest.java | 4 +-- .../webserver/HTTPSWebServerAuthTest.java | 2 +- .../utilities/mocks/PlanBukkitMocker.java | 30 +++++++++++++------ .../{ => utilities}/module/TestAPFModule.java | 2 +- 56 files changed, 333 insertions(+), 281 deletions(-) rename Plan/src/test/java/com/djrapitops/plan/{system => }/BukkitSystemTest.java (66%) rename Plan/src/test/java/com/djrapitops/plan/{system => }/BungeeBukkitConnectionTest.java (96%) rename Plan/src/test/java/com/djrapitops/plan/{system => }/BungeeSystemTest.java (97%) rename Plan/src/test/java/com/djrapitops/plan/{system => }/SpongeSystemTest.java (94%) rename Plan/src/test/java/{ => utilities}/module/TestAPFModule.java (98%) diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index 7154c0066..31d61a98b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -95,7 +95,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin { new BStatsBungee( this, - system.getDatabaseSystem().getActiveDatabase(), + system.getDatabaseSystem().getDatabase(), system.getInfoSystem().getConnectionSystem() ).registerMetrics(); diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java index 7c47dd4ec..aaf75bc29 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java @@ -125,7 +125,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin { new BStatsSponge( metrics, - system.getDatabaseSystem().getActiveDatabase() + system.getDatabaseSystem().getDatabase() ).registerMetrics(); slf4jLogger.info(locale.getString(PluginLang.ENABLED)); diff --git a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java index b7f66c131..53bcb506f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java +++ b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java @@ -10,6 +10,7 @@ import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.system.cache.SessionCache; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.error.ErrorHandler; @@ -29,12 +30,12 @@ import java.util.UUID; public class ShutdownHook extends Thread { private static ShutdownHook activated; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject - public ShutdownHook(Database database, ErrorHandler errorHandler) { - this.database = database; + public ShutdownHook(DBSystem dbSystem, ErrorHandler errorHandler) { + this.dbSystem = dbSystem; this.errorHandler = errorHandler; } @@ -71,7 +72,7 @@ public class ShutdownHook extends Thread { errorHandler.log(L.ERROR, this.getClass(), e); } finally { try { - database.close(); + dbSystem.getDatabase().close(); } catch (DBException e) { errorHandler.log(L.ERROR, this.getClass(), e); } @@ -86,6 +87,7 @@ public class ShutdownHook extends Thread { if (!end.isPresent()) { session.endSession(now); } + Database database = dbSystem.getDatabase(); if (!database.isOpen()) { database.init(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java index 02224726b..dc73dc6a0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java @@ -6,7 +6,7 @@ package com.djrapitops.plan.api; import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.PluginData; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.utilities.uuid.UUIDUtility; import com.djrapitops.plugin.logging.error.ErrorHandler; @@ -24,18 +24,18 @@ import java.util.UUID; public class ProxyAPI extends CommonAPI { private final HookHandler hookHandler; - private final Database database; + private final DBSystem dbSystem; @Inject public ProxyAPI( UUIDUtility uuidUtility, - Database database, + DBSystem dbSystem, HookHandler hookHandler, ErrorHandler errorHandler ) { super(uuidUtility, errorHandler); - this.database = database; + this.dbSystem = dbSystem; this.hookHandler = hookHandler; } @@ -46,11 +46,11 @@ public class ProxyAPI extends CommonAPI { @Override public String getPlayerName(UUID uuid) { - return database.fetch().getPlayerName(uuid); + return dbSystem.getDatabase().fetch().getPlayerName(uuid); } @Override public FetchOperations fetchFromPlanDB() { - return database.fetch(); + return dbSystem.getDatabase().fetch(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java index 48c6a4198..6bd9d8eb2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java @@ -6,7 +6,7 @@ package com.djrapitops.plan.api; import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.PluginData; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.utilities.uuid.UUIDUtility; import com.djrapitops.plugin.logging.error.ErrorHandler; @@ -24,18 +24,18 @@ import java.util.UUID; public class ServerAPI extends CommonAPI { private final HookHandler hookHandler; - private final Database database; + private final DBSystem dbSystem; @Inject public ServerAPI( UUIDUtility uuidUtility, HookHandler hookHandler, - Database database, + DBSystem dbSystem, ErrorHandler errorHandler ) { super(uuidUtility, errorHandler); this.hookHandler = hookHandler; - this.database = database; + this.dbSystem = dbSystem; } @Override @@ -45,11 +45,11 @@ public class ServerAPI extends CommonAPI { @Override public String getPlayerName(UUID uuid) { - return database.fetch().getPlayerName(uuid); + return dbSystem.getDatabase().fetch().getPlayerName(uuid); } @Override public FetchOperations fetchFromPlanDB() { - return database.fetch(); + return dbSystem.getDatabase().fetch(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java index 4b73d94de..89d565dcf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java @@ -2,7 +2,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.database.DBOpException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.server.Server; @@ -42,7 +42,7 @@ public class AnalyzeCommand extends CommandNode { private final InfoSystem infoSystem; private final ServerInfo serverInfo; private final WebServer webServer; - private final Database database; + private final DBSystem dbSystem; private final ConnectionSystem connectionSystem; private final ErrorHandler errorHandler; @@ -53,7 +53,7 @@ public class AnalyzeCommand extends CommandNode { InfoSystem infoSystem, ServerInfo serverInfo, WebServer webServer, - Database database, + DBSystem dbSystem, ErrorHandler errorHandler ) { super("analyze|analyse|analysis|a", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE); @@ -64,7 +64,7 @@ public class AnalyzeCommand extends CommandNode { connectionSystem = infoSystem.getConnectionSystem(); this.serverInfo = serverInfo; this.webServer = webServer; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; setShortHelp(locale.getString(CmdHelpLang.ANALYZE)); @@ -110,14 +110,14 @@ public class AnalyzeCommand extends CommandNode { private void sendWebUserNotificationIfNecessary(Sender sender) { if (webServer.isAuthRequired() && CommandUtils.isPlayer(sender) && - !database.check().doesWebUserExists(sender.getName())) { + !dbSystem.getDatabase().check().doesWebUserExists(sender.getName())) { sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY)); } } private Optional getServer(String[] args) { if (args.length >= 1 && connectionSystem.isServerAvailable()) { - Map bukkitServers = database.fetch().getBukkitServers(); + Map bukkitServers = dbSystem.getDatabase().fetch().getBukkitServers(); String serverIdentifier = getGivenIdentifier(args); for (Map.Entry entry : bukkitServers.entrySet()) { Server server = entry.getValue(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java index 91cbe60ee..63e6b2dc5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.PlanPlugin; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -25,7 +25,7 @@ public class InfoCommand extends CommandNode { private final PlanPlugin plugin; private final Locale locale; - private final Database database; + private final DBSystem dbSystem; private final ConnectionSystem connectionSystem; private final VersionCheckSystem versionCheckSystem; @@ -33,7 +33,7 @@ public class InfoCommand extends CommandNode { public InfoCommand( PlanPlugin plugin, Locale locale, - Database database, + DBSystem dbSystem, ConnectionSystem connectionSystem, VersionCheckSystem versionCheckSystem ) { @@ -41,7 +41,7 @@ public class InfoCommand extends CommandNode { this.plugin = plugin; this.locale = locale; - this.database = database; + this.dbSystem = dbSystem; this.connectionSystem = connectionSystem; this.versionCheckSystem = versionCheckSystem; @@ -60,7 +60,7 @@ public class InfoCommand extends CommandNode { "", locale.getString(CommandLang.INFO_VERSION, plugin.getVersion()), locale.getString(CommandLang.INFO_UPDATE, updateAvailable), - locale.getString(CommandLang.INFO_DATABASE, database.getName()), + locale.getString(CommandLang.INFO_DATABASE, dbSystem.getDatabase().getName()), locale.getString(CommandLang.INFO_BUNGEE_CONNECTION, connectedToBungee), "", ">" diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java index 69bb9f131..9db60f18d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.api.exceptions.database.DBOpException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -32,7 +32,7 @@ import java.util.UUID; public class InspectCommand extends CommandNode { private final Locale locale; - private final Database database; + private final DBSystem dbSystem; private final WebServer webServer; private final InfoProcessors processorFactory; private final Processing processing; @@ -45,7 +45,7 @@ public class InspectCommand extends CommandNode { Locale locale, InfoProcessors processorFactory, Processing processing, - Database database, + DBSystem dbSystem, WebServer webServer, ConnectionSystem connectionSystem, UUIDUtility uuidUtility, @@ -58,7 +58,7 @@ public class InspectCommand extends CommandNode { setArguments(""); this.locale = locale; - this.database = database; + this.dbSystem = dbSystem; this.webServer = webServer; this.uuidUtility = uuidUtility; this.errorHandler = errorHandler; @@ -87,7 +87,7 @@ public class InspectCommand extends CommandNode { return; } - if (!database.check().isPlayerRegistered(uuid)) { + if (!dbSystem.getDatabase().check().isPlayerRegistered(uuid)) { sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN)); return; } @@ -103,7 +103,7 @@ public class InspectCommand extends CommandNode { private void checkWebUserAndNotify(Sender sender) { if (CommandUtils.isPlayer(sender) && webServer.isAuthRequired()) { - boolean senderHasWebUser = database.check().doesWebUserExists(sender.getName()); + boolean senderHasWebUser = dbSystem.getDatabase().check().doesWebUserExists(sender.getName()); if (!senderHasWebUser) { sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY)); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java index ab7890275..3e324e2d1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.api.exceptions.database.DBOpException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -28,16 +28,21 @@ public class ListServersCommand extends CommandNode { private final Locale locale; private final ColorScheme colorScheme; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject - public ListServersCommand(Locale locale, ColorScheme colorScheme, Database database, ErrorHandler errorHandler) { + public ListServersCommand( + Locale locale, + ColorScheme colorScheme, + DBSystem dbSystem, + ErrorHandler errorHandler + ) { super("servers|serverlist|listservers|sl|ls", Permissions.MANAGE.getPermission(), CommandType.CONSOLE); this.locale = locale; this.colorScheme = colorScheme; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; setShortHelp(locale.getString(CmdHelpLang.SERVERS)); @@ -60,7 +65,7 @@ public class ListServersCommand extends CommandNode { } private void sendServers(Sender sender, Formatter serverFormatter) { - List servers = database.fetch().getServers(); + List servers = dbSystem.getDatabase().fetch().getServers(); for (Server server : servers) { sender.sendMessage(serverFormatter.apply(server)); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java index 99b6cdbd8..52e0c3bf1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java @@ -8,7 +8,7 @@ import com.djrapitops.plan.data.store.mutators.ActivityIndex; import com.djrapitops.plan.data.store.mutators.GeoInfoMutator; import com.djrapitops.plan.data.store.mutators.SessionsMutator; import com.djrapitops.plan.data.store.objects.DateHolder; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CommandLang; @@ -45,7 +45,7 @@ import java.util.UUID; public class QInspectCommand extends CommandNode { private final Locale locale; - private final Database database; + private final DBSystem dbSystem; private final PlanConfig config; private final Processing processing; private final Formatters formatters; @@ -57,7 +57,7 @@ public class QInspectCommand extends CommandNode { PlanConfig config, Locale locale, Processing processing, - Database database, + DBSystem dbSystem, UUIDUtility uuidUtility, Formatters formatters, ErrorHandler errorHandler @@ -69,7 +69,7 @@ public class QInspectCommand extends CommandNode { setArguments(""); this.locale = locale; - this.database = database; + this.dbSystem = dbSystem; this.uuidUtility = uuidUtility; this.errorHandler = errorHandler; @@ -98,7 +98,7 @@ public class QInspectCommand extends CommandNode { return; } - PlayerContainer container = database.fetch().getPlayerContainer(uuid); + PlayerContainer container = dbSystem.getDatabase().fetch().getPlayerContainer(uuid); if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) { sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN)); return; diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java index dd45cd56e..9a17b50bf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java @@ -1,6 +1,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.data.WebUser; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -40,7 +41,7 @@ public class RegisterCommand extends CommandNode { private final String notEnoughArgsMsg; private final Locale locale; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final PluginLogger logger; private final ErrorHandler errorHandler; @@ -48,16 +49,17 @@ public class RegisterCommand extends CommandNode { public RegisterCommand( Locale locale, Processing processing, - Database database, + DBSystem dbSystem, PluginLogger logger, - ErrorHandler errorHandler) { + ErrorHandler errorHandler + ) { // No Permission Requirement super("register", "", CommandType.PLAYER_OR_ARGS); this.locale = locale; this.processing = processing; this.logger = logger; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; setArguments("", "[name]", "[lvl]"); @@ -131,6 +133,7 @@ public class RegisterCommand extends CommandNode { processing.submitCritical(() -> { String userName = webUser.getName(); try { + Database database = dbSystem.getDatabase(); boolean userExists = database.check().doesWebUserExists(userName); if (userExists) { sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_EXISTS)); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java index b42f2fd76..c2bdd8f5f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.api.exceptions.database.DBOpException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CommandLang; @@ -33,20 +33,20 @@ public class SearchCommand extends CommandNode { private final Locale locale; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject public SearchCommand( Locale locale, Processing processing, - Database database, + DBSystem dbSystem, ErrorHandler errorHandler) { super("search", Permissions.SEARCH.getPermission(), CommandType.PLAYER_OR_ARGS); this.locale = locale; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; setArguments(""); @@ -68,7 +68,7 @@ public class SearchCommand extends CommandNode { processing.submitNonCritical(() -> { try { String searchTerm = args[0]; - List names = database.search().matchingPlayers(searchTerm); + List names = dbSystem.getDatabase().search().matchingPlayers(searchTerm); Collections.sort(names); boolean empty = Verify.isEmpty(names); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java index aadd3fc02..540e015a3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.command.commands.manage; import com.djrapitops.plan.api.exceptions.connection.*; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.request.InfoRequestFactory; import com.djrapitops.plan.system.info.server.Server; @@ -41,7 +41,7 @@ public class ManageConDebugCommand extends CommandNode { private final ConnectionSystem connectionSystem; private final InfoRequestFactory infoRequestFactory; private final WebServer webServer; - private final Database database; + private final DBSystem dbSystem; @Inject public ManageConDebugCommand( @@ -52,7 +52,7 @@ public class ManageConDebugCommand extends CommandNode { ConnectionSystem connectionSystem, InfoRequestFactory infoRequestFactory, WebServer webServer, - Database database + DBSystem dbSystem ) { super("con", Permissions.MANAGE.getPermission(), CommandType.ALL); @@ -63,7 +63,7 @@ public class ManageConDebugCommand extends CommandNode { this.connectionSystem = connectionSystem; this.infoRequestFactory = infoRequestFactory; this.webServer = webServer; - this.database = database; + this.dbSystem = dbSystem; setShortHelp(locale.getString(Check.isBungeeAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON)); setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_CON)); @@ -114,7 +114,7 @@ public class ManageConDebugCommand extends CommandNode { } private void testServers(Sender sender) { - List servers = database.fetch().getServers(); + List servers = dbSystem.getDatabase().fetch().getServers(); if (servers.isEmpty()) { sender.sendMessage(locale.getString(ManageLang.CON_NO_SERVERS)); 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 f2129231b..520f5ca6a 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 @@ -61,7 +61,7 @@ public class ManageHotSwapCommand extends CommandNode { Verify.isTrue(isCorrectDB, () -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName))); - Verify.isFalse(dbName.equals(dbSystem.getActiveDatabase().getConfigName()), + Verify.isFalse(dbName.equals(dbSystem.getDatabase().getConfigName()), () -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB))); try { diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java index 31a1dd1f8..d5e9adeb5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java @@ -99,7 +99,7 @@ public class ManageMoveCommand extends CommandNode { sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); - boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(dbSystem.getActiveDatabase().getConfigName()); + boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(dbSystem.getDatabase().getConfigName()); if (movingToCurrentDB) { sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName())); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java index 432ee9fe5..b91a2d4f1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java @@ -1,6 +1,7 @@ package com.djrapitops.plan.command.commands.manage; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -25,7 +26,7 @@ import java.util.UUID; /** * This manage subcommand is used to remove a single player's data from the - * database. + * dbSystem. * * @author Rsl1122 */ @@ -34,7 +35,7 @@ public class ManageRemoveCommand extends CommandNode { private final Locale locale; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final UUIDUtility uuidUtility; private final ErrorHandler errorHandler; @@ -42,7 +43,7 @@ public class ManageRemoveCommand extends CommandNode { public ManageRemoveCommand( Locale locale, Processing processing, - Database database, + DBSystem dbSystem, UUIDUtility uuidUtility, ErrorHandler errorHandler ) { @@ -50,7 +51,7 @@ public class ManageRemoveCommand extends CommandNode { this.locale = locale; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.uuidUtility = uuidUtility; this.errorHandler = errorHandler; @@ -84,19 +85,24 @@ public class ManageRemoveCommand extends CommandNode { return; } - if (!database.check().isPlayerRegistered(uuid)) { + Database db = dbSystem.getDatabase(); + if (!db.check().isPlayerRegistered(uuid)) { sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN)); return; } if (!Verify.contains("-a", args)) { - sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_REMOVAL, database.getName()))); + sender.sendMessage( + locale.getString(ManageLang.CONFIRMATION, + locale.getString(ManageLang.CONFIRM_REMOVAL, db.getName()) + ) + ); return; } sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); - database.remove().player(uuid); + db.remove().player(uuid); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); } catch (DBOpException e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java index 4aaf4acc3..b3d925b60 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.command.commands.manage; import com.djrapitops.plan.api.exceptions.database.DBOpException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.locale.Locale; @@ -33,7 +33,7 @@ public class ManageUninstalledCommand extends CommandNode { private final Locale locale; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; private final ServerInfo serverInfo; @@ -41,7 +41,7 @@ public class ManageUninstalledCommand extends CommandNode { public ManageUninstalledCommand( Locale locale, Processing processing, - Database database, + DBSystem dbSystem, ServerInfo serverInfo, ErrorHandler errorHandler ) { @@ -49,7 +49,7 @@ public class ManageUninstalledCommand extends CommandNode { this.locale = locale; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.serverInfo = serverInfo; this.errorHandler = errorHandler; @@ -76,7 +76,7 @@ public class ManageUninstalledCommand extends CommandNode { return; } - database.save().setAsUninstalled(serverUUID); + dbSystem.getDatabase().save().setAsUninstalled(serverUUID); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); } catch (DBOpException e) { sender.sendMessage("§cError occurred: " + e.toString()); @@ -87,7 +87,7 @@ public class ManageUninstalledCommand extends CommandNode { private Optional getServer(String[] args) { if (args.length >= 1) { - Map bukkitServers = database.fetch().getBukkitServers(); + Map bukkitServers = dbSystem.getDatabase().fetch().getBukkitServers(); String serverIdentifier = getGivenIdentifier(args); for (Map.Entry entry : bukkitServers.entrySet()) { Server server = entry.getValue(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java index 3be0c67b6..2b51491eb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java @@ -1,6 +1,7 @@ package com.djrapitops.plan.command.commands.webuser; import com.djrapitops.plan.data.WebUser; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -30,20 +31,21 @@ public class WebCheckCommand extends CommandNode { private final Locale locale; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject public WebCheckCommand( Locale locale, Processing processing, - Database database, - ErrorHandler errorHandler) { + DBSystem dbSystem, + ErrorHandler errorHandler + ) { super("check", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS); this.locale = locale; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; setShortHelp(locale.getString(CmdHelpLang.WEB_CHECK)); @@ -59,11 +61,12 @@ public class WebCheckCommand extends CommandNode { processing.submitNonCritical(() -> { try { - if (!database.check().doesWebUserExists(user)) { + Database db = dbSystem.getDatabase(); + if (!db.check().doesWebUserExists(user)) { sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS)); return; } - WebUser info = database.fetch().getWebUser(user); + WebUser info = db.fetch().getWebUser(user); sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel())); } catch (Exception e) { errorHandler.log(L.ERROR, this.getClass(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java index b5b591086..cad0252c7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.command.commands.webuser; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -29,21 +30,21 @@ public class WebDeleteCommand extends CommandNode { private final Locale locale; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject public WebDeleteCommand( Locale locale, Processing processing, - Database database, + DBSystem dbSystem, ErrorHandler errorHandler ) { super("delete|remove", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS); this.locale = locale; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; setShortHelp(locale.getString(CmdHelpLang.WEB_DELETE)); @@ -59,11 +60,12 @@ public class WebDeleteCommand extends CommandNode { processing.submitNonCritical(() -> { try { - if (!database.check().doesWebUserExists(user)) { + Database db = dbSystem.getDatabase(); + if (!db.check().doesWebUserExists(user)) { sender.sendMessage("§c[Plan] User Doesn't exist."); return; } - database.remove().webUser(user); + db.remove().webUser(user); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); } catch (Exception e) { errorHandler.log(L.ERROR, this.getClass(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java index 35804ca5f..5a1730c0f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.command.commands.webuser; import com.djrapitops.plan.data.WebUser; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CommandLang; @@ -30,21 +30,21 @@ public class WebListUsersCommand extends CommandNode { private final Locale locale; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject public WebListUsersCommand( Locale locale, Processing processing, - Database database, + DBSystem dbSystem, ErrorHandler errorHandler ) { super("list", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE); this.locale = locale; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; setShortHelp(locale.getString(CmdHelpLang.WEB_LIST)); @@ -54,7 +54,7 @@ public class WebListUsersCommand extends CommandNode { public void onCommand(Sender sender, String commandLabel, String[] args) { processing.submitNonCritical(() -> { try { - List users = database.fetch().getWebUsers(); + List users = dbSystem.getDatabase().fetch().getWebUsers(); users.sort(new WebUserComparator()); sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size())); for (WebUser user : users) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java index 749e0023e..95bae67e9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java @@ -8,7 +8,7 @@ import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.data.store.mutators.*; import com.djrapitops.plan.data.store.mutators.health.HealthInformation; import com.djrapitops.plan.data.time.WorldTimes; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -48,7 +48,7 @@ public class AnalysisContainer extends DataContainer { private final String version; private final PlanConfig config; private final Theme theme; - private final Database database; + private final DBSystem dbSystem; private final ServerProperties serverProperties; private final Formatters formatters; private final Graphs graphs; @@ -63,7 +63,7 @@ public class AnalysisContainer extends DataContainer { String version, PlanConfig config, Theme theme, - Database database, + DBSystem dbSystem, ServerProperties serverProperties, Formatters formatters, Graphs graphs, @@ -75,7 +75,7 @@ public class AnalysisContainer extends DataContainer { this.version = version; this.config = config; this.theme = theme; - this.database = database; + this.dbSystem = dbSystem; this.serverProperties = serverProperties; this.formatters = formatters; this.graphs = graphs; @@ -283,7 +283,7 @@ public class AnalysisContainer extends DataContainer { private void addSessionSuppliers() { Key sessionAccordion = new Key<>(SessionAccordion.class, "SESSION_ACCORDION"); - putCachingSupplier(serverNames, () -> database.fetch().getServerNames()); + putCachingSupplier(serverNames, () -> dbSystem.getDatabase().fetch().getServerNames()); putCachingSupplier(sessionAccordion, () -> accordions.serverSessionAccordion( getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all(), getSupplier(serverNames), @@ -471,7 +471,7 @@ public class AnalysisContainer extends DataContainer { private final String version; private final PlanConfig config; private final Theme theme; - private final Database database; + private final DBSystem dbSystem; private final ServerProperties serverProperties; private final Formatters formatters; private final Graphs graphs; @@ -484,7 +484,7 @@ public class AnalysisContainer extends DataContainer { @Named("currentVersion") String version, PlanConfig config, Theme theme, - Database database, + DBSystem dbSystem, ServerProperties serverProperties, Formatters formatters, Graphs graphs, @@ -495,7 +495,7 @@ public class AnalysisContainer extends DataContainer { this.version = version; this.config = config; this.theme = theme; - this.database = database; + this.dbSystem = dbSystem; this.serverProperties = serverProperties; this.formatters = formatters; this.graphs = graphs; @@ -510,7 +510,7 @@ public class AnalysisContainer extends DataContainer { version, config, theme, - database, + dbSystem, serverProperties, formatters, graphs, diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java index b3a0ea600..9e5d37828 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java @@ -7,7 +7,7 @@ import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.data.store.mutators.PlayersMutator; import com.djrapitops.plan.data.store.mutators.TPSMutator; import com.djrapitops.plan.data.store.mutators.health.NetworkHealthInformation; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -45,7 +45,7 @@ public class NetworkContainer extends DataContainer { private final String version; private final PlanConfig config; private final Theme theme; - private final Database database; + private final DBSystem dbSystem; private final ServerProperties serverProperties; private final Formatters formatters; private final Graphs graphs; @@ -55,7 +55,7 @@ public class NetworkContainer extends DataContainer { String version, PlanConfig config, Theme theme, - Database database, + DBSystem dbSystem, ServerProperties serverProperties, Formatters formatters, Graphs graphs @@ -64,7 +64,7 @@ public class NetworkContainer extends DataContainer { this.version = version; this.config = config; this.theme = theme; - this.database = database; + this.dbSystem = dbSystem; this.serverProperties = serverProperties; this.formatters = formatters; this.graphs = graphs; @@ -78,7 +78,7 @@ public class NetworkContainer extends DataContainer { } private void addServerBoxes() { - putSupplier(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA, () -> database.fetch().getPlayersOnlineForServers( + putSupplier(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA, () -> dbSystem.getDatabase().fetch().getPlayersOnlineForServers( getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>())) ); putSupplier(NetworkKeys.SERVERS_TAB, () -> { @@ -213,7 +213,7 @@ public class NetworkContainer extends DataContainer { private final Lazy version; private final Lazy config; private final Lazy theme; - private final Lazy database; + private final Lazy dbSystem; private final Lazy serverProperties; private final Lazy formatters; private final Lazy graphs; @@ -223,7 +223,7 @@ public class NetworkContainer extends DataContainer { @Named("currentVersion") Lazy version, Lazy config, Lazy theme, - Lazy database, + Lazy dbSystem, Lazy serverProperties, Lazy formatters, Lazy graphs @@ -231,7 +231,7 @@ public class NetworkContainer extends DataContainer { this.version = version; this.config = config; this.theme = theme; - this.database = database; + this.dbSystem = dbSystem; this.serverProperties = serverProperties; this.formatters = formatters; this.graphs = graphs; @@ -243,7 +243,7 @@ public class NetworkContainer extends DataContainer { version.get(), config.get(), theme.get(), - database.get(), + dbSystem.get(), serverProperties.get(), formatters.get(), graphs.get() diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/SystemObjectBindingModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/SystemObjectBindingModule.java index 2e410f8de..867183877 100644 --- a/Plan/src/main/java/com/djrapitops/plan/modules/SystemObjectBindingModule.java +++ b/Plan/src/main/java/com/djrapitops/plan/modules/SystemObjectBindingModule.java @@ -1,8 +1,6 @@ package com.djrapitops.plan.modules; import com.djrapitops.plan.data.plugin.PluginsConfigSection; -import com.djrapitops.plan.system.database.DBSystem; -import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.LocaleSystem; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -25,12 +23,6 @@ public class SystemObjectBindingModule { return localeSystem.getLocale(); } - @Provides - @Singleton - Database provideDatabase(DBSystem dbSystem) { - return dbSystem.getActiveDatabase(); - } - @Provides @Singleton PluginsConfigSection providePluginsConfigSection(PlanConfig config) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java index 3b9f5925d..6c4e2e619 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java @@ -2,7 +2,7 @@ package com.djrapitops.plan.system.cache; import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.system.SubSystem; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.error.ErrorHandler; @@ -20,7 +20,6 @@ import java.util.UUID; *
    *
  • PlayerName cache, used for reducing database calls on chat events
  • *
  • DisplayName cache, used for reducing database calls on chat events
  • - *
  • FirstSession MessageCount Map, used for tracking first session and message count on that session.
  • *
* * @author Rsl1122 @@ -30,7 +29,6 @@ import java.util.UUID; public class DataCache extends SessionCache implements SubSystem { private final ErrorHandler errorHandler; - private Database database; private final Map playerNames; private final Map uuids; @@ -38,16 +36,14 @@ public class DataCache extends SessionCache implements SubSystem { @Inject public DataCache( - Database database, + DBSystem dbSystem, ErrorHandler errorHandler ) { - super(database); + super(dbSystem); this.errorHandler = errorHandler; playerNames = new HashMap<>(); displayNames = new HashMap<>(); uuids = new HashMap<>(); - - this.database = database; } @Override @@ -93,7 +89,7 @@ public class DataCache extends SessionCache implements SubSystem { String name = playerNames.get(uuid); if (name == null) { try { - name = database.fetch().getPlayerName(uuid); + name = dbSystem.getDatabase().fetch().getPlayerName(uuid); playerNames.put(uuid, name); } catch (DBOpException e) { errorHandler.log(L.ERROR, this.getClass(), e); @@ -116,7 +112,7 @@ public class DataCache extends SessionCache implements SubSystem { if (cached == null) { List nicknames; try { - nicknames = database.fetch().getNicknames(uuid); + nicknames = dbSystem.getDatabase().fetch().getNicknames(uuid); if (!nicknames.isEmpty()) { return nicknames.get(nicknames.size() - 1); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/ProxyDataCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/ProxyDataCache.java index 4c1a844a8..be6121406 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/ProxyDataCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/ProxyDataCache.java @@ -1,6 +1,6 @@ package com.djrapitops.plan.system.cache; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plugin.logging.error.ErrorHandler; import javax.inject.Inject; @@ -18,8 +18,8 @@ import java.util.UUID; public class ProxyDataCache extends DataCache { @Inject - public ProxyDataCache(Database database, ErrorHandler errorHandler) { - super(database, errorHandler); + public ProxyDataCache(DBSystem dbSystem, ErrorHandler errorHandler) { + super(dbSystem, errorHandler); } @Override 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 2293ccd6c..37eb34267 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 @@ -2,7 +2,7 @@ package com.djrapitops.plan.system.cache; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.keys.SessionKeys; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import java.util.HashMap; import java.util.Map; @@ -19,10 +19,10 @@ public class SessionCache { private static final Map activeSessions = new HashMap<>(); - private final Database database; + protected final DBSystem dbSystem; - public SessionCache(Database database) { - this.database = database; + public SessionCache(DBSystem dbSystem) { + this.dbSystem = dbSystem; } public static Map getActiveSessions() { @@ -74,7 +74,7 @@ public class SessionCache { try { session.endSession(time); // Might throw a DBOpException - database.save().session(uuid, session); + dbSystem.getDatabase().save().session(uuid, session); } finally { removeSessionFromCache(uuid); } 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 1ddd3577d..d764bba1d 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 @@ -4,6 +4,7 @@ */ package com.djrapitops.plan.system.database; +import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.system.database.databases.sql.MySQLDB; import com.djrapitops.plan.system.database.databases.sql.SQLiteDB; import com.djrapitops.plan.system.locale.Locale; @@ -24,15 +25,29 @@ import javax.inject.Singleton; @Singleton public class BukkitDBSystem extends DBSystem { + private final PlanConfig config; + @Inject - public BukkitDBSystem(Locale locale, MySQLDB mySQLDB, SQLiteDB.Factory sqLiteDB, PlanConfig config, - PluginLogger logger, Timings timings, ErrorHandler errorHandler) { + public BukkitDBSystem( + Locale locale, + MySQLDB mySQLDB, + SQLiteDB.Factory sqLiteDB, + PlanConfig config, + PluginLogger logger, + Timings timings, + ErrorHandler errorHandler + ) { super(locale, logger, timings, errorHandler); + this.config = config; databases.add(mySQLDB); databases.add(sqLiteDB.usingDefaultFile()); + } + @Override + public void enable() throws EnableException { String dbType = config.getString(Settings.DB_TYPE).toLowerCase().trim(); db = getActiveDatabaseByName(dbType); + super.enable(); } } 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 f8f5013f3..103ceaa04 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 @@ -75,7 +75,7 @@ public abstract class DBSystem implements SubSystem { } } - public Database getActiveDatabase() { + public Database getDatabase() { return db; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/ProxyDBSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/database/ProxyDBSystem.java index 978b75179..0f31000f7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/ProxyDBSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/ProxyDBSystem.java @@ -22,8 +22,13 @@ import javax.inject.Singleton; public class ProxyDBSystem extends DBSystem { @Inject - public ProxyDBSystem(Locale locale, MySQLDB mySQLDB, - PluginLogger logger, Timings timings, ErrorHandler errorHandler) { + public ProxyDBSystem( + Locale locale, + MySQLDB mySQLDB, + PluginLogger logger, + Timings timings, + ErrorHandler errorHandler + ) { super(locale, logger, timings, errorHandler); databases.add(mySQLDB); db = mySQLDB; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/Importer.java b/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/Importer.java index 9fe2b45af..fc5c39060 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/Importer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/Importer.java @@ -13,7 +13,8 @@ import com.djrapitops.plan.data.container.UserInfo; import com.djrapitops.plan.data.store.objects.Nickname; import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.system.cache.GeolocationCache; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; +import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.system.database.databases.operation.SaveOperations; import com.djrapitops.plan.system.importing.data.ServerImportData; import com.djrapitops.plan.system.importing.data.UserImportData; @@ -38,7 +39,7 @@ import java.util.stream.Collectors; public abstract class Importer { private final GeolocationCache geolocationCache; - private final Database database; + private final DBSystem dbSystem; protected final Supplier serverUUID; private final String name; @@ -47,12 +48,12 @@ public abstract class Importer { protected Importer( Plan plugin, GeolocationCache geolocationCache, - Database database, + DBSystem dbSystem, ServerInfo serverInfo, String name ) { this.geolocationCache = geolocationCache; - this.database = database; + this.dbSystem = dbSystem; this.serverUUID = serverInfo::getServerUUID; this.name = name; @@ -97,7 +98,7 @@ public abstract class Importer { ExecutorService service = Executors.newCachedThreadPool(); - SaveOperations save = database.save(); + SaveOperations save = dbSystem.getDatabase().save(); submitTo(service, () -> save.insertTPS(ImmutableMap.of(serverUUID.get(), serverImportData.getTpsData()))); submitTo(service, () -> save.insertCommandUsage(ImmutableMap.of(serverUUID.get(), serverImportData.getCommandUsages()))); @@ -120,8 +121,9 @@ public abstract class Importer { UserImportRefiner userImportRefiner = new UserImportRefiner(plugin, userImportData); userImportData = userImportRefiner.refineData(); - Set existingUUIDs = database.fetch().getSavedUUIDs(); - Set existingUserInfoTableUUIDs = database.fetch().getSavedUUIDs(serverUUID.get()); + FetchOperations fetch = dbSystem.getDatabase().fetch(); + Set existingUUIDs = fetch.getSavedUUIDs(); + Set existingUserInfoTableUUIDs = fetch.getSavedUUIDs(serverUUID.get()); Map users = new HashMap<>(); List userInfo = new ArrayList<>(); @@ -150,7 +152,7 @@ public abstract class Importer { ExecutorService service = Executors.newCachedThreadPool(); - SaveOperations save = database.save(); + SaveOperations save = dbSystem.getDatabase().save(); save.insertUsers(users); submitTo(service, () -> save.insertSessions(ImmutableMap.of(serverUUID.get(), sessions), true)); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/OfflinePlayerImporter.java b/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/OfflinePlayerImporter.java index 1dc3aa82f..0dbcb06f5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/OfflinePlayerImporter.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/importing/importers/OfflinePlayerImporter.java @@ -6,7 +6,7 @@ package com.djrapitops.plan.system.importing.importers; import com.djrapitops.plan.Plan; import com.djrapitops.plan.system.cache.GeolocationCache; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.importing.data.ServerImportData; import com.djrapitops.plan.system.importing.data.UserImportData; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -31,10 +31,10 @@ public class OfflinePlayerImporter extends Importer { public OfflinePlayerImporter( Plan plugin, GeolocationCache geolocationCache, - Database database, + DBSystem dbSystem, ServerInfo serverInfo ) { - super(plugin, geolocationCache, database, serverInfo, "offline"); + super(plugin, geolocationCache, dbSystem, serverInfo, "offline"); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/InfoRequestPageHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/InfoRequestPageHandler.java index c30d3877a..5d0291f55 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/InfoRequestPageHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/InfoRequestPageHandler.java @@ -6,7 +6,7 @@ package com.djrapitops.plan.system.info.connection; import com.djrapitops.plan.api.exceptions.connection.NotFoundException; import com.djrapitops.plan.api.exceptions.connection.WebException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.webserver.Request; import com.djrapitops.plan.system.webserver.pages.PageHandler; @@ -32,18 +32,18 @@ import java.util.List; @Singleton public class InfoRequestPageHandler implements PageHandler { - private final Database database; + private final DBSystem dbSystem; private final ConnectionSystem connectionSystem; private final ResponseFactory responseFactory; private final PluginLogger logger; @Inject public InfoRequestPageHandler( - Database database, + DBSystem dbSystem, ConnectionSystem connectionSystem, ResponseFactory responseFactory, PluginLogger logger ) { - this.database = database; + this.dbSystem = dbSystem; this.connectionSystem = connectionSystem; this.responseFactory = responseFactory; this.logger = logger; @@ -68,7 +68,7 @@ public class InfoRequestPageHandler implements PageHandler { Verify.nullCheck(infoRequest, () -> new NotFoundException("Info Request has not been registered.")); logger.debug("ConnectionIn: " + infoRequest.getClass().getSimpleName()); - return new ConnectionIn(request, infoRequest, database, connectionSystem).handleRequest(); + return new ConnectionIn(request, infoRequest, dbSystem.getDatabase(), connectionSystem).handleRequest(); } catch (WebException e) { responseCode = getResponseCodeFor(e); throw e; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ProxyConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ProxyConnectionSystem.java index 54ed35ed3..7e86576a9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ProxyConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ProxyConnectionSystem.java @@ -6,7 +6,7 @@ package com.djrapitops.plan.system.info.connection; import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.database.DBOpException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.request.*; import com.djrapitops.plan.system.info.server.Server; @@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit; @Singleton public class ProxyConnectionSystem extends ConnectionSystem { - private final Database database; + private final DBSystem dbSystem; private final Lazy webServer; private final ErrorHandler errorHandler; private final WebExceptionLogger webExceptionLogger; @@ -38,7 +38,7 @@ public class ProxyConnectionSystem extends ConnectionSystem { @Inject public ProxyConnectionSystem( - Database database, + DBSystem dbSystem, Lazy webServer, ConnectionLog connectionLog, InfoRequests infoRequests, @@ -48,7 +48,7 @@ public class ProxyConnectionSystem extends ConnectionSystem { WebExceptionLogger webExceptionLogger ) { super(connectionLog, infoRequests, infoSystem, serverInfo); - this.database = database; + this.dbSystem = dbSystem; this.webServer = webServer; this.errorHandler = errorHandler; this.webExceptionLogger = webExceptionLogger; @@ -58,7 +58,7 @@ public class ProxyConnectionSystem extends ConnectionSystem { private void refreshServerMap() { if (latestServerMapRefresh < System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(15L)) { try { - bukkitServers = database.fetch().getBukkitServers(); + bukkitServers = dbSystem.getDatabase().fetch().getBukkitServers(); latestServerMapRefresh = System.currentTimeMillis(); } catch (DBOpException e) { errorHandler.log(L.ERROR, this.getClass(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ServerConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ServerConnectionSystem.java index 9a8c3be0b..fe702cf69 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ServerConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ServerConnectionSystem.java @@ -6,7 +6,8 @@ package com.djrapitops.plan.system.info.connection; import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException; import com.djrapitops.plan.api.exceptions.connection.NoServersException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; +import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.request.*; import com.djrapitops.plan.system.info.server.Server; @@ -23,7 +24,6 @@ import dagger.Lazy; import javax.inject.Inject; import javax.inject.Singleton; -import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -38,7 +38,7 @@ public class ServerConnectionSystem extends ConnectionSystem { private final Locale locale; private final PlanConfig config; private final Processing processing; - private final Database database; + private final DBSystem dbSystem; private final Lazy webServer; private final PluginLogger pluginLogger; private final WebExceptionLogger webExceptionLogger; @@ -52,7 +52,7 @@ public class ServerConnectionSystem extends ConnectionSystem { Locale locale, PlanConfig config, Processing processing, - Database database, + DBSystem dbSystem, Lazy webServer, ConnectionLog connectionLog, InfoRequests infoRequests, @@ -65,7 +65,7 @@ public class ServerConnectionSystem extends ConnectionSystem { this.locale = locale; this.config = config; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.webServer = webServer; this.pluginLogger = pluginLogger; this.webExceptionLogger = webExceptionLogger; @@ -75,9 +75,9 @@ public class ServerConnectionSystem extends ConnectionSystem { private void refreshServerMap() { processing.submitNonCritical(() -> { if (latestServerMapRefresh < System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(15L)) { - Optional bungeeInformation = database.fetch().getBungeeInformation(); - bungeeInformation.ifPresent(server -> mainServer = server); - bukkitServers = database.fetch().getBukkitServers(); + FetchOperations fetch = dbSystem.getDatabase().fetch(); + mainServer = fetch.getBungeeInformation().orElse(null); + bukkitServers = fetch.getBukkitServers(); latestServerMapRefresh = System.currentTimeMillis(); } }); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java index a5ac57f02..50e6ddb2a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java @@ -6,6 +6,7 @@ package com.djrapitops.plan.system.info.server; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.settings.Settings; @@ -32,19 +33,19 @@ public class BukkitServerInfo extends ServerInfo { private final Lazy webServer; private final PlanConfig config; private ServerInfoFile serverInfoFile; - private Database database; + private DBSystem dbSystem; @Inject public BukkitServerInfo( ServerProperties serverProperties, ServerInfoFile serverInfoFile, - Database database, + DBSystem dbSystem, Lazy webServer, PlanConfig config ) { super(serverProperties); this.serverInfoFile = serverInfoFile; - this.database = database; + this.dbSystem = dbSystem; this.webServer = webServer; this.config = config; } @@ -73,6 +74,7 @@ public class BukkitServerInfo extends ServerInfo { } private Server updateDbInfo(UUID serverUUID) throws IOException { + Database database = dbSystem.getDatabase(); Optional serverID = database.fetch().getServerID(serverUUID); if (!serverID.isPresent()) { return registerServer(serverUUID); @@ -99,14 +101,12 @@ public class BukkitServerInfo extends ServerInfo { int maxPlayers = serverProperties.getMaxPlayers(); Server server = new Server(-1, serverUUID, name, webAddress, maxPlayers); + + Database database = dbSystem.getDatabase(); database.save().serverInfoForThisServer(server); Optional serverID = database.fetch().getServerID(serverUUID); - if (!serverID.isPresent()) { - throw new IllegalStateException("Failed to Register Server (ID not found)"); - } - - int id = serverID.get(); + int id = serverID.orElseThrow(() -> new IllegalStateException("Failed to Register Server (ID not found)")); server.setId(id); serverInfoFile.saveServerUUID(serverUUID); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java index 000c58352..7e21a8787 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java @@ -6,6 +6,7 @@ package com.djrapitops.plan.system.info.server; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.webserver.WebServer; @@ -25,19 +26,19 @@ import java.util.UUID; @Singleton public class BungeeServerInfo extends ServerInfo { - private final Database database; + private final DBSystem dbSystem; private final Lazy webServer; private final PluginLogger logger; @Inject public BungeeServerInfo( ServerProperties serverProperties, - Database database, + DBSystem dbSystem, Lazy webServer, PluginLogger logger ) { super(serverProperties); - this.database = database; + this.dbSystem = dbSystem; this.webServer = webServer; this.logger = logger; } @@ -47,6 +48,7 @@ public class BungeeServerInfo extends ServerInfo { checkIfDefaultIP(); try { + Database database = dbSystem.getDatabase(); Optional bungeeInfo = database.fetch().getBungeeInformation(); if (bungeeInfo.isPresent()) { server = bungeeInfo.get(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java index 5226b0778..8a97a0498 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java @@ -1,6 +1,6 @@ package com.djrapitops.plan.system.info.server; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.webserver.WebServer; @@ -14,10 +14,10 @@ public class SpongeServerInfo extends BukkitServerInfo { public SpongeServerInfo( ServerProperties serverProperties, ServerInfoFile serverInfoFile, - Database database, + DBSystem dbSystem, Lazy webServer, PlanConfig config ) { - super(serverProperties, serverInfoFile, database, webServer, config); + super(serverProperties, serverInfoFile, dbSystem, webServer, config); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/VelocityServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/VelocityServerInfo.java index b0a96c951..e96f6fce8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/VelocityServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/VelocityServerInfo.java @@ -6,6 +6,7 @@ package com.djrapitops.plan.system.info.server; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.webserver.WebServer; @@ -25,19 +26,19 @@ import java.util.UUID; @Singleton public class VelocityServerInfo extends ServerInfo { - private final Database database; + private final DBSystem dbSystem; private final Lazy webServer; private final PluginLogger logger; @Inject public VelocityServerInfo( ServerProperties serverProperties, - Database database, + DBSystem dbSystem, Lazy webServer, PluginLogger logger ) { super(serverProperties); - this.database = database; + this.dbSystem = dbSystem; this.webServer = webServer; this.logger = logger; } @@ -47,6 +48,7 @@ public class VelocityServerInfo extends ServerInfo { checkIfDefaultIP(); try { + Database database = dbSystem.getDatabase(); Optional bungeeInfo = database.fetch().getBungeeInformation(); if (bungeeInfo.isPresent()) { server = bungeeInfo.get(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processors.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processors.java index 2389dc7aa..fb0d46dca 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processors.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/Processors.java @@ -1,7 +1,7 @@ package com.djrapitops.plan.system.processing.processors; import com.djrapitops.plan.data.container.TPS; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.processing.processors.info.InfoProcessors; import com.djrapitops.plan.system.processing.processors.player.PlayerProcessors; import dagger.Lazy; @@ -21,26 +21,26 @@ public class Processors { private final PlayerProcessors playerProcessors; private final InfoProcessors infoProcessors; - private final Lazy database; + private final Lazy dbSystem; @Inject public Processors( PlayerProcessors playerProcessors, InfoProcessors infoProcessors, - Lazy database + Lazy dbSystem ) { this.playerProcessors = playerProcessors; this.infoProcessors = infoProcessors; - this.database = database; + this.dbSystem = dbSystem; } public TPSInsertProcessor tpsInsertProcessor(List tpsList) { - return new TPSInsertProcessor(tpsList, database.get()); + return new TPSInsertProcessor(tpsList, dbSystem.get().getDatabase()); } public CommandProcessor commandProcessor(String command) { - return new CommandProcessor(command, database.get()); + return new CommandProcessor(command, dbSystem.get().getDatabase()); } public PlayerProcessors player() { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java index 81eefa336..3059fcdae 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/PlayerProcessors.java @@ -4,7 +4,7 @@ import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.data.store.objects.Nickname; import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.GeolocationCache; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; import dagger.Lazy; @@ -26,7 +26,7 @@ public class PlayerProcessors { private final Lazy processing; private final Lazy serverInfo; - private final Lazy database; + private final Lazy dbSystem; private final Lazy dataCache; private final Lazy geolocationCache; @@ -34,23 +34,23 @@ public class PlayerProcessors { public PlayerProcessors( Lazy processing, Lazy serverInfo, - Lazy database, + Lazy dbSystem, Lazy dataCache, Lazy geolocationCache ) { this.processing = processing; this.serverInfo = serverInfo; - this.database = database; + this.dbSystem = dbSystem; this.dataCache = dataCache; this.geolocationCache = geolocationCache; } public BanAndOpProcessor banAndOpProcessor(UUID uuid, Supplier banned, boolean op) { - return new BanAndOpProcessor(uuid, banned, op, database.get()); + return new BanAndOpProcessor(uuid, banned, op, dbSystem.get().getDatabase()); } public ProxyRegisterProcessor proxyRegisterProcessor(UUID uuid, String name, long registered, Runnable... afterProcess) { - return new ProxyRegisterProcessor(uuid, name, registered, processing.get(), database.get(), afterProcess); + return new ProxyRegisterProcessor(uuid, name, registered, processing.get(), dbSystem.get().getDatabase(), afterProcess); } public EndSessionProcessor endSessionProcessor(UUID uuid, long time) { @@ -58,24 +58,24 @@ public class PlayerProcessors { } public IPUpdateProcessor ipUpdateProcessor(UUID uuid, InetAddress ip, long time) { - return new IPUpdateProcessor(uuid, ip, time, database.get(), geolocationCache.get()); + return new IPUpdateProcessor(uuid, ip, time, dbSystem.get().getDatabase(), geolocationCache.get()); } public KickProcessor kickProcessor(UUID uuid) { - return new KickProcessor(uuid, database.get()); + return new KickProcessor(uuid, dbSystem.get().getDatabase()); } public NameProcessor nameProcessor(UUID uuid, String playerName, String displayName) { Nickname nickname = new Nickname(displayName, System.currentTimeMillis(), serverInfo.get().getServerUUID()); - return new NameProcessor(uuid, playerName, nickname, database.get(), dataCache.get()); + return new NameProcessor(uuid, playerName, nickname, dbSystem.get().getDatabase(), dataCache.get()); } public PingInsertProcessor pingInsertProcessor(UUID uuid, List> pingList) { - return new PingInsertProcessor(uuid, serverInfo.get().getServerUUID(), pingList, database.get()); + return new PingInsertProcessor(uuid, serverInfo.get().getServerUUID(), pingList, dbSystem.get().getDatabase()); } public RegisterProcessor registerProcessor(UUID uuid, Supplier registered, String name, Runnable... afterProcess) { - return new RegisterProcessor(uuid, registered, name, processing.get(), database.get(), afterProcess); + return new RegisterProcessor(uuid, registered, name, processing.get(), dbSystem.get().getDatabase(), afterProcess); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java index a51d21748..7e794f721 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java @@ -4,7 +4,7 @@ */ package com.djrapitops.plan.system.settings.network; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.settings.ServerSpecificSettings; @@ -42,7 +42,7 @@ public class NetworkSettings { private final Lazy config; private final ServerSpecificSettings serverSpecificSettings; private final Processing processing; - private final Lazy database; + private final Lazy dbSystem; private final Lazy serverInfo; private final PluginLogger logger; private final ErrorHandler errorHandler; @@ -52,7 +52,7 @@ public class NetworkSettings { Lazy config, ServerSpecificSettings serverSpecificSettings, Processing processing, - Lazy database, + Lazy dbSystem, Lazy serverInfo, PluginLogger logger, ErrorHandler errorHandler @@ -60,7 +60,7 @@ public class NetworkSettings { this.config = config; this.serverSpecificSettings = serverSpecificSettings; this.processing = processing; - this.database = database; + this.dbSystem = dbSystem; this.serverInfo = serverInfo; this.logger = logger; this.errorHandler = errorHandler; @@ -90,7 +90,7 @@ public class NetworkSettings { void loadFromDatabase() { logger.debug("NetworkSettings: Fetch Config settings from database.."); - Optional encodedConfigSettings = database.get().transfer().getEncodedConfigSettings(); + Optional encodedConfigSettings = dbSystem.get().getDatabase().transfer().getEncodedConfigSettings(); if (!encodedConfigSettings.isPresent()) { logger.debug("NetworkSettings: No Config settings in database."); @@ -157,7 +157,7 @@ public class NetworkSettings { String base64 = Base64Util.encode(transferBuilder.toString()); logger.debug("NetworkSettings: Saving Config settings to database.."); - database.get().transfer().storeConfigSettings(base64); + dbSystem.get().getDatabase().transfer().storeConfigSettings(base64); } private Map getConfigValues() { @@ -230,7 +230,7 @@ public class NetworkSettings { private void addServerSpecificValues(Map configValues) { logger.debug("NetworkSettings: Adding Server-specific Config Values.."); - for (UUID serverUUID : database.get().fetch().getServerUUIDs()) { + for (UUID serverUUID : dbSystem.get().getDatabase().fetch().getServerUUIDs()) { String theme = serverSpecificSettings.getString(serverUUID, THEME_BASE); Integer port = serverSpecificSettings.getInt(serverUUID, WEBSERVER_PORT); String name = serverSpecificSettings.getString(serverUUID, SERVER_NAME); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java index 90b52e32c..0c965138b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/RequestHandler.java @@ -5,7 +5,7 @@ package com.djrapitops.plan.system.webserver; import com.djrapitops.plan.system.DebugChannels; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -39,7 +39,7 @@ public class RequestHandler implements HttpHandler { private final Locale locale; private final PlanConfig config; private final Theme theme; - private final Database database; + private final DBSystem dbSystem; private final ResponseHandler responseHandler; private final Timings timings; private final PluginLogger logger; @@ -50,7 +50,7 @@ public class RequestHandler implements HttpHandler { Locale locale, PlanConfig config, Theme theme, - Database database, + DBSystem dbSystem, ResponseHandler responseHandler, Timings timings, PluginLogger logger, @@ -59,7 +59,7 @@ public class RequestHandler implements HttpHandler { this.locale = locale; this.config = config; this.theme = theme; - this.database = database; + this.dbSystem = dbSystem; this.responseHandler = responseHandler; this.timings = timings; this.logger = logger; @@ -111,7 +111,7 @@ public class RequestHandler implements HttpHandler { String authLine = authorization.get(0); if (authLine.contains("Basic ")) { - return new BasicAuthentication(authLine.split(" ")[1], database); + return new BasicAuthentication(authLine.split(" ")[1], dbSystem.getDatabase()); } return null; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java index 28df3bb0c..37a8ea36f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java @@ -8,7 +8,7 @@ import com.djrapitops.plan.api.exceptions.WebUserAuthException; import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.data.WebUser; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.webserver.Request; import com.djrapitops.plan.system.webserver.auth.Authentication; @@ -33,19 +33,19 @@ import java.util.UUID; public class PlayerPageHandler implements PageHandler { private final ResponseFactory responseFactory; - private final Database database; + private final DBSystem dbSystem; private final InfoSystem infoSystem; private final UUIDUtility uuidUtility; @Inject public PlayerPageHandler( ResponseFactory responseFactory, - Database database, + DBSystem dbSystem, InfoSystem infoSystem, UUIDUtility uuidUtility ) { this.responseFactory = responseFactory; - this.database = database; + this.dbSystem = dbSystem; this.infoSystem = infoSystem; this.uuidUtility = uuidUtility; } @@ -66,7 +66,7 @@ public class PlayerPageHandler implements PageHandler { } try { // TODO Move this Database dependency to PlayerPage generation in PageFactory instead. - if (database.check().isPlayerRegistered(uuid)) { + if (dbSystem.getDatabase().check().isPlayerRegistered(uuid)) { if (raw) { return ResponseCache.loadResponse(PageId.RAW_PLAYER.of(uuid), () -> responseFactory.rawPlayerPageResponse(uuid)); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/ServerPageHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/ServerPageHandler.java index 2d05e9fe0..15955fdf5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/ServerPageHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/ServerPageHandler.java @@ -8,7 +8,7 @@ import com.djrapitops.plan.api.exceptions.WebUserAuthException; import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException; import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.WebException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; @@ -36,7 +36,7 @@ public class ServerPageHandler implements PageHandler { private final Processing processing; private final ResponseFactory responseFactory; - private final Database database; + private final DBSystem dbSystem; private final ServerInfo serverInfo; private final InfoSystem infoSystem; @@ -44,13 +44,13 @@ public class ServerPageHandler implements PageHandler { public ServerPageHandler( Processing processing, ResponseFactory responseFactory, - Database database, + DBSystem dbSystem, ServerInfo serverInfo, InfoSystem infoSystem ) { this.processing = processing; this.responseFactory = responseFactory; - this.database = database; + this.dbSystem = dbSystem; this.serverInfo = serverInfo; this.infoSystem = infoSystem; } @@ -97,7 +97,7 @@ public class ServerPageHandler implements PageHandler { if (!target.isEmpty()) { try { String serverName = target.get(0).replace("%20", " "); - Optional serverUUIDOptional = database.fetch().getServerUUID(serverName); + Optional serverUUIDOptional = dbSystem.getDatabase().fetch().getServerUUID(serverName); if (serverUUIDOptional.isPresent()) { serverUUID = serverUUIDOptional.get(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java index e9b43ed7b..5203d97cf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java @@ -2,7 +2,7 @@ package com.djrapitops.plan.system.webserver.response; import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.WebUserAuthException; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.ErrorPageLang; @@ -30,7 +30,7 @@ public class ResponseFactory { private final PlanFiles files; private final PageFactory pageFactory; private final Locale locale; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject @@ -39,14 +39,14 @@ public class ResponseFactory { PlanFiles files, PageFactory pageFactory, Locale locale, - Database database, + DBSystem dbSystem, ErrorHandler errorHandler ) { this.version = version; this.files = files; this.pageFactory = pageFactory; this.locale = locale; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; } @@ -88,11 +88,11 @@ public class ResponseFactory { } public RawDataResponse rawPlayerPageResponse(UUID uuid) { - return new RawPlayerDataResponse(database.fetch().getPlayerContainer(uuid)); + return new RawPlayerDataResponse(dbSystem.getDatabase().fetch().getPlayerContainer(uuid)); } public RawDataResponse rawServerPageResponse(UUID serverUUID) { - return new RawServerDataResponse(database.fetch().getServerContainer(serverUUID)); + return new RawServerDataResponse(dbSystem.getDatabase().fetch().getServerContainer(serverUUID)); } public Response javaScriptResponse(String fileName) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java index 5bacdec75..4071fce22 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java @@ -8,7 +8,7 @@ import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.data.container.UserInfo; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -43,7 +43,7 @@ public class HtmlExport extends SpecificExport { private final Theme theme; private final Processing processing; private final PlanFiles files; - private final Database database; + private final DBSystem dbSystem; private final PageFactory pageFactory; private final ConnectionSystem connectionSystem; private final ErrorHandler errorHandler; @@ -55,7 +55,7 @@ public class HtmlExport extends SpecificExport { PlanConfig config, Theme theme, Processing processing, - Database database, + DBSystem dbSystem, PageFactory pageFactory, ServerInfo serverInfo, ConnectionSystem connectionSystem, @@ -66,7 +66,7 @@ public class HtmlExport extends SpecificExport { this.theme = theme; this.processing = processing; this.files = files; - this.database = database; + this.dbSystem = dbSystem; this.pageFactory = pageFactory; this.connectionSystem = connectionSystem; this.errorHandler = errorHandler; @@ -76,7 +76,7 @@ public class HtmlExport extends SpecificExport { if (Check.isBukkitAvailable() && connectionSystem.isServerAvailable()) { return; } - Optional serverName = database.fetch().getServerName(serverUUID); + Optional serverName = dbSystem.getDatabase().fetch().getServerName(serverUUID); serverName.ifPresent(name -> processing.submitNonCritical(() -> { try { exportAvailableServerPage(serverUUID, name); @@ -90,7 +90,7 @@ public class HtmlExport extends SpecificExport { if (Check.isBukkitAvailable() && connectionSystem.isServerAvailable()) { return; } - String playerName = database.fetch().getPlayerName(uuid); + String playerName = dbSystem.getDatabase().fetch().getPlayerName(uuid); if (playerName != null) { processing.submitNonCritical(() -> { try { @@ -137,13 +137,13 @@ public class HtmlExport extends SpecificExport { } private void exportAvailablePlayers() throws IOException { - for (Map.Entry entry : database.fetch().getUsers().entrySet()) { + for (Map.Entry entry : dbSystem.getDatabase().fetch().getUsers().entrySet()) { exportAvailablePlayerPage(entry.getKey(), entry.getValue().getName()); } } private void exportAvailableServerPages() throws IOException { - Map serverNames = database.fetch().getServerNames(); + Map serverNames = dbSystem.getDatabase().fetch().getServerNames(); for (Map.Entry entry : serverNames.entrySet()) { exportAvailableServerPage(entry.getKey(), entry.getValue()); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java index a6aecf08c..6553f9d6c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java @@ -4,7 +4,8 @@ import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.store.containers.AnalysisContainer; import com.djrapitops.plan.data.store.containers.NetworkContainer; import com.djrapitops.plan.data.store.containers.PlayerContainer; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; +import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -39,7 +40,7 @@ public class PageFactory { private final Lazy fileSystem; private final Lazy config; private final Lazy theme; - private final Lazy database; + private final Lazy dbSystem; private final Lazy serverInfo; private final Lazy connectionSystem; private final Lazy graphs; @@ -59,7 +60,7 @@ public class PageFactory { Lazy fileSystem, Lazy config, Lazy theme, - Lazy database, + Lazy dbSystem, Lazy serverInfo, Lazy connectionSystem, Lazy graphs, @@ -77,7 +78,7 @@ public class PageFactory { this.fileSystem = fileSystem; this.config = config; this.theme = theme; - this.database = database; + this.dbSystem = dbSystem; this.serverInfo = serverInfo; this.connectionSystem = connectionSystem; this.graphs = graphs; @@ -95,26 +96,27 @@ public class PageFactory { public DebugPage debugPage() { return new DebugPage( version, - database.get(), serverInfo.get(), connectionSystem.get(), formatters.get(), + dbSystem.get().getDatabase(), serverInfo.get(), connectionSystem.get(), formatters.get(), debugLogger.get(), timings.get(), errorHandler.get() ); } public PlayersPage playersPage() { return new PlayersPage(version, fileSystem.get(), config.get(), - database.get(), serverInfo.get(), tables.get(), + dbSystem.get().getDatabase(), serverInfo.get(), tables.get(), timings.get()); } public AnalysisPage analysisPage(UUID serverUUID) { AnalysisContainer analysisContainer = analysisContainerFactory.get() - .forServerContainer(database.get().fetch().getServerContainer(serverUUID)); + .forServerContainer(dbSystem.get().getDatabase().fetch().getServerContainer(serverUUID)); return new AnalysisPage(analysisContainer, fileSystem.get(), formatters.get().decimals(), timings.get()); } public InspectPage inspectPage(UUID uuid) { - PlayerContainer player = database.get().fetch().getPlayerContainer(uuid); - Map serverNames = database.get().fetch().getServerNames(); + FetchOperations fetch = dbSystem.get().getDatabase().fetch(); + PlayerContainer player = fetch.getPlayerContainer(uuid); + Map serverNames = fetch.getServerNames(); return new InspectPage( player, serverNames, version, @@ -129,7 +131,7 @@ public class PageFactory { } public NetworkPage networkPage() { - NetworkContainer networkContainer = database.get().fetch().getNetworkContainer(); // Not cached, big. + NetworkContainer networkContainer = dbSystem.get().getDatabase().fetch().getNetworkContainer(); // Not cached, big. return new NetworkPage(networkContainer, analysisPluginsTabContentCreator.get(), fileSystem.get(), serverInfo.get().getServerProperties()); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsBukkit.java b/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsBukkit.java index df3881a97..1ac0f7de9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsBukkit.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/metrics/BStatsBukkit.java @@ -25,7 +25,7 @@ public class BStatsBukkit { if ("CraftBukkit".equals(serverType) && Check.isSpigotAvailable()) { serverType = "Spigot"; } - String databaseType = plugin.getSystem().getDatabaseSystem().getActiveDatabase().getName(); + String databaseType = plugin.getSystem().getDatabaseSystem().getDatabase().getName(); addStringSettingPie("server_type", serverType); addStringSettingPie("database_type", databaseType); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java b/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java index 0bf1daf63..958768918 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java @@ -7,7 +7,7 @@ package com.djrapitops.plan.utilities.uuid; import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.system.cache.DataCache; -import com.djrapitops.plan.system.database.databases.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plugin.api.utility.UUIDFetcher; import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.error.ErrorHandler; @@ -23,13 +23,13 @@ import java.util.UUID; public class UUIDUtility { private final DataCache dataCache; - private final Database database; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject - public UUIDUtility(DataCache dataCache, Database database, ErrorHandler errorHandler) { + public UUIDUtility(DataCache dataCache, DBSystem dbSystem, ErrorHandler errorHandler) { this.dataCache = dataCache; - this.database = database; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; } @@ -46,7 +46,7 @@ public class UUIDUtility { return uuidOf; } try { - uuid = database.fetch().getUuidOf(playerName); + uuid = dbSystem.getDatabase().fetch().getUuidOf(playerName); } catch (DBOpException e) { errorHandler.log(L.ERROR, UUIDUtility.class, e); } diff --git a/Plan/src/test/java/com/djrapitops/plan/system/BukkitSystemTest.java b/Plan/src/test/java/com/djrapitops/plan/BukkitSystemTest.java similarity index 66% rename from Plan/src/test/java/com/djrapitops/plan/system/BukkitSystemTest.java rename to Plan/src/test/java/com/djrapitops/plan/BukkitSystemTest.java index 5d13b494c..fac4192d1 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/BukkitSystemTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/BukkitSystemTest.java @@ -2,10 +2,12 @@ * License is provided in the jar as LICENSE also here: * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE */ -package com.djrapitops.plan.system; +package com.djrapitops.plan; -import com.djrapitops.plan.Plan; import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.system.PlanSystem; +import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plan.system.settings.config.PlanConfig; import org.junit.*; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; @@ -22,18 +24,22 @@ public class BukkitSystemTest { @ClassRule public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - private static Plan planMock; private PlanSystem bukkitSystem; + private static PlanComponent COMPONENT; @BeforeClass public static void setUpClass() throws Exception { PlanBukkitMocker mockUtil = PlanBukkitMocker.setUp() - .withDataFolder(temporaryFolder.getRoot()) - .withLogging() + .withDataFolder(temporaryFolder.newFolder()) .withPluginDescription() .withResourceFetchingFromJar() .withServer(); - planMock = mockUtil.getPlanMock(); + COMPONENT = DaggerPlanComponent.builder().plan(mockUtil.getPlanMock()).build(); + } + + @Before + public void setUp() { + bukkitSystem = COMPONENT.system(); } @After @@ -44,11 +50,9 @@ public class BukkitSystemTest { } @Test - @Ignore public void testEnable() throws EnableException { -// Settings.WEBSERVER_PORT.setTemporaryValue(9005); - - bukkitSystem = null; //TODO + PlanConfig config = bukkitSystem.getConfigSystem().getConfig(); + config.set(Settings.WEBSERVER_PORT, 9005); bukkitSystem.enable(); } } diff --git a/Plan/src/test/java/com/djrapitops/plan/system/BungeeBukkitConnectionTest.java b/Plan/src/test/java/com/djrapitops/plan/BungeeBukkitConnectionTest.java similarity index 96% rename from Plan/src/test/java/com/djrapitops/plan/system/BungeeBukkitConnectionTest.java rename to Plan/src/test/java/com/djrapitops/plan/BungeeBukkitConnectionTest.java index 68987c8bd..9e36f395f 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/BungeeBukkitConnectionTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/BungeeBukkitConnectionTest.java @@ -2,11 +2,10 @@ * License is provided in the jar as LICENSE also here: * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE */ -package com.djrapitops.plan.system; +package com.djrapitops.plan; -import com.djrapitops.plan.Plan; -import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.system.PlanSystem; import org.junit.*; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; diff --git a/Plan/src/test/java/com/djrapitops/plan/system/BungeeSystemTest.java b/Plan/src/test/java/com/djrapitops/plan/BungeeSystemTest.java similarity index 97% rename from Plan/src/test/java/com/djrapitops/plan/system/BungeeSystemTest.java rename to Plan/src/test/java/com/djrapitops/plan/BungeeSystemTest.java index 7ef72a105..dd62f5fba 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/BungeeSystemTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/BungeeSystemTest.java @@ -2,10 +2,10 @@ * License is provided in the jar as LICENSE also here: * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE */ -package com.djrapitops.plan.system; +package com.djrapitops.plan; -import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.system.PlanSystem; import org.junit.*; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; diff --git a/Plan/src/test/java/com/djrapitops/plan/system/SpongeSystemTest.java b/Plan/src/test/java/com/djrapitops/plan/SpongeSystemTest.java similarity index 94% rename from Plan/src/test/java/com/djrapitops/plan/system/SpongeSystemTest.java rename to Plan/src/test/java/com/djrapitops/plan/SpongeSystemTest.java index f6db2fead..c7c1d48ff 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/SpongeSystemTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/SpongeSystemTest.java @@ -2,10 +2,10 @@ * License is provided in the jar as LICENSE also here: * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE */ -package com.djrapitops.plan.system; +package com.djrapitops.plan; -import com.djrapitops.plan.PlanSponge; import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.system.PlanSystem; import org.junit.*; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; diff --git a/Plan/src/test/java/com/djrapitops/plan/system/webserver/HTTPSWebServerAuthTest.java b/Plan/src/test/java/com/djrapitops/plan/system/webserver/HTTPSWebServerAuthTest.java index 2de7656af..59dd7d0af 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/webserver/HTTPSWebServerAuthTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/webserver/HTTPSWebServerAuthTest.java @@ -49,7 +49,7 @@ public class HTTPSWebServerAuthTest { bukkitSystem = null; //TODO // bukkitSystem.enable(); // -// bukkitSystem.getDatabaseSystem().getActiveDatabase().save() +// bukkitSystem.getDatabaseSystem().getDatabase().save() // .webUser(new WebUser("test", PassEncryptUtil.createHash("testPass"), 0)); } diff --git a/Plan/src/test/java/utilities/mocks/PlanBukkitMocker.java b/Plan/src/test/java/utilities/mocks/PlanBukkitMocker.java index d12af6b9d..3fee8477e 100644 --- a/Plan/src/test/java/utilities/mocks/PlanBukkitMocker.java +++ b/Plan/src/test/java/utilities/mocks/PlanBukkitMocker.java @@ -5,8 +5,15 @@ package utilities.mocks; import com.djrapitops.plan.Plan; +import com.djrapitops.plugin.benchmarking.Timings; +import com.djrapitops.plugin.command.ColorScheme; +import com.djrapitops.plugin.logging.console.PluginLogger; import com.djrapitops.plugin.logging.console.TestPluginLogger; +import com.djrapitops.plugin.logging.debug.CombineDebugLogger; +import com.djrapitops.plugin.logging.debug.DebugLogger; +import com.djrapitops.plugin.logging.debug.MemoryDebugLogger; import com.djrapitops.plugin.logging.error.ConsoleErrorLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.task.thread.ThreadRunnableFactory; import org.bukkit.Server; import org.bukkit.command.ConsoleCommandSender; @@ -21,7 +28,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doReturn; /** @@ -44,11 +50,22 @@ public class PlanBukkitMocker extends Mocker { planMock = Mockito.mock(Plan.class); super.planMock = planMock; - doCallRealMethod().when(planMock).getVersion(); - doCallRealMethod().when(planMock).getColorScheme(); + doReturn(new ColorScheme("§1", "§2", "§3")).when(planMock).getColorScheme(); + doReturn("1.0.0").when(planMock).getVersion(); + TestLogger testLogger = new TestLogger(); ThreadRunnableFactory runnableFactory = new ThreadRunnableFactory(); + PluginLogger testPluginLogger = new TestPluginLogger(); + DebugLogger debugLogger = new CombineDebugLogger(new MemoryDebugLogger()); + ErrorHandler consoleErrorLogger = new ConsoleErrorLogger(testPluginLogger); + Timings timings = new Timings(debugLogger); + + doReturn(testLogger).when(planMock).getLogger(); doReturn(runnableFactory).when(planMock).getRunnableFactory(); + doReturn(testPluginLogger).when(planMock).getPluginLogger(); + doReturn(debugLogger).when(planMock).getDebugLogger(); + doReturn(consoleErrorLogger).when(planMock).getErrorHandler(); + doReturn(timings).when(planMock).getTimings(); return this; } @@ -58,13 +75,8 @@ public class PlanBukkitMocker extends Mocker { return this; } + @Deprecated public PlanBukkitMocker withLogging() { - TestLogger testLogger = new TestLogger(); - doReturn(testLogger).when(planMock).getLogger(); - TestPluginLogger testPluginLogger = new TestPluginLogger(); - doReturn(testPluginLogger).when(planMock).getPluginLogger(); - ConsoleErrorLogger consoleErrorLogger = new ConsoleErrorLogger(testPluginLogger); - doReturn(consoleErrorLogger).when(planMock).getErrorHandler(); return this; } diff --git a/Plan/src/test/java/module/TestAPFModule.java b/Plan/src/test/java/utilities/module/TestAPFModule.java similarity index 98% rename from Plan/src/test/java/module/TestAPFModule.java rename to Plan/src/test/java/utilities/module/TestAPFModule.java index 21be460fd..3e39ee303 100644 --- a/Plan/src/test/java/module/TestAPFModule.java +++ b/Plan/src/test/java/utilities/module/TestAPFModule.java @@ -1,4 +1,4 @@ -package module; +package utilities.module; import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plugin.IPlugin;