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;
}
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));
}
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());
}
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());
}
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());
}
Aggregations