Search in sources :

Example 1 with DBType

use of com.djrapitops.plan.storage.database.DBType in project Plan by plan-player-analytics.

the class DatabaseCommands method onHotswap.

public void onHotswap(CMDSender sender, Arguments arguments) {
    DBType toDB = arguments.get(0).flatMap(DBType::getForName).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_INCORRECT_DB, arguments.get(0).orElse("<MySQL/SQLite>"))));
    try {
        Database database = dbSystem.getActiveDatabaseByType(toDB);
        database.init();
        if (database.getState() == Database.State.CLOSED) {
            return;
        }
        config.set(DatabaseSettings.TYPE, toDB.getName());
        config.save();
    } catch (DBOpException | IOException e) {
        errorLogger.warn(e, ErrorContext.builder().related(toDB).build());
        sender.send(locale.getString(CommandLang.PROGRESS_FAIL, e.getMessage()));
        return;
    }
    statusCommands.onReload(sender);
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) Database(com.djrapitops.plan.storage.database.Database) DBType(com.djrapitops.plan.storage.database.DBType) IOException(java.io.IOException)

Example 2 with DBType

use of com.djrapitops.plan.storage.database.DBType in project Plan by plan-player-analytics.

the class DatabaseCommands method onMove.

public void onMove(String mainCommand, CMDSender sender, Arguments arguments) {
    DBType fromDB = arguments.get(0).flatMap(DBType::getForName).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_INCORRECT_DB, arguments.get(0).orElse("<MySQL/SQLite>"))));
    DBType toDB = arguments.get(1).flatMap(DBType::getForName).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_INCORRECT_DB, arguments.get(0).orElse("<MySQL/SQLite>"))));
    if (fromDB == toDB) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_SAME_DB));
    }
    if (sender.supportsChatEvents()) {
        sender.buildMessage().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(locale.getString(CommandLang.CONFIRM_DENY)).send();
    } else {
        sender.buildMessage().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();
    }
    confirmation.confirm(sender, choice -> {
        if (Boolean.TRUE.equals(choice)) {
            performMove(sender, fromDB, toDB);
        } else {
            sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED_DATA));
        }
    });
}
Also used : DBType(com.djrapitops.plan.storage.database.DBType)

Example 3 with DBType

use of com.djrapitops.plan.storage.database.DBType in project Plan by plan-player-analytics.

the class DatabaseCommands method onClear.

public void onClear(String mainCommand, CMDSender sender, Arguments arguments) {
    DBType fromDB = arguments.get(0).flatMap(DBType::getForName).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_INCORRECT_DB, arguments.get(0).orElse("<MySQL/SQLite>"))));
    if (sender.supportsChatEvents()) {
        sender.buildMessage().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(locale.getString(CommandLang.CONFIRM_DENY)).send();
    } else {
        sender.buildMessage().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();
    }
    confirmation.confirm(sender, choice -> {
        if (Boolean.TRUE.equals(choice)) {
            performClear(sender, fromDB);
        } else {
            sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED_DATA));
        }
    });
}
Also used : DBType(com.djrapitops.plan.storage.database.DBType)

Aggregations

DBType (com.djrapitops.plan.storage.database.DBType)3 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)1 Database (com.djrapitops.plan.storage.database.Database)1 IOException (java.io.IOException)1