Search in sources :

Example 1 with CommentedConfigurationNode

use of org.spongepowered.configurate.CommentedConfigurationNode in project SpongeCommon by SpongePowered.

the class InheritableConfigHandle method load.

public void load() throws ConfigurateException {
    final CommentedConfigurationNode node;
    final CommentedConfigurationNode mergedNode;
    if (this.isAttached()) {
        // store "what's in the file" separately in memory
        node = this.loader.load();
        // and perform any necessary version updates
        this.doVersionUpdate(node);
        // make a copy of the file data
        mergedNode = node.copy();
    } else {
        node = null;
        mergedNode = CommentedConfigurationNode.root(SpongeConfigs.OPTIONS);
    }
    // merge with settings from parent
    if (this.parent != null && this.parent.mergedNode != null) {
        mergedNode.mergeFrom(this.parent.mergedNode);
    }
    // populate the config object
    this.instance = mergedNode.get(this.instanceType);
    this.node = node;
    this.mergedNode = mergedNode;
    this.doSave();
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode)

Example 2 with CommentedConfigurationNode

use of org.spongepowered.configurate.CommentedConfigurationNode in project SpongeCommon by SpongePowered.

the class Installer method loadConfig.

private LauncherConfig loadConfig() throws ConfigurateException {
    final CommentedConfigurationNode node = this.loader.load();
    final LauncherConfig ret = node.get(LauncherConfig.class);
    // Write back to apply any additions to the file
    this.loader.save(node);
    return ret;
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode)

Example 3 with CommentedConfigurationNode

use of org.spongepowered.configurate.CommentedConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigHandle method load.

void load() throws ConfigurateException {
    if (this.loader == null) {
        // we are virtual
        return;
    }
    final CommentedConfigurationNode node = this.loader.load();
    this.doVersionUpdate(node);
    this.node = node;
    this.instance = node.get(this.instanceType);
    this.doSave();
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode)

Example 4 with CommentedConfigurationNode

use of org.spongepowered.configurate.CommentedConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigHandle method updateSetting.

public CompletableFuture<CommentedConfigurationNode> updateSetting(final String key, final Object value) {
    return ConfigHandle.asyncFailableFuture(() -> {
        final CommentedConfigurationNode upd = this.getSetting(key);
        upd.set(value);
        this.instance = this.node.get(this.instanceType);
        this.save();
        return upd;
    }, ForkJoinPool.commonPool());
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode)

Example 5 with CommentedConfigurationNode

use of org.spongepowered.configurate.CommentedConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigHandle method updateSetting.

public <V> CompletableFuture<CommentedConfigurationNode> updateSetting(final String key, final V value, final TypeToken<V> token) {
    return ConfigHandle.asyncFailableFuture(() -> {
        final CommentedConfigurationNode upd = this.getSetting(key);
        upd.set(token, value);
        this.instance = this.node.get(this.instanceType);
        this.save();
        return upd;
    }, ForkJoinPool.commonPool());
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode)

Aggregations

CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)8 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 NodePath (org.spongepowered.configurate.NodePath)1 ConfigurationTransformation (org.spongepowered.configurate.transformation.ConfigurationTransformation)1