spigot file config code example

Example 1: spigot make config file

@Override
    public void onEnable() {
        createFiles();
    }

    private void createFiles(){
        File configf = new File(getDataFolder(), "config.yml");

        if(!configf.exists()){
            configf.getParentFile().mkdirs();
            saveResource("config.yml", false);
        }
        FileConfiguration config = new YamlConfiguration();

        try{
            config.load(configf);
        }catch (IOException | InvalidConfigurationException e){
            e.printStackTrace();
        }
    }

Example 2: spigot make config file

public private File configf;
    public FileConfiguration config;

    private void createFiles(){
        configf = new File(getDataFolder(), "config.yml");

        if(!configf.exists()){
            configf.getParentFile().mkdirs();
            saveResource("config.yml", false);
        }
        config = new YamlConfiguration();

        try{
            config.load(configf);
        }catch (IOException | InvalidConfigurationException e){
            e.printStackTrace();
        }
    }

Tags:

Java Example