Solved Creating config

Discussion in 'Plugin Development' started by Clybzotik, Jan 12, 2019.

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

    Clybzotik

    Hello, I wanted to create a plugin config, but I encountered the following problem: I can't get a config with this code, the file just does not appear.
    PHP:
    public void OnEnable() {
            
    File config = new File(getDataFolder() + File.separator  "config.yml");
            if(!
    config.exists()) {
                
    getConfig().options().copyDefaults(true);
                
    saveDefaultConfig();
                
    getLogger().info("Create config...");
            }
    }
     
  2. Online

    timtower Administrator Administrator Moderator

    @Clybzotik It needs to be onEnable, not OnEnable.
     
  3. Offline

    Clybzotik

    Realy?
    Yes, the problem was exactly that, thanks
     
  4. Offline

    KarimAKL

    @Clybzotik Pretty sure 'saveDefaultConfig();' should be enough to create the config, why all the other code? Just asking because i'm curious.
     
  5. Offline

    TheWolfBadger

    With using File, he's able to check if the config exists already. Not sure if they fixed this problem yet in Bukkit, but I remember a while back that saveDefaultConfig() would overwrite the current config that was already made. Using File he can check if it exists and then use the method saveDefaultConfig() to save the config within his plugin.
     
    KarimAKL likes this.
  6. Offline

    KarimAKL

    @TheWolfBadger I see, i haven't had that so i didn't know, thanks for the information. :)
     
    TheWolfBadger likes this.
Thread Status:
Not open for further replies.

Share This Page