use of com.archyx.aureliumskills.data.storage.StorageProvider in project AureliumSkills by Archy-X.
the class SkillsCommand method onBackupLoad.
@Subcommand("backup load")
@CommandPermission("aureliumskills.backup.load")
public void onBackupLoad(CommandSender sender, String fileName) {
StorageProvider storageProvider = plugin.getStorageProvider();
Locale locale = plugin.getLang().getLocale(sender);
if (storageProvider != null) {
File file = new File(plugin.getDataFolder() + "/backups/" + fileName);
if (file.exists()) {
if (file.getName().endsWith(".yml")) {
// Require player to double type command
if (sender instanceof Player) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData((Player) sender);
if (playerData == null)
return;
Object typed = playerData.getMetadata().get("backup_command");
if (typed != null) {
if (typed instanceof String) {
String typedFile = (String) typed;
if (typedFile.equals(file.getName())) {
sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_LOADING, locale));
storageProvider.loadBackup(YamlConfiguration.loadConfiguration(file), sender);
playerData.getMetadata().remove("backup_command");
} else {
backupLoadConfirm(playerData, sender, file);
}
} else {
backupLoadConfirm(playerData, sender, file);
}
} else {
backupLoadConfirm(playerData, sender, file);
}
} else {
sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_LOADING, locale));
storageProvider.loadBackup(YamlConfiguration.loadConfiguration(file), sender);
}
} else {
sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_MUST_BE_YAML, locale));
}
} else {
// If file does not exist
sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_FILE_NOT_FOUND, locale));
}
}
}
Aggregations