Search in sources :

Example 1 with ConfigurationNode

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

the class WorldMigrator method getOldWorldContainer.

/**
 * Gets the old world container used when this server used to be running Bukkit.
 *
 * @return The world container
 */
public static Path getOldWorldContainer() {
    Path worldContainer = Paths.get(".");
    final Path bukkitYml = worldContainer.resolve("bukkit.yml");
    if (Files.exists(bukkitYml)) {
        try {
            final ConfigurationNode node = YamlConfigurationLoader.builder().path(bukkitYml).build().load();
            final String containerCandidate = node.node("settings", "world-container").getString("");
            if (!containerCandidate.isEmpty()) {
                try {
                    worldContainer = worldContainer.resolve(containerCandidate);
                } catch (final InvalidPathException ipe) {
                    SpongeCommon.logger().warn("Cannot use path [{}] specified under [world-container] in bukkit" + ".yml. Will use [{}] instead.", containerCandidate, worldContainer, ipe);
                }
            }
        } catch (final ConfigurateException ex) {
            SpongeCommon.logger().warn("Cannot load bukkit.yml. Will use [{}] instead.", worldContainer, ex);
        }
    }
    return worldContainer;
}
Also used : Path(java.nio.file.Path) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) ConfigurateException(org.spongepowered.configurate.ConfigurateException) InvalidPathException(java.nio.file.InvalidPathException)

Example 2 with ConfigurationNode

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

the class DuplicateRemovalVisitorTest method testPreservesListElements.

@Test
void testPreservesListElements() throws SerializationException {
    final ConfigurationNode parent = BasicConfigurationNode.root(n -> {
        n.appendListNode().raw("one");
        n.appendListNode().raw("two");
        n.appendListNode().raw("red");
        n.appendListNode().raw("blue");
    });
    final ConfigurationNode child = BasicConfigurationNode.root(n -> {
        n.appendListNode().raw("one");
        n.appendListNode().raw("two");
        n.appendListNode().raw("red");
        n.appendListNode().raw("green");
    });
    DuplicateRemovalVisitor.visit(child, parent);
    assertEquals(ImmutableList.of("one", "two", "red", "green"), child.getList(String.class));
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationNode

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

the class DuplicateRemovalVisitorTest method testSpongeExample.

@Test
void testSpongeExample() {
    final ConfigurationNode parent = CommentedConfigurationNode.root(p -> {
        p.node("sponge", "world-generation-modifiers").raw(ImmutableList.of()).comment("World Generation Modifiers to apply to the " + "world");
        p.node("sponge", "player-block-tracker").act(pBT -> {
            pBT.node("block-blacklist").raw(ImmutableList.of()).comment("Block IDs that will be " + "blacklisted for player block placement tracking");
            pBT.node("enabled").raw(true);
        });
    });
    final ConfigurationNode child = parent.copy();
    DuplicateRemovalVisitor.visit(child, parent);
    assertTrue(child.empty());
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigurationNode

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

the class DuplicateRemovalVisitorTest method testMapKeysClearedInList.

@Test
void testMapKeysClearedInList() {
    final ConfigurationNode parent = BasicConfigurationNode.root(n -> {
        n.appendListNode().raw("one");
        n.appendListNode().raw("two");
        n.appendListNode().act(c -> {
            c.node("zombie").raw(false);
            c.node("villager").raw(false);
            c.node("cat").raw(true);
            c.node("ocelot").raw(true);
        });
        n.appendListNode().raw("blue");
    });
    final ConfigurationNode child = BasicConfigurationNode.root(n -> {
        n.appendListNode().raw("one");
        n.appendListNode().raw("two");
        n.appendListNode().act(c -> {
            c.node("zombie").raw(false);
            c.node("villager").raw(false);
            c.node("cat").raw(true);
            c.node("ocelot").raw(false);
        });
        n.appendListNode().raw("blue");
    });
    DuplicateRemovalVisitor.visit(child, parent);
    assertEquals(4, child.childrenList().size());
    assertNull(child.node(2, "cat").raw());
    assertEquals(false, child.node(2, "ocelot").raw());
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigurationNode

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

the class DuplicateRemovalVisitorTest method testClearEqualValues.

@Test
void testClearEqualValues() {
    final ConfigurationNode parent = BasicConfigurationNode.root();
    final ConfigurationNode child = BasicConfigurationNode.root();
    parent.raw("test");
    child.raw("test");
    DuplicateRemovalVisitor.visit(child, parent);
    assertNull(child.raw());
}
Also used : CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) BasicConfigurationNode(org.spongepowered.configurate.BasicConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationNode (org.spongepowered.configurate.ConfigurationNode)24 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)20 Test (org.junit.jupiter.api.Test)19 BasicConfigurationNode (org.spongepowered.configurate.BasicConfigurationNode)19 DataContainer (org.spongepowered.api.data.persistence.DataContainer)7 DataView (org.spongepowered.api.data.persistence.DataView)2 ConfigurateException (org.spongepowered.configurate.ConfigurateException)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 InvalidPathException (java.nio.file.InvalidPathException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ResourceKey (org.spongepowered.api.ResourceKey)1 RespawnLocation (org.spongepowered.api.util.RespawnLocation)1 NodePath (org.spongepowered.configurate.NodePath)1 HoconConfigurationLoader (org.spongepowered.configurate.hocon.HoconConfigurationLoader)1