Created
October 31, 2018 19:53
-
-
Save mworzala/0533a76d83e014e1da6941ab35b17eea to your computer and use it in GitHub Desktop.
MaybeConfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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