Lang implemented for DatabaseCommands

This commit is contained in:
Risto Lahtela 2020-09-01 09:52:33 +03:00
parent 53705616b8
commit 9b068f14a8
2 changed files with 53 additions and 33 deletions

View File

@ -29,6 +29,7 @@ import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.DatabaseSettings;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.lang.CommandLang;
import com.djrapitops.plan.settings.locale.lang.HelpLang;
import com.djrapitops.plan.settings.locale.lang.ManageLang;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.DBType;
@ -124,7 +125,7 @@ public class DatabaseCommands {
try {
String timeStamp = timestamp.apply(System.currentTimeMillis());
String fileName = dbName + "-backup-" + timeStamp;
sender.send("Creating a backup file '" + fileName + ".db' with contents of " + dbName);
sender.send(locale.getString(CommandLang.DB_BACKUP_CREATE, fileName, dbName));
toDB = sqliteFactory.usingFileCalled(fileName);
toDB.init();
toDB.executeTransaction(new BackupCopyTransaction(fromDB, toDB)).get();
@ -142,7 +143,7 @@ public class DatabaseCommands {
public void onRestore(String mainCommand, CMDSender sender, Arguments arguments) {
String backupDbName = arguments.get(0)
.orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 1, "<backup-file>")));
.orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 1, "<" + locale.getString(HelpLang.ARG_BACKUP_FILE) + ">")));
boolean containsDBFileExtension = backupDbName.endsWith(".db");
File backupDBFile = files.getFileFromPluginFolder(backupDbName + (containsDBFileExtension ? "" : ".db"));
@ -169,15 +170,16 @@ public class DatabaseCommands {
if (sender.supportsChatEvents()) {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to overwrite data in Plan " + toDB.getType().getName() + " with data in " + backupDBFile.toPath()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover("Accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_OVERWRITE_DB, toDB.getType().getName(), backupDBFile.toPath().toString())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM))
.addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover(locale.getString(CommandLang.CONFIRM_ACCEPT))
.addPart(" ")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover("Cancel")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover(locale.getString(CommandLang.CONFIRM_DENY))
.send();
} else {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to overwrite data in Plan " + toDB.getType().getName() + " with data in " + backupDBFile.toPath()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§a/" + mainCommand + " accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_OVERWRITE_DB, toDB.getType().getName(), backupDBFile.toPath().toString())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§a/" + mainCommand + " accept")
.addPart(" ")
.addPart("§c/" + mainCommand + " cancel")
.send();
@ -187,7 +189,7 @@ public class DatabaseCommands {
if (choice) {
performRestore(sender, backupDBFile, toDB);
} else {
sender.send(colors.getMainColor() + "Cancelled. No data was changed.");
sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED));
}
});
}
@ -197,7 +199,7 @@ public class DatabaseCommands {
SQLiteDB fromDB = sqliteFactory.usingFile(backupDBFile);
fromDB.init();
sender.send("Writing to " + toDB.getType().getName() + "..");
sender.send(locale.getString(CommandLang.DB_WRITE, toDB.getType().getName()));
toDB.executeTransaction(new BackupCopyTransaction(fromDB, toDB)).get();
sender.send(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (InterruptedException e) {
@ -221,15 +223,16 @@ public class DatabaseCommands {
if (sender.supportsChatEvents()) {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to overwrite data in Plan " + toDB.getName() + " with data in " + fromDB.getName()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover("Accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_OVERWRITE_DB, toDB.getName(), fromDB.getName())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM))
.addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover(locale.getString(CommandLang.CONFIRM_ACCEPT))
.addPart(" ")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover("Cancel")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover(locale.getString(CommandLang.CONFIRM_DENY))
.send();
} else {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to overwrite data in Plan " + toDB.getName() + " with data in " + fromDB.getName()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§a/" + mainCommand + " accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_OVERWRITE_DB, toDB.getName(), fromDB.getName())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§a/" + mainCommand + " accept")
.addPart(" ")
.addPart("§c/" + mainCommand + " cancel")
.send();
@ -239,7 +242,7 @@ public class DatabaseCommands {
if (choice) {
performMove(sender, fromDB, toDB);
} else {
sender.send(colors.getMainColor() + "Cancelled. No data was changed.");
sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED));
}
});
}
@ -251,7 +254,7 @@ public class DatabaseCommands {
fromDatabase.init();
toDatabase.init();
sender.send("Writing to " + toDB.getName() + "..");
sender.send(locale.getString(CommandLang.DB_WRITE, toDB.getName()));
fromDatabase.executeTransaction(new BackupCopyTransaction(fromDatabase, toDatabase)).get();
@ -276,15 +279,16 @@ public class DatabaseCommands {
if (sender.supportsChatEvents()) {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to remove all Plan-data in " + fromDB.getName()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover("Accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CLEAR_DB, fromDB.getName())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM))
.addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover(locale.getString(CommandLang.CONFIRM_ACCEPT))
.addPart(" ")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover("Cancel")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover(locale.getString(CommandLang.CONFIRM_DENY))
.send();
} else {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to remove all Plan-data in " + fromDB.getName()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§a/" + mainCommand + " accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CLEAR_DB, fromDB.getName())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§a/" + mainCommand + " accept")
.addPart(" ")
.addPart("§c/" + mainCommand + " cancel")
.send();
@ -294,7 +298,7 @@ public class DatabaseCommands {
if (choice) {
performClear(sender, fromDB);
} else {
sender.send(colors.getMainColor() + "Cancelled. No data was changed.");
sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED));
}
});
}
@ -304,7 +308,7 @@ public class DatabaseCommands {
Database fromDatabase = dbSystem.getActiveDatabaseByType(fromDB);
fromDatabase.init();
sender.send("Removing Plan-data from " + fromDB.getName() + "..");
sender.send(locale.getString(CommandLang.DB_REMOVAL, fromDB.getName()));
fromDatabase.executeTransaction(new RemoveEverythingTransaction())
.get(); // Wait for completion
@ -326,22 +330,23 @@ public class DatabaseCommands {
String identifier = arguments.concatenate(" ");
UUID playerUUID = identifiers.getPlayerUUID(identifier);
if (playerUUID == null) {
throw new IllegalArgumentException("Player '" + identifier + "' was not found, they have no UUID.");
throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_PLAYER_NOT_FOUND, identifier));
}
Database database = dbSystem.getDatabase();
if (sender.supportsChatEvents()) {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to remove data of " + playerUUID + " from " + database.getType().getName()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover("Accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_REMOVE_PLAYER_DB, playerUUID, database.getType().getName())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM))
.addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover(locale.getString(CommandLang.CONFIRM_ACCEPT))
.addPart(" ")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover("Cancel")
.addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover(locale.getString(CommandLang.CONFIRM_DENY))
.send();
} else {
sender.buildMessage()
.addPart(colors.getMainColor() + "You are about to remove data of " + playerUUID + " from " + database.getType().getName()).newLine()
.addPart(colors.getTertiaryColor() + "Confirm: ").addPart("§a/" + mainCommand + " accept")
.addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_REMOVE_PLAYER_DB, playerUUID, database.getType().getName())).newLine()
.addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§a/" + mainCommand + " accept")
.addPart(" ")
.addPart("§c/" + mainCommand + " cancel")
.send();
@ -351,14 +356,14 @@ public class DatabaseCommands {
if (choice) {
performRemoval(sender, database, playerUUID);
} else {
sender.send(colors.getMainColor() + "Cancelled. No data was changed.");
sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED));
}
});
}
private void performRemoval(CMDSender sender, Database database, UUID playerToRemove) {
try {
sender.send("Removing data of " + playerToRemove + " from " + database.getType().getName() + "..");
sender.send(locale.getString(CommandLang.DB_REMOVAL_PLAYER, playerToRemove, database.getType().getName()));
queryService.playerRemoved(playerToRemove);
database.executeTransaction(new RemovePlayerTransaction(playerToRemove))
@ -386,7 +391,7 @@ public class DatabaseCommands {
Server server = dbSystem.getDatabase()
.query(ServerQueries.fetchServerMatchingIdentifier(identifier))
.filter(s -> !s.isProxy())
.orElseThrow(() -> new IllegalArgumentException("Server '" + identifier + "' was not found from the database."));
.orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_SERVER_NOT_FOUND, identifier)));
if (server.getUuid().equals(serverInfo.getServerUUID())) {
throw new IllegalArgumentException(locale.getString(ManageLang.UNINSTALLING_SAME_SERVER));
@ -394,7 +399,7 @@ public class DatabaseCommands {
dbSystem.getDatabase().executeTransaction(new SetServerAsUninstalledTransaction(server.getUuid()));
sender.send(locale.getString(ManageLang.PROGRESS_SUCCESS));
sender.send("§aIf the server is still installed, it will automatically set itself as installed in the database.");
sender.send(locale.getString(CommandLang.DB_UNINSTALLED));
}
public void onHotswap(CMDSender sender, Arguments arguments) {

View File

@ -25,7 +25,16 @@ public enum CommandLang implements Lang {
CONFIRM_EXPIRED("Cmd Confirm - Expired", "Confirmation expired, use the command again"),
CONFIRM_FAIL_ACCEPT("Cmd Confirm - Fail on accept", "The accepted action errored upon execution: ${0}"),
CONFIRM_FAIL_DENY("Cmd Confirm - Fail on deny", "The denied action errored upon execution: ${0}"),
CONFIRM("Cmd Confirm - confirmation", "Confirm: "),
CONFIRM_ACCEPT("Cmd Confirm - accept", "Accept"),
CONFIRM_DENY("Cmd Confirm - deny", "Cancel"),
CONFIRM_OVERWRITE_DB("Cmd Confirm - overwriting db", "You are about to overwrite data in Plan ${0} with data in ${1}"),
CONFIRM_CLEAR_DB("Cmd Confirm - clearing db", "You are about to remove all Plan-data in ${0}"),
CONFIRM_REMOVE_PLAYER_DB("Cmd Confirm - remove player db", "You are about to remove data of ${0} from ${1}"),
CONFIRM_CANCELLED("Cmd Confirm - cancelled, no data change", "Cancelled. No data was changed."),
FAIL_PLAYER_NOT_FOUND("Cmd FAIL - No player", "Player '${0}' was not found, they have no UUID."),
FAIL_SERVER_NOT_FOUND("Cmd FAIL - No server", "Server '${0}' was not found from the database."),
FAIL_REQ_ARGS("Cmd FAIL - Requires Arguments", "§cArguments required (${0}) ${1}"),
FAIL_REQ_ONE_ARG("Cmd FAIL - Require only one Argument", "§cSingle Argument required ${1}"),
FAIL_NO_PERMISSION("Cmd FAIL - No Permission", "§cYou do not have the required permission."),
@ -77,6 +86,12 @@ public enum CommandLang implements Lang {
QINSPECT_MOB_KILLS("Cmd Qinspect - Mob Kills", " §2Mob Kills: §f${0}"),
QINSPECT_DEATHS("Cmd Qinspect - Deaths", " §2Deaths: §f${0}"),
DB_BACKUP_CREATE("Cmd db - creating backup", "Creating a backup file '${0}.db' with contents of ${1}"),
DB_WRITE("Cmd db - write", "Writing to ${0}.."),
DB_REMOVAL("Cmd db - removal", "Removing Plan-data from ${0}.."),
DB_REMOVAL_PLAYER("Cmd db - removal player", "Removing data of ${0} from ${1}.."),
DB_UNINSTALLED("Cmd db - server uninstalled", "§aIf the server is still installed, it will automatically set itself as installed in the database."),
DISABLE_DISABLED("Cmd Disable - Disabled", "§aPlan systems are now disabled. You can still use /planbungee reload to restart the plugin."),
RELOAD_COMPLETE("Cmd Info - Reload Complete", "§aReload Complete"),