Search in sources :

Example 1 with YAMLInvalidContentException

use of at.pcgamingfreaks.yaml.YAMLInvalidContentException in project Bukkit_Bungee_PluginLib by GeorgH93.

the class Configuration method loadConfig.

private void loadConfig() {
    try {
        if (!configFile.exists() || configFile.length() == 0) {
            logger.info("No config found. Create new one ...");
            if (!configBaseDir.exists() && !configBaseDir.mkdir()) {
                logger.warning("Couldn't create directory. " + configBaseDir.toString());
            }
            try (InputStream is = getClass().getResourceAsStream("/" + inJarPrefix + configPath);
                OutputStream os = new FileOutputStream(configFile)) {
                ByteStreams.copy(is, os);
                os.flush();
            } catch (NullPointerException | IOException e) {
                logger.warning(ConsoleColor.RED + "Failed to extract configuration!" + ConsoleColor.RESET);
                return;
            }
            logger.info("Configuration extracted successfully!");
            config = new YAML(configFile);
            if (newConfigCreated()) {
                try {
                    saveConfig();
                } catch (FileNotFoundException e) {
                    logger.warning(ConsoleColor.RED + "Failed to save the config cause the file does not exist! Has it been deleted?" + ConsoleColor.RESET);
                }
            }
        } else {
            config = new YAML(configFile);
            updateConfig();
        }
    } catch (IOException | YAMLInvalidContentException | NoSuchElementException e) {
        logger.warning(ConsoleColor.RED + "Failed to read the config file! Please check it!" + ConsoleColor.RESET);
        e.printStackTrace();
    }
}
Also used : YAMLInvalidContentException(at.pcgamingfreaks.yaml.YAMLInvalidContentException) YAML(at.pcgamingfreaks.yaml.YAML) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

YAML (at.pcgamingfreaks.yaml.YAML)1 YAMLInvalidContentException (at.pcgamingfreaks.yaml.YAMLInvalidContentException)1 NoSuchElementException (java.util.NoSuchElementException)1