Config error

Discussion in 'Spigot Plugin Development' started by BartRiemsdijk, May 26, 2016.

  1. Hey!

    when i am changing things in my plugins config the are changed back after reload!
    i already tried getConfig().options().copyDefaults(false); and getConfig().options().copyDefaults(true);

    Here is my code:
    Code (Text):
    package me.BartRiemsdijk.spawntp;

    import org.bukkit.Bukkit;
    import org.bukkit.Server;
    import org.bukkit.command.PluginCommand;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

        public class Main extends JavaPlugin {
        public static Plugin plugin = null;
       
          public static Main plugin1;

          public void onEnable()
          {
              this.getConfig();
              getConfig().addDefault("Messages.setspawn", "§7[§cSpawnTp§7] §cSpawn succesfuly set");
              getConfig().addDefault("Messages.spawn", "§7[§cSpawnTp§7] §cTeleported to spawn");
              getConfig().addDefault("Messages.noperms", "§7[§cSpawnTp§7] §cAcces denied");
            saveConfig();
           
           
            getCommand("setspawn").setExecutor(new Commands(this));
            getCommand("spawn").setExecutor(new Commands(this));

            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new Events(this), this);

            getConfig().options().copyDefaults(false);
          }
          public void onDisable() {
            saveConfig();
          }
        }
       
     
  2. You're adding defaults every time the plugin gets enabled. Test if the config exists first, since it won't when servers first use the plugin. Only if it doesn't is when you should add the defaults.
     
  3. Why not just use #saveDefaultConfig();?
     
    • Agree Agree x 1
  4. How to do that?
     
  5. Code (Java):
    check if the file filename.yml is existed {
      // do something
     }else // if its not
      // create the filename.yml
    }