Java Code Examples for org.bukkit.configuration.file.FileConfiguration#getConfigurationSection()

The following examples show how to use org.bukkit.configuration.file.FileConfiguration#getConfigurationSection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LevelConfigYmlReader.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public BlockLevelConfigMap readLevelConfig(FileConfiguration config) {
    double defaultScore = config.getDouble("general.default", 10d);
    int defaultLimit = config.getInt("general.limit", Integer.MAX_VALUE);
    int defaultDiminishingReturns = config.getInt("general.diminishingReturns", 0);
    BlockLevelConfigBuilder defaultBuilder = new BlockLevelConfigBuilder()
            .scorePerBlock(defaultScore)
            .limit(defaultLimit)
            .diminishingReturns(defaultDiminishingReturns);
    List<BlockLevelConfig> blocks = new ArrayList<>();
    addDefaults(blocks, defaultBuilder);
    ConfigurationSection section = config.getConfigurationSection("blocks");
    if (section != null) {
        for (String key : section.getKeys(false)) {
            if (section.isConfigurationSection(key)) {
                BlockLevelConfig blockConfig = readBlockSection(section.getConfigurationSection(key), getBlockMatch(key), defaultBuilder);
                blocks.add(blockConfig);
            }
        }
    }
    return new BlockLevelConfigMap(blocks, defaultBuilder);
}
 
Example 2
Source File: Sounds.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
public static void init(String file) {
	try {
		BufferedReader reader = new BufferedReader(new InputStreamReader(Sounds.class.getResourceAsStream(file)));
		FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(reader);
		if(fileConfiguration.isConfigurationSection("STEP")) {
			stepSounds = new Sounds(fileConfiguration.getConfigurationSection("STEP"));
		}
		for(DisguiseType type : DisguiseType.values()) {
			if(fileConfiguration.isConfigurationSection(type.name())) {
				setSoundsForEntity(type, new Sounds(fileConfiguration.getConfigurationSection(type.name())));
			}
		}
		reader.close();
	} catch(IOException e) {
		iDisguise.getInstance().getLogger().log(Level.SEVERE, "Cannot load the required sound effect configuration.", e);
	}
}
 
Example 3
Source File: Rewards.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
private void setupRewards() {
    this.rewardList.clear();
    FileConfiguration config = getConfig("rewards.yml");
    if(!config.isConfigurationSection("rewards")) return;

    ConfigurationSection sectionRewards = config.getConfigurationSection("rewards");
    if(sectionRewards == null) return;

    Set<String> rewardSet = sectionRewards.getKeys(false);
    for(String rewardId : rewardSet) {
        ConfigurationSection rewardInfo = sectionRewards.getConfigurationSection(rewardId);
        if(rewardInfo == null) continue;

        Reward reward = setupReward(rewardId, rewardInfo);
        if(reward != null) this.rewardList.add(reward);
    }
}
 
Example 4
Source File: Util.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<Bounty> readBountyList(FileConfiguration config) {
    ArrayList<Bounty> bountyList = new ArrayList<>();
    ConfigurationSection section1 = config.getConfigurationSection("bounties");
    for (String key : section1.getKeys(false)) {
        Bounty bounty;
        if (section1.isSet(key + ".issuer")) {
            bounty = new Bounty(UUID.fromString(section1.getString(key + ".issuer")),
                    section1.getDouble(key + ".amount"));
        } else {
            bounty = new Bounty(null,
                    section1.getDouble(key + ".amount"));
        }
        bountyList.add(bounty);
    }
    return bountyList;
}
 
Example 5
Source File: ConfigurationHandler.java    From MineableSpawners with MIT License 6 votes vote down vote up
private void setSection(FileConfiguration config) {
    Map<String, String> msgs = new HashMap<>();
    Map<String, Boolean> bools = new HashMap<>();
    Map<String, List<String>> lsts = new HashMap<>();

    ConfigurationSection section = config.getConfigurationSection("set");

    msgs.put("no-permission", section.getString("messages.no-permission"));
    msgs.put("no-individual-permission", section.getString("messages.no-individual-permission"));
    msgs.put("invalid-type", section.getString("messages.invalid-type"));
    msgs.put("not-looking-at", section.getString("messages.not-looking-at"));
    msgs.put("already-type", section.getString("messages.already-type"));
    msgs.put("success", section.getString("messages.success"));
    msgs.put("blacklisted", section.getString("messages.blacklisted"));

    bools.put("require-permission", section.getBoolean("require-permission"));
    bools.put("require-individual-permission", section.getBoolean("require-individual-permission"));

    lsts.put("blacklisted-worlds", section.getStringList("blacklisted-worlds"));

    messages.put("set", msgs);
    booleans.put("set", bools);
    lists.put("set", lsts);
}
 
Example 6
Source File: ConfigurationHandler.java    From MineableSpawners with MIT License 6 votes vote down vote up
private void giveSection(FileConfiguration config) {
    Map<String, String> msgs = new HashMap<>();
    Map<String, Boolean> bools = new HashMap<>();

    ConfigurationSection section = config.getConfigurationSection("give");

    msgs.put("no-permission", section.getString("messages.no-permission"));
    msgs.put("player-does-not-exist", section.getString("messages.player-does-not-exist"));
    msgs.put("invalid-type", section.getString("messages.invalid-type"));
    msgs.put("invalid-amount", section.getString("messages.invalid-amount"));
    msgs.put("inventory-full", section.getString("messages.inventory-full"));
    msgs.put("success", section.getString("messages.success"));
    msgs.put("received", section.getString("messages.received"));

    bools.put("require-permission", section.getBoolean("require-permission"));

    messages.put("give", msgs);
    booleans.put("give", bools);
}
 
Example 7
Source File: ConfigurationHandler.java    From MineableSpawners with MIT License 6 votes vote down vote up
private void globalSection(FileConfiguration config) {
    Map<String, String> msgs = new HashMap<>();
    Map<String, Boolean> bools = new HashMap<>();
    Map<String, List<String>> lsts = new HashMap<>();

    ConfigurationSection section = config.getConfigurationSection("global");

    msgs.put("name", section.getString("display.name"));

    lsts.put("lore", section.getStringList("display.lore"));

    bools.put("lore-enabled", section.getBoolean("display.lore-enabled"));

    messages.put("global", msgs);
    lists.put("global", lsts);
    booleans.put("global", bools);
}
 
Example 8
Source File: ConfigurationHandler.java    From MineableSpawners with MIT License 6 votes vote down vote up
private void explodeSection(FileConfiguration config) {
    Map<String, String> msgs = new HashMap<>();
    Map<String, Boolean> bools = new HashMap<>();
    Map<String, Double> dbls = new HashMap<>();
    Map<String, List<String>> lsts = new HashMap<>();

    ConfigurationSection section = config.getConfigurationSection("explode");

    bools.put("drop", section.getBoolean("drop"));

    dbls.put("chance", section.getDouble("chance"));

    lsts.put("blacklisted-worlds", section.getStringList("blacklisted-worlds"));

    messages.put("explode", msgs);
    booleans.put("explode", bools);
    doubles.put("explode", dbls);
    lists.put("explode", lsts);
}
 
Example 9
Source File: DatabaseConfiguration.java    From ScoreboardStats with MIT License 6 votes vote down vote up
/**
 * Loads the configuration
 */
public void loadConfiguration() {
    serverConfig = new HikariConfig();

    Path file = plugin.getDataFolder().toPath().resolve("sql.yml");
    //Check if the file exists. If so load the settings form there
    if (Files.notExists(file)) {
        //Create a new configuration based on the default settings form bukkit.yml
        plugin.saveResource("sql.yml", false);
    }

    FileConfiguration sqlConfig = YamlConfiguration.loadConfiguration(file.toFile());

    ConfigurationSection sqlSettingSection = sqlConfig.getConfigurationSection("SQL-Settings");
    serverConfig.setUsername(sqlSettingSection.getString("Username"));
    serverConfig.setPassword(sqlSettingSection.getString("Password"));
    serverConfig.setDriverClassName(sqlSettingSection.getString("Driver"));
    serverConfig.setJdbcUrl(replaceUrlString(sqlSettingSection.getString("Url")));
    if (serverConfig.getDriverClassName().contains("sqlite")) {
        serverConfig.setConnectionTestQuery("SELECT 1");
    }

    tablePrefix = sqlSettingSection.getString("tablePrefix", "");
}
 
Example 10
Source File: LevelManager.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private void loadTaunts() {
	tauntList.clear();
       File tauntFile = new File(SkyWarsReloaded.get().getDataFolder(), "taunts.yml");

       if (!tauntFile.exists()) {
       	if (SkyWarsReloaded.getNMS().getVersion() < 9) {
               	SkyWarsReloaded.get().saveResource("taunts18.yml", false);
               	File sf = new File(SkyWarsReloaded.get().getDataFolder(), "taunts18.yml");
               	if (sf.exists()) {
               		sf.renameTo(new File(SkyWarsReloaded.get().getDataFolder(), "taunts.yml"));
               	}
       	} else {
           	SkyWarsReloaded.get().saveResource("taunts.yml", false);
       	}
       }
       
       if (tauntFile.exists()) {
           FileConfiguration storage = YamlConfiguration.loadConfiguration(tauntFile);

           if (storage.getConfigurationSection("taunts") != null) {
           	for (String key: storage.getConfigurationSection("taunts").getKeys(false)) {
               	String name = storage.getString("taunts." + key + ".name");
               	List<String> lore = storage.getStringList("taunts." + key + ".lore");
               	int level = storage.getInt("taunts." + key + ".level");
               	int cost = storage.getInt("taunts." + key + ".cost");
               	String message = storage.getString("taunts." + key + ".message");
               	String sound = storage.getString("taunts." + key + ".sound");
               	boolean useCustomSound = storage.getBoolean("taunts." + key + ".useCustomSound", false);
               	double volume = storage.getDouble("taunts." + key + ".volume");
               	double pitch = storage.getDouble("taunts." + key + ".pitch");
               	double speed = storage.getDouble("taunts." + key + ".particleSpeed");
               	int density = storage.getInt("taunts." + key + ".particleDensity");
               	List<String> particles = storage.getStringList("taunts." + key + ".particles");
               	Material icon = Material.valueOf(storage.getString("taunts." + key + ".icon", "DIAMOND"));
               	tauntList.add(new Taunt(key, name, lore, message, sound, useCustomSound, volume, pitch, speed, density, particles, icon, level, cost));
               }
           } 
       }
       Collections.<Taunt>sort(tauntList);
}
 
Example 11
Source File: ConfigurationHandler.java    From MineableSpawners with MIT License 5 votes vote down vote up
private void mainSection(FileConfiguration config) {
    Map<String, String> msgs = new HashMap<>();

    ConfigurationSection section = config.getConfigurationSection("main");

    msgs.put("title", section.getString("help-message.title"));
    msgs.put("give", section.getString("help-message.give"));
    msgs.put("set", section.getString("help-message.set"));
    msgs.put("types", section.getString("help-message.types"));
    msgs.put("reload", section.getString("help-message.reload"));

    messages.put("main", msgs);
}
 
Example 12
Source File: ItemManager.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public Map<String, Integer> loadCivItems(FileConfiguration civConfig) {
    HashMap<String, Integer> items = new HashMap<>();
    ConfigurationSection configurationSection = civConfig.getConfigurationSection("items");
    if (configurationSection == null) {
        return items;
    }
    for (String key : configurationSection.getKeys(false)) {
        CivItem currentItem = getItemType(key);
        if (currentItem == null) {
            continue;
        }
        items.put(key, civConfig.getInt("items." + key));
    }
    return items;
}
 
Example 13
Source File: MapPool.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static MapPool of(MapPoolManager manager, FileConfiguration config, String key) {
  ConfigurationSection section = config.getConfigurationSection("pools." + key);
  String type = section.getString("type").toLowerCase();
  switch (type) {
    case "ordered":
      return new Rotation(manager, section, key);
    case "voted":
      return new VotingPool(manager, section, key);
    case "shuffled":
      return new RandomMapPool(manager, section, key);
    default:
      PGM.get().getLogger().severe("Invalid map pool type for " + key + ": '" + type + "'");
      return new DisabledMapPool(manager, section, key);
  }
}
 
Example 14
Source File: ChestManager.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void load(Map<Integer, Inventory> itemList, String fileName) {
	itemList.clear();
	File chestFile = new File(SkyWarsReloaded.get().getDataFolder(), fileName);

	if (!chestFile.exists()) {
		SkyWarsReloaded.get().saveResource(fileName, false);
	}

	if (chestFile.exists()) {
		FileConfiguration storage = YamlConfiguration.loadConfiguration(chestFile);

		if (storage.getConfigurationSection("chestItems") != null) {
			for (String key: storage.getConfigurationSection("chestItems").getKeys(false)) {
				if (Util.get().isInteger(key)) {
					int percent = Integer.valueOf(key);
					List<ItemStack> items = (List<ItemStack>) storage.getList("chestItems." + key + ".items");
					if (!itemList.containsKey(percent)) {
						itemList.put(percent, Bukkit.createInventory(null, 54, fileName + " " + percent));
					}
					for (ItemStack iStack: items) {
						itemList.get(percent).addItem(iStack);
					}
				}
			}
		}
	}
}
 
Example 15
Source File: BackpackConverter.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
private int convert(File worldFolder, int intoVaultNum) {
    PlayerVaults plugin = PlayerVaults.getInstance();
    VaultManager vaults = VaultManager.getInstance();
    int converted = 0;
    long lastUpdate = 0;
    File[] files = worldFolder.listFiles();
    for (File file : files != null ? files : new File[0]) {
        if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) {
            try {
                OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().substring(0, file.getName().lastIndexOf('.')));
                if (player == null || player.getUniqueId() == null) {
                    plugin.getLogger().warning("Unable to convert Backpack for player: " + (player != null ? player.getName() : file.getName()));
                } else {
                    UUID uuid = player.getUniqueId();
                    FileConfiguration yaml = YamlConfiguration.loadConfiguration(file);
                    ConfigurationSection section = yaml.getConfigurationSection("backpack");
                    if (section.getKeys(false).size() <= 0) {
                        continue; // No slots
                    }

                    Inventory vault = vaults.getVault(uuid.toString(), intoVaultNum);
                    if (vault == null) {
                        vault = plugin.getServer().createInventory(null, section.getKeys(false).size());
                    }
                    for (String key : section.getKeys(false)) {
                        ConfigurationSection slotSection = section.getConfigurationSection(key);
                        ItemStack item = slotSection.getItemStack("ItemStack");
                        if (item == null) {
                            continue;
                        }

                        // Overwrite
                        vault.setItem(Integer.parseInt(key.split(" ")[1]), item);
                    }
                    vaults.saveVault(vault, uuid.toString(), intoVaultNum);
                    converted++;

                    if (System.currentTimeMillis() - lastUpdate >= 1500) {
                        plugin.getLogger().info(converted + " backpacks have been converted in " + worldFolder.getAbsolutePath());
                        lastUpdate = System.currentTimeMillis();
                    }
                }
            } catch (Exception e) {
                plugin.getLogger().warning("Error converting " + file.getAbsolutePath());
                e.printStackTrace();
            }
        }
    }
    return converted;
}
 
Example 16
Source File: LevelManager.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void loadParticleEffects() {
    particleList.clear();
    File particleFile = new File(SkyWarsReloaded.get().getDataFolder(), "particleeffects.yml");

    if (!particleFile.exists()) {
    	SkyWarsReloaded.get().saveResource("particleeffects.yml", false);
    }

    if (particleFile.exists()) {
        FileConfiguration storage = YamlConfiguration.loadConfiguration(particleFile);

        if (storage.getConfigurationSection("effects") != null) {
        	for (String key: storage.getConfigurationSection("effects").getKeys(false)) {
            	String name = storage.getString("effects." + key + ".displayname");
            	String material = storage.getString("effects." + key + ".icon");
            	int level = storage.getInt("effects." + key + ".level");
            	int cost = storage.getInt("effects." + key + ".cost");
            	List<String> particles = storage.getStringList("effects." + key + ".particles");
            	
            	List<ParticleEffect> effects = new ArrayList<ParticleEffect>();
            	if (particles != null) {
                	for (String part: particles) {
                		final String[] parts = part.split(":");
                        if (parts.length == 6 
                        		&& SkyWarsReloaded.getNMS().isValueParticle(parts[0].toUpperCase()) 
                        		&& Util.get().isFloat(parts[1])
                				&& Util.get().isFloat(parts[2])
                				&& Util.get().isFloat(parts[3])
                        		&& Util.get().isInteger(parts[4]) 
                        		&& Util.get().isInteger(parts[5])) {
                        	effects.add(new ParticleEffect(parts[0].toUpperCase(), Float.valueOf(parts[1]), Float.valueOf(parts[2]), Float.valueOf(parts[3]), Integer.valueOf(parts[4]), Integer.valueOf(parts[5])));
                        } else {
                        	SkyWarsReloaded.get().getLogger().info("The particle effect " + key + " has an invalid particle effect");
                        }
                	}
            	}
            	Material mat = Material.matchMaterial(material);
            	if (mat != null) {
            		particleList.add(new ParticleItem(key, effects, name, mat, level, cost));
                }
        	}
        }
    }
    
    Collections.<ParticleItem>sort(particleList);
}
 
Example 17
Source File: SpellType.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
public SpellType(List<String> reqs,
                 String name,
                 Material material,
                 CVItem shopIcon,
                 int qty,
                 int min,
                 int max,
                 double price,
                 String permission,
                 List<String> groups,
                 FileConfiguration config,
                 boolean isInShop,
                 int level) {
    super(reqs,
            false,
            ItemType.SPELL,
            name,
            material,
            shopIcon,
            qty,
            min,
            max,
            price,
            permission,
            groups,
            isInShop,
            level);
    this.config = config;
    this.components = new HashMap<>();
    ConfigurationSection componentSection = config.getConfigurationSection("components");
    if (componentSection == null) {
        Civs.logger.severe("Failed to load spell type " + name + " no components");
        return;
    }
    for (String key : componentSection.getKeys(false)) {
        ConfigurationSection currentSection = componentSection.getConfigurationSection(key);
        if (currentSection != null) {
            components.put(key, currentSection);
        }
    }
}
 
Example 18
Source File: MigrationPermissionsBukkit.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object ignored, ArgumentList args, String label) {
    ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "PermissionsBukkit");
    log.addListener(plugin.getConsoleSender());
    log.addListener(sender);

    log.log("Starting.");
    
    if (!Bukkit.getPluginManager().isPluginEnabled("PermissionsBukkit")) {
        log.logError("Plugin not loaded.");
        return CommandResult.STATE_ERROR;
    }

    PermissionsPlugin permissionsBukkit = (PermissionsPlugin) Bukkit.getPluginManager().getPlugin("PermissionsBukkit");
    FileConfiguration config = permissionsBukkit.getConfig();

    // Migrate all groups
    log.log("Starting group migration.");
    AtomicInteger groupCount = new AtomicInteger(0);

    ConfigurationSection groupsSection = config.getConfigurationSection("groups");

    Iterators.tryIterate(groupsSection.getKeys(false), key -> {
        final String groupName = MigrationUtils.standardizeName(key);
        Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();

        // migrate data
        if (groupsSection.isConfigurationSection(key)) {
            migrate(lpGroup, groupsSection.getConfigurationSection(key));
        }

        plugin.getStorage().saveGroup(lpGroup).join();
        log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
    });
    log.log("Migrated " + groupCount.get() + " groups");

    // Migrate all users
    log.log("Starting user migration.");
    AtomicInteger userCount = new AtomicInteger(0);

    ConfigurationSection usersSection = config.getConfigurationSection("users");

    Iterators.tryIterate(usersSection.getKeys(false), key -> {
        UUID uuid = BukkitUuids.lookupUuid(log, key);
        if (uuid == null) {
            return;
        }

        User lpUser = plugin.getStorage().loadUser(uuid, null).join();

        // migrate data
        if (usersSection.isConfigurationSection(key)) {
            migrate(lpUser, usersSection.getConfigurationSection(key));
        }

        plugin.getUserManager().getHouseKeeper().cleanup(lpUser.getUniqueId());
        plugin.getStorage().saveUser(lpUser);
        log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY);
    });

    log.log("Migrated " + userCount.get() + " users.");
    log.log("Success! Migration complete.");
    log.log("Don't forget to remove the PermissionsBukkit jar from your plugins folder & restart the server. " +
            "LuckPerms may not take over as the server permission handler until this is done.");
    return CommandResult.SUCCESS;
}
 
Example 19
Source File: LevelManager.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void loadWinSounds() {
    winSoundList.clear();
    File soundFile = new File(SkyWarsReloaded.get().getDataFolder(), "winsounds.yml");

    if (!soundFile.exists()) {
    	if (SkyWarsReloaded.getNMS().getVersion() < 9) {
            	SkyWarsReloaded.get().saveResource("winsounds18.yml", false);
            	File sf = new File(SkyWarsReloaded.get().getDataFolder(), "winsounds18.yml");
            	if (sf.exists()) {
            		sf.renameTo(new File(SkyWarsReloaded.get().getDataFolder(), "winsounds.yml"));
            	}
    	} else {
        	SkyWarsReloaded.get().saveResource("winsounds.yml", false);
    	}
    }

    if (soundFile.exists()) {
        FileConfiguration storage = YamlConfiguration.loadConfiguration(soundFile);

        if (storage.getConfigurationSection("sounds") != null) {
        	for (String key: storage.getConfigurationSection("sounds").getKeys(false)) {
        		String sound = storage.getString("sounds." + key + ".sound");
            	String name = storage.getString("sounds." + key + ".displayName");
            	int volume = storage.getInt("sounds." + key + ".volume");
            	int pitch = storage.getInt("sounds." + key + ".pitch");
            	String material = storage.getString("sounds." + key + ".icon");
            	int level = storage.getInt("sounds." + key + ".level");
            	int cost = storage.getInt("sounds." + key + ".cost");
            	boolean isCustom = storage.getBoolean("sounds." + key + ".isCustomSound");
            	
            	Material mat = Material.matchMaterial(material);
            	if (mat != null) {
            		if (!isCustom) {
            			try {
            				Sound s = Sound.valueOf(sound);
            				if (s != null) {
                				winSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom));
            				}
            			} catch (IllegalArgumentException e) {
            				SkyWarsReloaded.get().getServer().getLogger().info(sound + " is not a valid sound in winsounds.yml");
            			}
            		} else {
            			winSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom));
            		}
            			
                } else {
                	SkyWarsReloaded.get().getServer().getLogger().info(mat + " is not a valid Material in winsounds.yml");
                }
        	}
        }
    }
    Collections.<SoundItem>sort(winSoundList);
}
 
Example 20
Source File: GameMap.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
private static void updateMapData() {
	 File mapFile = new File(SkyWarsReloaded.get().getDataFolder(), "maps.yml");       
        if (mapFile.exists()) {
            FileConfiguration storage = YamlConfiguration.loadConfiguration(mapFile);

            if (storage.getConfigurationSection("maps") != null) {
                for (String key: storage.getConfigurationSection("maps").getKeys(false)) {
                	String displayname = storage.getString("maps." + key + ".displayname");
                	int minplayers = storage.getInt("maps." + key + ".minplayers");
                	String creator = storage.getString("maps." + key + ".creator");
                	List<String> signs = storage.getStringList("maps." + key + ".signs");
                	boolean registered = storage.getBoolean("maps." + key + ".registered");
                	
            		File dataDirectory = SkyWarsReloaded.get().getDataFolder();
                    File mapDataDirectory = new File(dataDirectory, "mapsData");

                    if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
                    	return;
                    }

                    File newMapFile = new File(mapDataDirectory, key + ".yml");
                    copyDefaults(newMapFile);
                    FileConfiguration fc = YamlConfiguration.loadConfiguration(newMapFile);
                    fc.set("displayname", displayname);
    	            fc.set("minplayers", minplayers);
    	            fc.set("creator", creator);
    	            fc.set("signs", signs);
    	            fc.set("registered", registered);
    	            fc.set("environment", "NORMAL");
    	            fc.set("spectateSpawn", "0:95:0");
    	            fc.set("deathMatchSpawns", null);
    	            fc.set("legacy", true);
    	            try {
						fc.save(newMapFile);
					} catch (IOException e) {
						e.printStackTrace();
					}
                }
            }
            boolean result = mapFile.delete();
            if (!result) {
                SkyWarsReloaded.get().getLogger().info("Failed to Delete Old MapData File");
               }
        }
}