Solved Error on config.yml creation

Discussion in 'Spigot Plugin Development' started by MrJan01, Apr 30, 2017.

  1. Hello SpigotMC.org community.
    Today I have started a new plugin and I tried to generate the config.yml.
    Surprisingly when I opened the folder in my Plugins folders in my server I realized that
    the config.yml was uncompleted and never happened to me...

    This is the code related to the creation of the config.yml file:
    Code (Text):
    package com.gmail.private;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;

    /**
    * Created by MrJan01 on 24/04/2017.
    */
    public class Main
    extends JavaPlugin
    {
        public static JavaPlugin GetMain;

        public void onEnable() {
            System.out.println("-------------------------------");
            System.out.println("AINCRAFT CORE ADDON");
            System.out.println("-------------------------------");
            GetMain = this;
            getCommand("AincraftLogin").setExecutor(new Commands());
            Bukkit.getServer().getPluginManager().registerEvents(new Events(), this);
            getConfig();
            saveConfig();
        }
    I attached also a screen capture of the project ( on IntelliJ )
    screenshot.png

    Thank you.
     
    • Funny Funny x 1
  2. Why did you run getConfig if you're not what it returns
    And why did you use saveConfig if you didn't set any values
     
    • Agree Agree x 1
  3. 1) getConfig() at the line 21 has no sense.
    2) saveConfig() copies exactly what is written in your config.yml in your plugin's .jar file. Check if you get any Exception on your logs.
     
  4. Maybe loadConfig() ?
     
  5. No, loadConfig() doesn't exist. Maybe you meant reloadConfig() but it's useless because the config is loaded at the startup by default.
     
  6. What I should do?
     
  7. We don't know what you want to do, so we don't know what you should do.
     
  8. I want to create a config.yml with the content of the file inside the src.
     
  9. This does what you want, it saves a default config, but if it exists it doesn't overwrite the existing file.
    Code (Java):
    saveResource("config.yml", false)
    There's also
    Code (Java):
    getConfig().options.copyDefaults(true);
    saveConfig();
     
    • Agree Agree x 1
  10. Thank you!
    One think that worked for me was put SaveDefaultConfig();
    and SaveConfig();

    I hope help others!