Java Code Examples for com.electronwill.nightconfig.core.file.CommentedFileConfig

The following examples show how to use com.electronwill.nightconfig.core.file.CommentedFileConfig. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public Function<ModConfig, CommentedFileConfig> reader(Path configBasePath) {
	return (c) -> {
		final Path configPath = configBasePath.resolve(c.getFileName());
		final CommentedFileConfig configData = CommentedFileConfig.builder(configPath).sync()
				.onFileNotFound((newfile, configFormat) -> setupConfigFile(c, newfile, configFormat))
		LOGGER.debug(CONFIG, "Built TOML config for {}", configPath.toString());
		LOGGER.debug(CONFIG, "Loaded TOML config file {}", configPath.toString());

		try {
			FileWatcher.defaultInstance().addWatch(configPath, new ConfigWatcher(c, configData, Thread.currentThread().getContextClassLoader()));
			LOGGER.debug(CONFIG, "Watching TOML config file {} for changes", configPath.toString());
		} catch (IOException e) {
			throw new RuntimeException("Couldn't watch config file", e);

		return configData;
Example 2
private void openConfig(final ModConfig config, final Path configBasePath) {
	LOGGER.debug(CONFIG, "Loading config file type {} at {} for {}", config.getType(), config.getFileName(), config.getModId());
	final CommentedFileConfig configData = config.getHandler().reader(configBasePath).apply(config);
	config.fireEvent(new ModConfig.Loading(config));;
Example 3
Source Project: MiningGadgets   Source File:    License: MIT License 5 votes vote down vote up
public static void loadConfig(ForgeConfigSpec spec, Path path) {

        final CommentedFileConfig configData = CommentedFileConfig.builder(path)

Example 4
ConfigWatcher(final ModConfig modConfig, final CommentedFileConfig commentedFileConfig, final ClassLoader classLoader) {
	this.modConfig = modConfig;
	this.commentedFileConfig = commentedFileConfig;
	this.realClassLoader = classLoader;
Example 5
public void save() {
	((CommentedFileConfig) this.configData).save();
Example 6
public Path getFullPath() {
	return ((CommentedFileConfig) this.configData).getNioPath();
Example 7
Source Project: Sandbox   Source File:    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public Config(Path path) {
    this.config = CommentedFileConfig.builder(path).autoreload().build();
Example 8
public void test() {
	File file = new File("test.conf");
	CommentedFileConfig config = CommentedFileConfig.of(file);
Example 9
 * Returns an Config that converts "just-in-time" the values that are read from the specified
 * Config.
 * @param config the config to wrap
 * @return a wrapper that converts the values read from the config
public CommentedFileConfig wrapRead(CommentedFileConfig config) {
	return new ConvertedCommentedFileConfig(config, this::convert, v -> v,
Example 10
 * Returns an Config that converts "just-in-time" the values that are put into the specified
 * Config.
 * @param config                    the config to wrap
 * @param supportValueTypePredicate Predicate that checks if a given class is supported by the
 *                                  returned config
 * @return a wrapper that converts the values put into the config
public CommentedFileConfig wrapWrite(CommentedFileConfig config,
									 Predicate<Class<?>> supportValueTypePredicate) {
	return new ConvertedCommentedFileConfig(config, v -> v, this::convert,