#Issues with the reloading configs

1 messages · Page 1 of 1 (latest)

fierce herald
#

Hello! I want to make the reload command to reload configs, but it doesn't work

    public void reloadConfigFiles() {
        config = new YamlConfiguration();
        dataConfig = new YamlConfiguration();
        langConfig = new YamlConfiguration();
        try {
            config.load(configFile);
            dataConfig.load(dataFile);
            langConfig.load(langFile);
            System.out.println("Successfully reloaded the config files.");
        } catch (IOException | InvalidConfigurationException e) {
            e.printStackTrace();
        }
    }
cursive socket
#

Are you doing anything with those variables

frozen sonnet
cursive socket
#

Because it doesn't look like it

sick kestrel
#

I probably won't be able to help you, but could you elaborate on how it doesn't work? If there's an exception thrown, include the traceback

frozen sonnet
#

its a default of fileconfiguration

#

not yamlconfiguration

#

btw

fierce herald
fierce herald
cursive socket
#

You are just loading them to local variables which are then immediately discarded

frozen sonnet
#
public class CustomConfig {
    private File file;
    private FileConfiguration fileConfiguration;

    public CustomConfig(String name, JavaPlugin main){
        if(!main.getDataFolder().exists()){
            main.getDataFolder().mkdirs();
        }

        file = new File(main.getDataFolder(),name+".yml");
        if(!file.exists()){
            try {
                file.createNewFile();
                if(main.getResource(name+".yml")!=null){
                    main.saveResource(name+".yml",true);
                }
            }catch (Exception exception){
                exception.printStackTrace();
            }
        }
        fileConfiguration = YamlConfiguration.loadConfiguration(file);


    }

    public CustomConfig(String subfolder,String name, JavaPlugin main){
        if(!main.getDataFolder().exists()){
            main.getDataFolder().mkdirs();
        }
        File folder = new File(main.getDataFolder(),subfolder);
        if(!folder.exists()){
            try{
                folder.mkdirs();
            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
        file = new File(main.getDataFolder()+"/"+subfolder,name+".yml");
        if(!file.exists()){
            try {
                file.createNewFile();
                if(main.getResource("/"+subfolder+name+".yml")!=null){
                    main.saveResource("/"+subfolder+name+".yml",true);
                }
            }catch (Exception exception){
                exception.printStackTrace();
            }
        }
        fileConfiguration = YamlConfiguration.loadConfiguration(file);


    }

    public FileConfiguration getConfig(){
        return fileConfiguration;
    }

    public void save(){
        try {
            fileConfiguration.save(file);
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
    public String getString(String path){
        return getConfig().getString(path);
    }
    public void reload(){
        fileConfiguration = YamlConfiguration.loadConfiguration(file);
    }
    public void deleteFile(){
        file.delete();
    }
}
#

there

#

a custom config wrapper

frozen sonnet
#

public CustomConfig arenaConfig = new CustomConfig("games","arenas",this);

fierce herald
frozen sonnet
#

use the wrapper i sent you

fierce herald
#
    public void reloadConfigFiles() {
        config = YamlConfiguration.loadConfiguration(configFile);
        dataConfig = YamlConfiguration.loadConfiguration(dataFile);
        langConfig = YamlConfiguration.loadConfiguration(langFile);
        System.out.println("Successfully reloaded the config files.");
    }
frozen sonnet
#

are they proper type?

fierce herald
#

wdym

frozen sonnet
#

hopefully dataConfig is still not a yamlconfiguration

fierce herald
#

no, it is

#
    private File configFile;
    private FileConfiguration config;
    private File dataFile;
    private FileConfiguration dataConfig;
    private File langFile;
    private FileConfiguration langConfig;
frozen sonnet
#

so you are calling the values inside the config from the config itself right?

#

no middle man to cache them or something

fierce herald
#

maybe, it is cause I'm using an enum to store the messages?

frozen sonnet
#

well..

#

guess you found the problem

fierce herald
fierce herald
frozen sonnet
#

afaik enums are static and also built at runtime