Solved Saving custom.yml file

Discussion in 'Spigot Plugin Development' started by anakinsky249, Jun 12, 2017.

  1. Hi, I'm using the following code to create and use yml files:
    Code (Text):
    File f;
    FileConfiguration config;
    f = new File(getDataFolder(), "config.yml");
    config = YamlConfiguration.loadConfiguration(f);
    Simple enough.

    I made a config.yml file inside of my project main tree (same folder as the plugin.yml) and I'd like to use that one if no config file is found. I know there's something like savedefaultconfig() but I dont think it saves config made that way. Thanks for your help.

    EDIT: I'd prefer not using config.setDefault
     
  2. Since you are using the Spigot API, why are you create a seperate Data Folder like that as a config.yml? That does not make sense when you could just make some methods that register onEnable().
     
  3. Because that's how I used to do it. So I guess you mean there are no ways to do that ? Or do I have to use plain old java ?
     
  4. There is but it is useless to unless you are making a seperate file, for instance, 'file.yml' instead of config.yml.

    This is really a waste of time and effort.
     
  5. I have like 5/6 yml files to use. I wanted to use property files but apparently yml is better for config mens
     
  6. Yes, try something like this: (Fix Spaces)
    Code (Text):
    public void saveConfig(String name) {
                  if (!name.endsWith(".yml")) {
                  name = name + ".yml";
                  }
                   FileConfiguration config = getConfig(name);
             File file = new File(plugin.getDataFolder(),name);
    createConfig(name);
    try {
    config.save(file);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
     
  7. config.save doesn't work I already had tried that... createConfig doesn't appear to be a valid method
     
  8. saveResource worked! Thanks