Никакие значения не копируются из конфигурации по умолчанию - PullRequest
3 голосов
/ 10 марта 2012

Я написал этот код:

public void reloadDefConfig(File filepath, String fileInJar) {
    File configFile = filepath;
    FileConfiguration daConfig = YamlConfiguration.loadConfiguration(configFile);

    if (!configFile.exists()){
        log.info(logName + "Creating default \"" + fileInJar + "\".");

        InputStream defConfigStream = getResource(fileInJar);

        if (defConfigStream != null){
            YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
            daConfig.setDefaults(defConfig);

            try {
                daConfig.save(configFile);
                log.info(logName + "Default config file \"" + fileInJar + "\" wrote.");
            } catch (IOException ex){
                log.severe(logName + "Could not write config file: " + fileInJar);
            }
        } else {
            log.warning(logName + "Could not find default \"" + fileInJar + "\" file.");
        }
    }
}

С намерением взять этот config.yml файл внутри JAR и вывести его:

# Home section; this next part of code decides how large the radius to check for monsters
#  for the /home command if not set it will be auto default to 10x10x10 if you want to 
#  disable the radius use -1 on the value (note one value with -1 will disable all)
  home:
    x: 10
    y: 10
    x: 10

Но когда я называю это так:

reloadDefConfig(new File(getDataFolder(), "config.yml"), "config.yml");

Никакие значения не копируются:

# Home section; this next part of code decides how large the radius to check for monsters
#  for the /home command if not set it will be auto default to 10x10x10 if you want to 
#  disable the radius use -1 on the value (note one value with -1 will disable all)

1 Ответ

3 голосов
/ 10 марта 2012

Возможно, у вас есть два пробела до home:.Попробуйте избавиться от них или добавить родительский узел, чтобы полученный файл выглядел так:

# Home section; this next part of code decides how large the radius to check for monsters
#  for the /home command if not set it will be auto default to 10x10x10 if you want to 
#  disable the radius use -1 on the value (note one value with -1 will disable all)
Main:
  home:
    x: 10
    y: 10
    x: 10
...