Creating config like config.yml?

Discussion in 'Plugin Development' started by DerFreakey, May 11, 2015.

Thread Status:
Not open for further replies.
  1. Hey Guys,
    at first I have to say "Sorry for my bad english."

    But thats not the problem, today I tried to create a config like the config.yml so that I can add the defaults with the Text Editor of Eclipse, but I can't figure out how this works, because I don't know how to save the file (it's called "messages.yml") from the src package to the plugins/MyPluginName folder.

    Has anyone got an idea how I could do this? And no, I don't want to use the YamlConfiguration, because I want to add the defaults in the Text Editor and not in the class.

    Thanks for your help,
    Best Regards
  2. 1. You need a File and a FileConfiguration:
    public File f;
    public FileConfiguration config;
    2. In a method where you load it, get the file. getDataFolder() represents plugins/YourPluginName.
    f = new File(getDataFolder(), "messages.yml");
    3. In the same method, load the config:
    config = YamlConfiguration.loadConfiguration(f);
    4. In the same method, save the defaults:
    5. Create the method to save the defaults:
    public void saveDefaults() {
    InputStream defConfigInputStream = getResource("messages.yml");
    if (defConfigInputStream != null) {
    YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigInputStream);
    6. make a saveMessages method:
    public void saveMessages() {
    try {;
    } catch(Exception e) {
    //Handle exception
    DerFreakey likes this.
  3. Offline


    Have you file configuration and file? When yes:; when no, what is your code?

    Other things, write to file, read from file is also fileconfiguration.whatYouNeed, config is fileconfiguration, too, but bukkit added method saveConfig().

    I dont saw the post before me, i no refreshed the page, but I dont going to remove this post, it maybe help, but I think post before me answered all.

  4. Thank you very much! That's what i needed! :)
Thread Status:
Not open for further replies.

Share This Page