public ConfigurationSection getSetSection(String path, Map<String, String> defaultValues) throws InvalidConfigurationException { if (config.isConfigurationSection(path)) { return config.getConfigurationSection(path); } else if (config.contains(path)) { throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile + " is not a configuration section"); } else { logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultValues, configFile}); ConfigurationSection section = config.createSection(path); for (Map.Entry<String, String> entry : defaultValues.entrySet()) { section.set(entry.getKey(), entry.getValue()); } return section; } }
public Map<String, String> getSetStringMap(String path, Map<String, String> defaultValues) throws InvalidConfigurationException { if (config.isConfigurationSection(path)) { ConfigurationSection section = config.getConfigurationSection(path); Map<String, Object> entries = section.getValues(false); Map<String, String> values = new HashMap<>(entries.size()); for (Map.Entry<String, Object> entry : entries.entrySet()) { Object obj = entry.getValue(); if (obj instanceof String) { values.put(entry.getKey(), (String) obj); } else if (obj instanceof Double || obj instanceof Integer || obj instanceof Boolean) { values.put(entry.getKey(), obj.toString()); } else { throw new InvalidConfigurationException("Object " + obj + " found in map " + path + " in file " + configFile.toAbsolutePath() + " is not an integerr"); } } return values; } else if (config.contains(path)) { throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile + " is not a map"); } else { logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultValues, configFile}); ConfigurationSection section = config.createSection(path); for (Map.Entry<String, String> entry : defaultValues.entrySet()) { section.set(entry.getKey(), entry.getValue()); } return defaultValues; } }
private void register() { registerFile.getParentFile().mkdirs(); YamlConfiguration registered = new YamlConfiguration(); if (registerFile.exists()) { try { registered.load(registerFile); } catch (Exception ex) { logger.log(Level.WARNING, "Error reading " + registerFile, ex); return; } } ConfigurationSection playerSection = registered.createSection(playerId); playerSection.set("name", playerName); playerSection.set("code", code); playerSection.set("skin_url", skinURL); try { registered.save(registerFile); } catch (Exception ex) { logger.log(Level.WARNING, "Error saving " + registerFile, ex); return; } } }
ConfigurationSection rpSection = rpConfig.createSection(rpKey);
YamlConfiguration configuration = new YamlConfiguration(); for (URLMap map : saveMaps) { ConfigurationSection mapConfig = configuration.createSection(Short.toString(map.id)); mapConfig.set("world", map.world); mapConfig.set("url", map.url);
private void loadYml(File ymlFile) { try { BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage( ChatWriter.pluginMessage(ChatColor.GREEN + "Loading statistics from YAML-File ...")); YamlConfiguration config = null; Map<OfflinePlayer, PlayerStatistic> map = new HashMap<>(); this.databaseFile = ymlFile; if (!ymlFile.exists()) { ymlFile.getParentFile().mkdirs(); ymlFile.createNewFile(); config = new YamlConfiguration(); config.createSection("data"); config.save(ymlFile); } else { config = YamlConfiguration.loadConfiguration(ymlFile); } this.fileDatabase = config; } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); ex.printStackTrace(); } BedwarsRel.getInstance().getServer().getConsoleSender() .sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Done!")); }
private void loadYml(File ymlFile) { try { BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage( ChatWriter.pluginMessage(ChatColor.GREEN + "Loading statistics from YAML-File ...")); YamlConfiguration config = null; Map<OfflinePlayer, PlayerStatistic> map = new HashMap<>(); this.databaseFile = ymlFile; if (!ymlFile.exists()) { ymlFile.getParentFile().mkdirs(); ymlFile.createNewFile(); config = new YamlConfiguration(); config.createSection("data"); config.save(ymlFile); } else { config = YamlConfiguration.loadConfiguration(ymlFile); } this.fileDatabase = config; } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); ex.printStackTrace(); } BedwarsRel.getInstance().getServer().getConsoleSender() .sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Done!")); }
tokenSection = cfg.createSection("tokens"); tokenSection.set("default", token); tokens.put("default", KeyCreator.createKeyFrom(token));
ConfigurationSection itemSection = itemConfig.createSection(template); itemSection.set("creator_id", player.getUniqueId().toString()); itemSection.set("creator", player.getName());
ConfigurationSection wandSection = wandConfig.createSection(template); wand.save(wandSection, true); wandSection.set("creator_id", player.getUniqueId().toString());
yml.createSection("teams", this.teams);
ConfigurationSection s = blockConfig.createSection(BLOCKS_YAML_PREFIX + "." + pos); ConfigurationSection en = blockConfig.createSection(ENTITIES_YAML_PREFIX + pos + "." + e.getUniqueId()); en.set("type", e.getType().name()); en.set("name", e.getCustomName()); ConfigurationSection a = blockConfig.createSection(ATTACHED_YAML_PREFIX + pos); a.set("bd", block.getBlockData().getAsString());
yml.createSection("teams", this.teams);