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? Spoiler: Main Code 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(); } } Spoiler: Config Code (Text): # # +------------------------------------------------------+ # # | Dear Player | # # +------------------------------------------------------+ # # # T # T # T # T # T # T # T # T # T # T # T # T And the config that actually gets generated: Spoiler: Generated Config Code (Text): # # +------------------------------------------------------+ # # | Dear Player | # # +------------------------------------------------------+ #
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.
getConfig().options.copyDefaults(true); saveConfig(); that works for default configuration every tiem
I suggest you to use the JavaPlugin#saveResource method for saving Files, since it saves also comments properly
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();