Create config file from folder

Discussion in 'Spigot Plugin Development' started by kinukin, Jun 3, 2017.

  1. Is this possible to do?

    I want to create a config folder manually from the folder where the configs will be stored. Is it possible to manually create a config from its folder and have it be saved and load from code?

    Thanks
     
  2. I'm not sure what you mean but java supports a way to make folders and bukkit allows you to have config folders
     
  3. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Code (Text):
    File customFile = new File(plugin.getDataFolder(), "myData.yml");
    if(!customFile.exists) customFile.createNewFile();
    FileConfiguration customConfig = YamlConfiguration.loadFrom(customFile);
    customConfig.set("mykey", "myvalue");
    customConfig.save(customFile);
     

  4. Can I write a value in the config instead of writing it through code? Like an MOTD for example. You can manually write in the config
     
  5. Mas

    Mas

    Well of course, it's just like any normal config file. Open it and change whatever you want.
     
  6. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Just use a regular config then?
    Create a config.yml file in your IDE/jar, and use this:
    Code (Text):
    motd: YourMotdHere
    And in the onEnable:
    Code (Text):
    plugin.getConfig().options().saveDefaults(true);
    plugin.saveDefaultConfig()
     
  7. How can I do it using a custom config?