Hello! I have a config file for my plugin and all the default values are loaded from the default config correctly but when someone changes the values in the config, they aren’t changed in the code.
Here is the code:
@Inject
@DefaultConfig(sharedRoot = false)
private ConfigurationLoader<CommentedConfigurationNode> configLoader;
@Inject
@ConfigDir(sharedRoot = false)
private Path privateConfigDir;
@Inject
@DefaultConfig(sharedRoot = false)
private Path defaultConfig;
private ConfigurationNode rootDefNode;
private boolean lagEnabled;
public static int clearInterval;
@Listener
public void onServerStart(GameStartedServerEvent event) {
initConfig();
lagEnabled=rootDefNode.getNode("clearlagEnabled").getBoolean();
clearInterval=rootDefNode.getNode("clearInterval").getInt();
}
public void initConfig() {
if (!defaultConfig.toFile().exists()) {
try {
plugin.getAsset("core.conf").orElse(null).copyToFile(defaultConfig);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
rootDefNode = configLoader.load();
lagEnabled=rootDefNode.getNode("clearlagEnabled").getBoolean();
clearInterval=rootDefNode.getNode("clearInterval").getInt();
System.out.println(lagEnabled );
System.out.println(clearInterval);
} catch (IOException e) {
System.out.println("Config doesnt exist");
}
}
Here is the config file
{
//ClearLag
clearlagEnabled=true
clearInterval=3 //Do not set under 3. Time units in Minutes
}