Added a fail message to commands if database is not open

This commit is contained in:
Rsl1122 2019-02-22 10:17:27 +02:00
parent 8caa8350ca
commit ac7093237e
15 changed files with 97 additions and 0 deletions

View File

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

View File

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

View File

@ -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<Server> serverFormatter = serverLister(sCol, tCol);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Server> serverOptional = getServer(args);

View File

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

View File

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

View File

@ -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<WebUser> users = dbSystem.getDatabase().query(WebUserQueries.fetchAllPlanWebUsers());

View File

@ -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!"),