Solved Copy config.yml from jar to plugin folder

Discussion in 'Spigot Plugin Development' started by Bredo, Jan 21, 2020.

Thread Status:
Not open for further replies.
  1. Okay, so I am trying to copy a config.yml file from inside of mine jar out to my plugins folder
    I have done it before, but I don't remember how, now I think I have tried 7 different ways to do it, every time nothing happens.
    I have tested that the InputStream is correct, and I can get the data from the config.yml inside of my jar, but I can't copy it out to my plugin folders config.yml

    my code at the moment:
    Code (Java):

            config = new File(main.getDataFolder(), "config.yml");
            configC = YamlConfiguration.loadConfiguration(config);
            InputStream input = this.getClass().getResourceAsStream("config.yml");
            File in = new File(input.toString());
            YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(in);
            configC.setDefaults(defConfig);
            configC.options().copyDefaults(true);
     
     
  2. You can save any resource with your JavaPlugin instance
    plugin.saveResource("config.yml", false) for example.
    The boolean is for replacement
     
    • Agree Agree x 1
  3. hmm it doesn't work :/
    I've tried:
    Code (Text):

        main.saveResource(main.getClass().getResource("config.yml").getPath(), true);
    and
        main.saveResource(config.getPath(), true);
     
     
  4. I'm on mobile, so I can't explain it, but read the wiki it will help you(hopefully)

    Your .yml file must be under src folder(if you are using maven under resource instead of src).

    By the way if you are using maven depending on your setting you must use the include tag.

    Edit: wording

    Editn 2: config.yml comes with bukkit you just need to run saveDefaults or something similar on #onEnable()
     
  5. I don't use maven, and it is in my src :( I have no idea why it won't work
    And I already tried the saveDeafult... :(

    [​IMG]
     
    #5 Bredo, Jan 21, 2020
    Last edited: Jan 21, 2020
  6. Drag your config.yml directly onto your src folder. Then you just need to call saveResource("config.yml", false)
    no path, file or anything else. Just the name and the classloader will find it
     
  7. I have tried that, that didn't work
     
  8. I found a solution, but thanks for the help.
     
Thread Status:
Not open for further replies.