Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.savvy.cb.other;
- import me.savvy.cb.Core;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import java.io.File;
- import java.io.IOException;
- /**
- * Created by savit on 6/27/2017.
- */
- public class ConfigBuilder {
- private String name;
- private File file;
- private FileConfiguration fc;
- public ConfigBuilder(String name, String path, String fileName) {
- this.name = name;
- try {
- file = new File(path + "/" + fileName);
- if (!(file.exists())) {
- file.getParentFile().mkdirs();
- file.createNewFile();
- }
- fc = YamlConfiguration.loadConfiguration(file);
- } catch(IOException ex) {
- Core.getInstance().getLogger().severe(String.format("Unable to generate configuration file '%s'", fileName));
- ex.printStackTrace();
- }
- }
- public FileConfiguration getConfig() {
- return fc;
- }
- public File getFile() {
- return file;
- }
- public void saveConfig() {
- try {
- fc.save(file);
- Core.getInstance().getLogger().info(String.format("Successfully saved configuration file '%s'", file.getName()));
- } catch(IOException ex) {
- Core.getInstance().getLogger().severe(String.format("Unable to generate configuration file '%s'", file.getName()));
- ex.printStackTrace();
- }
- }
- public void register() {
- if(!ConfigManager.hasConfig(name)) {
- ConfigManager.addConfig(name, this);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement