Search in sources :

Example 1 with StorageProvider

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));
        }
    }
}
Also used : Locale(java.util.Locale) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) StorageProvider(com.archyx.aureliumskills.data.storage.StorageProvider) NBTFile(de.tr7zw.changeme.nbtapi.NBTFile) File(java.io.File) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Aggregations

PlayerData (com.archyx.aureliumskills.data.PlayerData)1 StorageProvider (com.archyx.aureliumskills.data.storage.StorageProvider)1 NBTFile (de.tr7zw.changeme.nbtapi.NBTFile)1 File (java.io.File)1 Locale (java.util.Locale)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Player (org.bukkit.entity.Player)1