From ac7093237e52a1292d264734da17de736e227010 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 22 Feb 2019 10:17:27 +0200 Subject: [PATCH] Added a fail message to commands if database is not open --- .../plan/command/commands/AnalyzeCommand.java | 7 +++++++ .../plan/command/commands/InspectCommand.java | 7 +++++++ .../plan/command/commands/ListServersCommand.java | 7 +++++++ .../plan/command/commands/QInspectCommand.java | 7 +++++++ .../plan/command/commands/RegisterCommand.java | 6 ++++++ .../plan/command/commands/SearchCommand.java | 7 +++++++ .../command/commands/manage/ManageBackupCommand.java | 4 ++++ .../commands/manage/ManageConDebugCommand.java | 7 +++++++ .../command/commands/manage/ManageImportCommand.java | 11 +++++++++++ .../command/commands/manage/ManageRestoreCommand.java | 5 +++++ .../commands/manage/ManageUninstalledCommand.java | 8 ++++++++ .../command/commands/webuser/WebCheckCommand.java | 6 ++++++ .../command/commands/webuser/WebDeleteCommand.java | 6 ++++++ .../command/commands/webuser/WebListUsersCommand.java | 7 +++++++ .../plan/system/locale/lang/CommandLang.java | 2 ++ 15 files changed, 97 insertions(+) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java index e13716cdb..37b67efaf 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java @@ -18,6 +18,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.db.Database; import com.djrapitops.plan.db.access.queries.objects.ServerQueries; import com.djrapitops.plan.db.access.queries.objects.WebUserQueries; import com.djrapitops.plan.system.database.DBSystem; @@ -90,6 +91,12 @@ public class AnalyzeCommand extends CommandNode { @Override public void onCommand(Sender sender, String commandLabel, String[] args) { + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); processing.submitNonCritical(() -> { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java index 366c2d02d..c6e356c4c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.access.queries.PlayerFetchQueries; import com.djrapitops.plan.db.access.queries.objects.WebUserQueries; import com.djrapitops.plan.system.database.DBSystem; @@ -92,6 +93,12 @@ public class InspectCommand extends CommandNode { sender.sendMessage(locale.getString(CommandLang.FAIL_NO_PERMISSION)); } + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + runInspectTask(playerName, sender); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java index 25f4df850..ab4867e7c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.access.queries.objects.ServerQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.Server; @@ -70,6 +71,12 @@ public class ListServersCommand extends CommandNode { @Override public void onCommand(Sender sender, String commandLabel, String[] args) { + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + String sCol = colorScheme.getSecondaryColor(); String tCol = colorScheme.getTertiaryColor(); Formatter serverFormatter = serverLister(sCol, tCol); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java index 1544d7308..1e8786ae2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java @@ -24,6 +24,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.db.Database; import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; @@ -102,6 +103,12 @@ public class QInspectCommand extends CommandNode { return; } + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + runInspectTask(playerName, sender); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java index 53b64dc31..21fd98d37 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java @@ -88,6 +88,12 @@ public class RegisterCommand extends CommandNode { @Override public void onCommand(Sender sender, String commandLabel, String[] args) { try { + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + if (CommandUtils.isPlayer(sender)) { playerRegister(args, sender); } else { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java index 24d08d4fc..63e977156 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.command.commands; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.access.queries.objects.UserIdentifierQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; @@ -72,6 +73,12 @@ public class SearchCommand extends CommandNode { @Override public void onCommand(Sender sender, String commandLabel, String[] args) { + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments())))); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java index eb370a640..68b86db3f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java @@ -110,6 +110,10 @@ public class ManageBackupCommand extends CommandNode { private void runBackupTask(Sender sender, String[] args, Database database) { processing.submitCritical(() -> { try { + Database.State dbState = database.getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.WARN_DATABASE_NOT_OPEN, dbState.name())); + } sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); createNewBackup(args[0], database); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java index 5f7d1bc04..4a9e4449d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.command.commands.manage; import com.djrapitops.plan.api.exceptions.connection.*; +import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.access.queries.objects.ServerQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem; @@ -123,6 +124,12 @@ public class ManageConDebugCommand extends CommandNode { return; } + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + processing.submitNonCritical(() -> testServers(sender)); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java index 73dbb7131..608baae6a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java @@ -16,6 +16,8 @@ */ package com.djrapitops.plan.command.commands.manage; +import com.djrapitops.plan.db.Database; +import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.importing.ImportSystem; import com.djrapitops.plan.system.importing.importers.Importer; import com.djrapitops.plan.system.locale.Locale; @@ -44,18 +46,21 @@ import java.util.Optional; public class ManageImportCommand extends CommandNode { private final Locale locale; + private final DBSystem dbSystem; private final Processing processing; private final ImportSystem importSystem; @Inject public ManageImportCommand( Locale locale, + DBSystem dbSystem, Processing processing, ImportSystem importSystem ) { super("import", Permissions.MANAGE.getPermission(), CommandType.CONSOLE); this.locale = locale; + this.dbSystem = dbSystem; this.processing = processing; this.importSystem = importSystem; @@ -77,6 +82,12 @@ public class ManageImportCommand extends CommandNode { return; } + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + findAndProcessImporter(sender, importArg); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java index a40b3ae30..c23b7f581 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java @@ -122,6 +122,11 @@ public class ManageRestoreCommand extends CommandNode { SQLiteDB backupDB = sqliteFactory.usingFile(backupDBFile); backupDB.init(); + Database.State dbState = database.getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.WARN_DATABASE_NOT_OPEN, dbState.name())); + } + sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); database.executeTransaction(new BackupCopyTransaction(backupDB, database)).get(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java index 9a5052299..ce23ecf31 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.command.commands.manage; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.access.queries.objects.ServerQueries; import com.djrapitops.plan.db.access.transactions.commands.SetServerAsUninstalledTransaction; import com.djrapitops.plan.system.database.DBSystem; @@ -24,6 +25,7 @@ import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; +import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.processing.Processing; @@ -78,6 +80,12 @@ public class ManageUninstalledCommand extends CommandNode { public void onCommand(Sender sender, String commandLabel, String[] args) { sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + processing.submitNonCritical(() -> { try { Optional serverOptional = getServer(args); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java index e0b976d8f..87a0f5e76 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java @@ -71,6 +71,12 @@ public class WebCheckCommand extends CommandNode { @Override public void onCommand(Sender sender, String commandLabel, String[] args) { + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments())))); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java index c402876de..bd3bba1e0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java @@ -72,6 +72,12 @@ public class WebDeleteCommand extends CommandNode { @Override public void onCommand(Sender sender, String commandLabel, String[] args) { + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments())))); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java index 0bb620a26..861a5fb5c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.command.commands.webuser; import com.djrapitops.plan.data.WebUser; +import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.access.queries.objects.WebUserQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; @@ -67,6 +68,12 @@ public class WebListUsersCommand extends CommandNode { @Override public void onCommand(Sender sender, String commandLabel, String[] args) { + Database.State dbState = dbSystem.getDatabase().getState(); + if (dbState != Database.State.OPEN) { + sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); + return; + } + processing.submitNonCritical(() -> { try { List users = dbSystem.getDatabase().query(WebUserQueries.fetchAllPlanWebUsers()); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/locale/lang/CommandLang.java b/Plan/common/src/main/java/com/djrapitops/plan/system/locale/lang/CommandLang.java index 29696d408..ff5a00475 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/locale/lang/CommandLang.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/locale/lang/CommandLang.java @@ -27,6 +27,8 @@ public enum CommandLang implements Lang { FAIL_NO_PERMISSION("Cmd FAIL - No Permission", "§cYou do not have the required permission."), FAIL_USERNAME_NOT_VALID("Cmd FAIL - Invalid Username", "§cUser does not have an UUID."), FAIL_USERNAME_NOT_KNOWN("Cmd FAIL - Unknown Username", "§cUser has not been seen on this server"), + FAIL_DATABASE_NOT_OPEN("Cmd FAIL - Database not open", "§cDatabase is ${0} - Please try again a bit later."), + WARN_DATABASE_NOT_OPEN("Cmd WARN - Database not open", "§eDatabase is ${0} - This might take longer than expected.."), FAIL_WEB_USER_EXISTS("Cmd FAIL - WebUser exists", "§cUser already exists!"), FAIL_WEB_USER_NOT_EXISTS("Cmd FAIL - WebUser does not exists", "§cUser does not exists!"),