Solved Config Files

Discussion in 'BungeeCord Plugin Development' started by MrFishCakes, May 30, 2017.

Thread Status:
Not open for further replies.
  1. Hello,
    I am having trouble creating my config file in BungeeCord I keep getting this error:
    http://prntscr.com/fdvwzh
    My code can be found here:
    Code (Java):
    package me.mrfishcakes.bungeecore.utils;

    import java.io.File;
    import java.io.IOException;

    import me.mrfishcakes.bungeecore.BungeeCore;

    import net.md_5.bungee.BungeeCord;
    import net.md_5.bungee.config.Configuration;
    import net.md_5.bungee.config.ConfigurationProvider;
    import net.md_5.bungee.config.YamlConfiguration;

    public class Files {

        public static Configuration config;
        public static ConfigurationProvider configp;
        public static File configfile;

        public void checkConfig() {
            configfile = new File(BungeeCore.plugin.getDataFolder() + "/config.yml");
            if (!configfile.exists()) {
                try {
                    configfile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                loadConfig();
            }
        }

        public void loadConfig() {
            configfile = new File(BungeeCord.getInstance().getPluginsFolder() + "/config.yml");
            configp = ConfigurationProvider.getProvider(YamlConfiguration.class);
            try {
                config = configp.load(configfile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void saveConfig() {
            configfile = new File(BungeeCord.getInstance().getPluginsFolder() + "/config.yml");
            configp = ConfigurationProvider.getProvider(YamlConfiguration.class);
            try {
                configp.save(config, configfile);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
     

    Anyone able to tell me why there's an error now?
    Thanks.
     
  2. Try JSON file configurations. They will work like a charm. ;)
     
  3. I did some playing around and eventually got it working but thanks for the tip I'll give it ago. ;)
     
Thread Status:
Not open for further replies.