@Override public Object[] getPath() { LinkedList<Object> pathElements = new LinkedList<>(); ConfigurationNode ptr = this; if (ptr.getParent() == null) { return new Object[] {this.getKey()}; } do { pathElements.addFirst(ptr.getKey()); } while ((ptr = ptr.getParent()).getParent() != null); return pathElements.toArray(); }
@NonNull @Override public Object[] getPath() { LinkedList<Object> pathElements = new LinkedList<>(); ConfigurationNode pointer = this; if (pointer.getParent() == null) { return new Object[]{this.getKey()}; } do { pathElements.addFirst(pointer.getKey()); } while ((pointer = pointer.getParent()).getParent() != null); return pathElements.toArray(); }
@NonNull @Override public Object[] getPath() { LinkedList<Object> pathElements = new LinkedList<>(); ConfigurationNode pointer = this; if (pointer.getParent() == null) { return new Object[]{this.getKey()}; } do { pathElements.addFirst(pointer.getKey()); } while ((pointer = pointer.getParent()).getParent() != null); return pathElements.toArray(); }
@Test public void testCopyPaths() { ConfigurationNode node = SimpleConfigurationNode.root(); node.getNode("test").setValue(5); node.getNode("section", "val1").setValue(true); node.getNode("section", "val2").setValue("TEST"); ConfigurationNode original = node.getNode("section"); ConfigurationNode copy = original.copy(); assertNotNull(original.getParent()); assertNull(copy.getParent()); ConfigurationNode originalVal = original.getNode("val1"); ConfigurationNode copyVal = copy.getNode("val1"); assertEquals(2, originalVal.getPath().length); assertEquals(1, copyVal.getPath().length); assertNotNull(originalVal.getParent()); assertNotNull(copyVal.getParent()); assertNotSame(originalVal.getParent(), copyVal.getParent()); }
tBuilder() .addAction(new Object[]{WILDCARD_OBJECT, WILDCARD_OBJECT, 0, "worlds"}, (nodePath, configurationNode) -> { ConfigurationNode entityNode = configurationNode.getParent().getParent(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : configurationNode.getChildrenMap().entrySet()) { entityNode.getAppendedNode().setValue(ent.getValue()) configurationNode.getParent().getNode("permissions-default").setValue(value); continue; if (defaultNode.getBoolean()) { ConfigurationNode addToNode = null; final ConfigurationNode defaultsParent = valueAtPath.getParent().getParent().getParent().getNode("systems", "default"); for (ConfigurationNode node : defaultsParent.getChildrenList()) { if (Objects.equal(node.getNode(FileSubjectData.KEY_CONTEXTS).getValue(), valueAtPath.getNode(FileSubjectData.KEY_CONTEXTS).getValue())) { addToNode = defaultsParent.getAppendedNode(); addToNode.getNode("parents").getAppendedNode().setValue("group:" + valueAtPath.getParent().getKey());
/** * Creat a configuration transformation that converts the Bukkit global configuration structure to the new Sponge configuration structure. * @return A transformation that converts a Bukkit-style configuration to a Sponge-style configuration */ private static ConfigurationTransformation initialToZero() { return builder() .setMoveStrategy(MoveStrategy.MERGE) .addAction(p("permissions"), (inputPath, valueAtPath) -> new Object[0]) .addAction(p("permissions", "backend"), (inputPath, valueAtPath) -> p("default-backend")) .addAction(p("permissions", "allowOps"), DELETE_ITEM) .addAction(p("permissions", "basedir"), DELETE_ITEM) .addAction(p("updater"), (inputPath, valueAtPath) -> { valueAtPath.getNode("enabled").setValue(valueAtPath.getValue()); valueAtPath.getNode("always-update").setValue(valueAtPath.getParent().getNode("alwaysUpdate")); valueAtPath.getParent().getNode("alwaysUpdate").setValue(null); return null; }) .build(); }