Checking if my config.yml exists

Discussion in 'Plugin Development' started by Fishrock123, Oct 18, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Fishrock123

    How do I check if my Plugin's config.yml exists? :p
     
  2. if (new File(plugins + File.separator + (PluginName) + File.separator + "config.yml").isFile())
     
  3. Offline

    Sagacious_Zed Bukkit Docs

    You don't need to with the new Configurations API, you are doing much more work than what is most likely needed.

    but otherwise assuming this is in the main class of your plugin.
    Code:
    File configFile = new File(this.getDataFolder(), "config.yml");
    configFile.exists(); // this will tell you if the file exists.
     
  4. Offline

    Fishrock123

    Thanks guys!

    Otherwise it goes and re-writes my file.. ;-; And, this is working great now.
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    If it rewrites your files, you are not setting your defaults correctly.
     
  6. Offline

    Fishrock123

    Eh?

    Code:java
    1. public void onEnable() {
    2. final FileConfiguration c = this.getConfig();
    3.  
    4. if (!new File("plugins" + File.separator + "EntitySuppressor" + File.separator + "config.yml").exists()) {
    5. this.l.info("ES Generating Config File... :D");
    6. c.addDefault("ESConfigVersion; DO NOT CHANGE!", 0.1);
    7. c.addDefault("DefaultMaximum", 64);
    8. c.addDefault("checkDifference", 8);
    9. c.addDefault("limitSquid", true);
    10. c.addDefault("SpawnFlagsCheckInterval", 200);
    11. String[] dnLW = {"null_example_world", "null_example_world_nether"};
    12. c.addDefault("nonLimitedWorlds", Arrays.asList(dnLW));
    13. c.addDefault("LimitSpawners", true);
    14. c.createSection("WorldMaximums");
    15. c.getConfigurationSection("WorldMaximums").addDefault("world", 64);
    16. c.getConfigurationSection("WorldMaximums").addDefault("world_nether", 64);
    17. c.addDefault("debug", false);
    18.  
    19. c.options().copyDefaults(true);
    20. this.saveConfig();
    21. }
    22. //Stuff
    23. }
     
  7. Please read this about file directories:
    http://forums.bukkit.org/threads/37571/
    Important part is "Lesson 3", the rest is outdated with the old config, but that still applies to the new one ...
     
  8. Offline

    Fishrock123

    Eh?

    I... don't need that?
     
  9. Offline

    thehutch

    Use this it helps ok
    @Bone008 is refering to the old API and you dont need to find if it exists anymore because it always will.
     
  10. In Lesson 3, I wrote the inconvenient manner of using such code (as you posted):
    Code:
    "plugins" + File.separator + "EntitySuppressor" + File.separator + "config.yml"
    Not exactly, what I was trying to point out the thing with File.separator.

    This also refers to @Pandemoneus btw.
     
  11. Lol, that just came to my mind. I gotta rewrite my whole config for my next plugin anyway.
     
Thread Status:
Not open for further replies.

Share This Page