Java Code Examples for org.bukkit.configuration.file.YamlConfiguration#setDefaults()

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#setDefaults() . 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: Expansion.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
public final void reloadConfig(String fileName) {
    try {
        File dataFolder = getDataFolder();
        File file = new File(dataFolder, fileName);

        File realFile = file.getCanonicalFile();
        String realName = realFile.getName();

        YamlConfiguration config = new YamlConfiguration();
        config.load(realFile);

        InputStream jarStream = getResource(fileName);
        if(jarStream != null) {
            InputStreamReader reader = new InputStreamReader(jarStream, StandardCharsets.UTF_8);
            YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(reader);
            config.setDefaults(defaultConfig);
        }

        fileNameToConfigMap.put(realName, config);
    } catch(IOException | InvalidConfigurationException ex) {
        Logger logger = getLogger();
        logger.log(Level.SEVERE, "An error ocurred while loading a config named '" + fileName + "'.", ex);
    }
}
 
Example 2
Source File: ConfigAccessor.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reloads the configuration from the file. If the file is null, it will
 * try to load defaults, and if that fails it will create an empty yaml configuration.
 */
public void reloadConfig() {
    if (configFile == null) {
        InputStream str = plugin.getResource(fileName);
        if (str == null) {
            fileConfiguration = new YamlConfiguration();
        } else {
            fileConfiguration = YamlConfiguration
                    .loadConfiguration(new InputStreamReader(str));
        }
    } else {
        fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
        // Look for defaults in the jar
        InputStream defConfigStream = plugin.getResource(fileName);
        if (defConfigStream != null) {
            YamlConfiguration defConfig = YamlConfiguration
                    .loadConfiguration(new InputStreamReader(defConfigStream));
            fileConfiguration.setDefaults(defConfig);
        }
    }
}
 
Example 3
Source File: CustomItemConfig.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
public CustomItemConfig(String group) {
	_defaultConfig = new YamlConfiguration();
	_defaultItemSection = _defaultConfig.createSection("custom-items");

	_configFile = new File(CustomItemManager._plugin.getDataFolder(), "CustomItems" + File.separator + group + ".yml");

	if (!_configFile.exists()) {
		_config = new YamlConfiguration();
		_config.options().header(
				"----- CustomItems (" + group + ") ----- Item configuration file -----\n" +
				"\n" +
				"Note regarding allowed-worlds/blocked-worlds:\n" +
				"  allowed-worlds, when not empty, acts like a whitelist and only\n" +
				"  on worlds from this list the item will be enabled!\n");
	} else {
		_config = YamlConfiguration.loadConfiguration(_configFile);
	}

	_itemsSection = _config.getConfigurationSection("custom-items");
	if (_itemsSection == null) {
		_itemsSection = _config.createSection("custom-items");
	}

	_config.setDefaults(_defaultConfig);
}
 
Example 4
Source File: CommentedYaml.java    From ScoreboardStats with MIT License 6 votes vote down vote up
/**
 * Gets the YAML file configuration from the disk while loading it
 * explicit with UTF-8. This allows umlauts and other UTF-8 characters
 * for all Bukkit versions.
 * <p>
 * Bukkit add also this feature since
 * https://github.com/Bukkit/Bukkit/commit/24883a61704f78a952e948c429f63c4a2ab39912
 * To be allow the same feature for all Bukkit version, this method was
 * created.
 *
 * @return the loaded file configuration
 */
public FileConfiguration getConfigFromDisk() {
    Path file = dataFolder.resolve(FILE_NAME);

    YamlConfiguration newConf = new YamlConfiguration();
    newConf.setDefaults(getDefaults());
    try {
        //UTF-8 should be available on all java running systems
        List<String> lines = Files.readAllLines(file);
        load(lines, newConf);
    } catch (InvalidConfigurationException | IOException ex) {
        logger.error("Couldn't load the configuration", ex);
    }

    return newConf;
}