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

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#load() . 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: KettleConfig.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static void init(File configFile) {
    CONFIG_FILE = configFile;
    config = new YamlConfiguration();

    try {
        config.load(CONFIG_FILE);
    } catch (IOException ignored) {
    } catch (InvalidConfigurationException ex) {
        Bukkit.getLogger().log(Level.SEVERE, "Could not load kettle.yml, please correct your syntax errors", ex);
        throw Throwables.propagate(ex);
    }

    config.options().header(HEADER);
    config.options().copyDefaults(true);
    verbose = getBoolean("verbose", false);

    commands = new HashMap<>();
    commands.put("kettle", new KettleCommand("kettle"));

    version = getInt("config-version", 1);
    set("config-version", 1);
    readConfig(KettleConfig.class, null);
}
 
Example 2
Source File: SpigotConfig.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static void init(File configFile) {
    CONFIG_FILE = configFile;
    config = new YamlConfiguration();
    try {
        config.load(CONFIG_FILE);
    } catch (IOException ignored) {
    } catch (InvalidConfigurationException ex) {
        Bukkit.getLogger().log(Level.SEVERE, "Could not load spigot.yml, please correct your syntax errors", ex);
        throw Throwables.propagate(ex);
    }

    config.options().header(HEADER);
    config.options().copyDefaults(true);

    commands = new HashMap<>();

    version = getInt("config-version", 11);
    set("config-version", 11);
    readConfig(SpigotConfig.class, null);
}
 
Example 3
Source File: CommentYamlConfiguration.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
public static YamlConfiguration loadConfiguration(File file) {
     Validate.notNull(file, "File cannot be null");
     YamlConfiguration config = new CommentYamlConfiguration();
     if(!file.exists())
try {
	file.createNewFile();
} catch (IOException e1) {
	e1.printStackTrace();
}
     try {
         config.load(file);
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     } catch (IOException | InvalidConfigurationException var4) {
         Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, var4);
     }
 
     return config;
 }
 
Example 4
Source File: UCConfig.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
private static YamlConfiguration updateFile(File saved) {
    YamlConfiguration finalyml = new YamlConfiguration();
    YamlConfiguration tempProts = new YamlConfiguration();
    try {
        finalyml.load(saved);

        tempProts.load(new InputStreamReader(UChat.get().getResource("assets/ultimatechat/protections.yml"), StandardCharsets.UTF_8));
    } catch (Exception e) {
        e.printStackTrace();
    }

    for (String key : tempProts.getKeys(true)) {
        Object obj = tempProts.get(key);
        if (finalyml.get(key) != null) {
            obj = finalyml.get(key);
        }
        finalyml.set(key, obj);
    }
    return finalyml;
}
 
Example 5
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 6
Source File: MenuLoader.java    From TrMenu with MIT License 5 votes vote down vote up
public static List<String> loadMenu(File file) {
    String name = file.getName();
    List<String> errors = Lists.newArrayList();

    if (file.isDirectory()) {
        for (File f : Objects.requireNonNull(file.listFiles())) {
            errors.addAll(Objects.requireNonNull(loadMenu(f)));
        }
    } else if (!name.toLowerCase().endsWith(".yml") && !name.toLowerCase().endsWith(".json")) {
        return new ArrayList<>();
    } else {
        Map<String, Object> sets;
        try {
            if (name.toLowerCase().endsWith(".json")) {
                sets = new GsonBuilder().registerTypeAdapter(Double.class, (JsonSerializer<Double>) (src, typeOfSrc, context) -> src == src.longValue() ? new JsonPrimitive(src.longValue()) : new JsonPrimitive(src)).create().fromJson(JsonItem.readFileAsJson(file), Map.class);
            } else {
                YamlConfiguration config = new YamlConfiguration();
                config.load(file);
                sets = config.getValues(false);
            }
        } catch (Exception e) {
            errors.add(TLocale.asString("MENU.LOADING-ERRORS." + (name.toLowerCase().endsWith(".json") ? "JSON" : "YAML"), name, e.getMessage(), Arrays.toString(e.getStackTrace())));
            return errors;
        }
        errors.addAll(loadMenu(sets, name, file, true).getErrors());
    }
    return errors;
}
 
Example 7
Source File: ExpansionManager.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private YamlConfiguration getExpansionDescription(JarFile jarFile) throws IllegalStateException, IOException, InvalidConfigurationException {
    JarEntry entry = jarFile.getJarEntry("expansion.yml");
    if(entry == null) {
        String errorMessage = ("Expansion file '" + jarFile.getName() + "' does not contain an expansion.yml file.");
        throw new IllegalStateException(errorMessage);
    }
    
    InputStream inputStream = jarFile.getInputStream(entry);
    InputStreamReader reader = new InputStreamReader(inputStream);
    BufferedReader buffer = new BufferedReader(reader);
    
    YamlConfiguration description = new YamlConfiguration();
    description.load(buffer);
    return description;
}
 
Example 8
Source File: CivSettings.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public static FileConfiguration loadCivConfig(String filepath) throws FileNotFoundException, IOException, InvalidConfigurationException {

		File file = new File(plugin.getDataFolder().getPath()+"/data/"+filepath);
		if (!file.exists()) {
			CivLog.warning("Configuration file:"+filepath+" was missing. Streaming to disk from Jar.");
			streamResourceToDisk("/data/"+filepath);
		}
		
		CivLog.info("Loading Configuration file:"+filepath);
		// read the config.yml into memory
		YamlConfiguration cfg = new YamlConfiguration(); 
		cfg.load(file);
		return cfg;
	}