Generating config issue...

Discussion in 'Spigot Plugin Development' started by Invaerne, Apr 29, 2017.

  1. Hi there,

    I'm having a small issue with generating the entire config.yml.
    For some reasons the plugin only generates the beginning... Any ideas what may cause this problem?

    Code (Text):
    public class SpawnPoint extends JavaPlugin
    {
    private File spawnFile;
    private File configFile;
    private FileConfiguration spawn;
    private FileConfiguration config;

        public void onEnable() {
           
         registerSpawnFiles();
         registerCommands();
         registerConfig();
       }

    private void registerCommands() {
         getCommand("setspw").setExecutor(new SetSpawnCommand(this));
         getCommand("spawn").setExecutor(new SpawnCommand(this));
       }
       private void registerSpawnFiles() {
         this.spawnFile = new File(getDataFolder(), "spawn.yml");
         this.spawn = YamlConfiguration.loadConfiguration(this.spawnFile);
         saveSpawn();
       }
       public void saveSpawn() {
         try {
           this.spawn.save(this.spawnFile);
         }
         catch (Exception localException) {
         }
       }
       public File getSpawnFile() {
         return this.spawnFile;
       }
       public FileConfiguration getSpawn() {
         return this.spawn;
       }
       
       private void registerConfig() {
            this.configFile = new File(getDataFolder(), "config.yml");
            this.config = YamlConfiguration.loadConfiguration(this.configFile);
            saveConfig();
        }
    }

     

    Code (Text):
    #
    # +------------------------------------------------------+ #
    # |                    Dear Player                       | #
    # +------------------------------------------------------+ #
    #

    # T
    # T
    # T
    # T
    # T
    # T
    # T
    # T
    # T
    # T
    # T
    # T

    And the config that actually gets generated:

    Code (Text):
    #
    # +------------------------------------------------------+ #
    # |                    Dear Player                       | #
    # +------------------------------------------------------+ #
     
     
  2. Maybe use saveDefaultConfig(); ?
    Or if it is a custom file,
    I don't know if it is right but, get the file and then file.options.saveDefaults(true)

    I don't know if it is file or config since I can't test.
     
  3. getConfig().options.copyDefaults(true);
    saveConfig();
    that works for default configuration every tiem
     
  4. I suggest you to use the JavaPlugin#saveResource method for saving Files, since it saves also comments properly
     
    • Agree Agree x 1
    • Informative Informative x 1
  5. Still the same problem...
     
  6. you have a config.yml next to your plugin.yml in your project?
     
  7. Yep, and the plugin only generates first few lines...
     
  8. Try loadConfig() ? I had the same problem
     
  9. Check out if you compiled fine your project.
    YamlConfiguration.loadConfiguration(new File("config.yml")); isn't not needed. You already save your config by doing:
    Code (Text):
    getConfig().options().copyDefaults(true); // just to be sure
    saveDefaultConfig();