Java Code Examples for ninja.leaping.configurate.commented.CommentedConfigurationNode#hasMapChildren()
The following examples show how to use
ninja.leaping.configurate.commented.CommentedConfigurationNode#hasMapChildren() .
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
Source File: GriefDefenderConfig.java From GriefDefender with MIT License | 4 votes |
/** * Traverses the given {@code root} config node, removing any values which * are also present and set to the same value on this configs "parent". * * @param root The node to process */ private void removeDuplicates(CommentedConfigurationNode root) { if (this.parent == null) { throw new IllegalStateException("parent is null"); } Iterator<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root); while (it.hasNext()) { ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode> next = it.next(); CommentedConfigurationNode node = next.getNode(); // remove empty maps if (node.hasMapChildren()) { if (node.getChildrenMap().isEmpty()) { node.setValue(null); } continue; } // ignore list values if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) { continue; } // if the node already exists in the parent config, remove it CommentedConfigurationNode parentValue = this.parent.data.getNode(next.getPath().getArray()); if (Objects.equals(node.getValue(), parentValue.getValue())) { node.setValue(null); } else { // Fix list bug if (parentValue.getValue() == null) { if (node.getValueType() == ValueType.LIST) { final List<?> nodeList = (List<?>) node.getValue(); if (nodeList.isEmpty()) { node.setValue(null); } continue; } } // Fix double bug final Double nodeVal = node.getValue(Types::asDouble); if (nodeVal != null) { Double parentVal = parentValue.getValue(Types::asDouble); if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) { node.setValue(null); continue; } } } } }
Example 2
Source File: GriefDefenderConfig.java From GriefDefender with MIT License | 4 votes |
/** * Traverses the given {@code root} config node, removing any values which * are also present and set to the same value on this configs "parent". * * @param root The node to process */ private void removeDuplicates(CommentedConfigurationNode root) { if (this.parent == null) { throw new IllegalStateException("parent is null"); } Iterator<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root); while (it.hasNext()) { ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode> next = it.next(); CommentedConfigurationNode node = next.getNode(); // remove empty maps if (node.hasMapChildren()) { if (node.getChildrenMap().isEmpty()) { node.setValue(null); } continue; } // ignore list values if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) { continue; } // if the node already exists in the parent config, remove it CommentedConfigurationNode parentValue = this.parent.data.getNode(next.getPath().getArray()); if (Objects.equals(node.getValue(), parentValue.getValue())) { node.setValue(null); } else { // Fix list bug if (parentValue.getValue() == null) { if (node.getValueType() == ValueType.LIST) { final List<?> nodeList = (List<?>) node.getValue(); if (nodeList.isEmpty()) { node.setValue(null); } continue; } } // Fix double bug final Double nodeVal = node.getValue(Types::asDouble); if (nodeVal != null) { Double parentVal = parentValue.getValue(Types::asDouble); if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) { node.setValue(null); continue; } } } } }
Example 3
Source File: GriefPreventionConfig.java From GriefPrevention with MIT License | 4 votes |
/** * Traverses the given {@code root} config node, removing any values which * are also present and set to the same value on this configs "parent". * * @param root The node to process */ private void removeDuplicates(CommentedConfigurationNode root) { if (this.parent == null) { throw new IllegalStateException("parent is null"); } Iterator<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root); while (it.hasNext()) { ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode> next = it.next(); CommentedConfigurationNode node = next.getNode(); // remove empty maps if (node.hasMapChildren()) { if (node.getChildrenMap().isEmpty()) { node.setValue(null); } continue; } // ignore list values if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) { continue; } // if the node already exists in the parent config, remove it CommentedConfigurationNode parentValue = this.parent.data.getNode(next.getPath().getArray()); if (Objects.equals(node.getValue(), parentValue.getValue())) { node.setValue(null); } else { // Fix list bug if (parentValue.getValue() == null) { if (node.getValueType() == ValueType.LIST) { final List<?> nodeList = (List<?>) node.getValue(); if (nodeList.isEmpty()) { node.setValue(null); } continue; } } // Fix double bug final Double nodeVal = node.getValue(Types::asDouble); if (nodeVal != null) { Double parentVal = parentValue.getValue(Types::asDouble); if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) { node.setValue(null); continue; } } } } }