Skip to content

Instantly share code, notes, and snippets.

@mworzala
Created October 31, 2018 19:53
Show Gist options
  • Save mworzala/0533a76d83e014e1da6941ab35b17eea to your computer and use it in GitHub Desktop.
Save mworzala/0533a76d83e014e1da6941ab35b17eea to your computer and use it in GitHub Desktop.
MaybeConfig
public class CommonConfig {
CommentedConfigurationNode addDefault(CommentedConfigurationNode node) {
//default config options
return node;
}
}
// This could also be static to avoid creating instances. probably would be better.
public class ConfigManager {
public ConfigManager(Function<CommentedConfigurationNode, CommentedConfigurationNode> customOptions, File location) throws Exception { //dont throw this do it right
if (!location.exists())
location.createNewFile();
ConfigurationLoader<CommentedConfigurationNode> conf = HoconConfigurationLoader.builder().setFile(location).build();
CommentedConfigurationNode node = conf.load();
node = customOptions.apply(node);
// save node to file
}
}
public void IAmAPlugin() throws Exception {
String fileLoc = "C:/some/file.file";
ConfigManager conf = new ConfigManager(new File(fileLoc), (node) -> {
node = new CommonConfig().addDefault(node);
node.AddSomeValueOrABunch();
return node;
});
conf.getValueOrWhatnot();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment