ConfigFile

Discussion in 'Plugin Development' started by TGF, Nov 2, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    TGF

    Hi, i don't know how to create config.yml:p

    Show Spoiler
    Code:
    private FileConfiguration customConfig = null;
        private File customConfigFile = null;
        
        public void reloadCustomConfig() {
            if (customConfigFile == null) {
            customConfigFile = new File(getDataFolder(), "customConfig.yml");
            }
            customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
         
            InputStream defConfigStream = this.getResource("customConfig.yml");
            if (defConfigStream != null) {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                customConfig.setDefaults(defConfig);
            }
        }
        public FileConfiguration getCustomConfig() {
            if (customConfig == null) {
                this.reloadCustomConfig();
            }
            return customConfig;
        }
        public void saveCustomConfig() {
            if (customConfig == null || customConfigFile == null) {
            return;
            }
            try {
                getCustomConfig().save(customConfigFile);
            } catch (IOException ex) {
                this.getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
            }
        }
        public void saveDefaultConfig() {
            if (!configFile.exists()) {            
                 this.plugin.saveResource(fileName, false);
             }
        }

    This is what i put in the main class before onEnable.
     
  2. Offline

    Vandrake

    FileConfiguration config;
    inside onenable:
    config = getConfig();
    config.set("whatever", true);
    saveConfig();
    profit
     
    ferrybig likes this.
Thread Status:
Not open for further replies.

Share This Page