Java Code Examples for ninja.leaping.configurate.ConfigurationNode#hasMapChildren()

The following examples show how to use ninja.leaping.configurate.ConfigurationNode#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: ConfigTabControl.java    From ChatUI with MIT License 6 votes vote down vote up
private ConfigEntry.ConfigValue nodeToValue(ConfigurationNode node) {
    if (node.hasMapChildren() || node.hasListChildren()) {
        return new ConfigEntry.ComplexValue(node);
    }
    Object value = node.getValue();
    if (value instanceof Number) {
        return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.NUMBER);
    } else if (value instanceof Boolean) {
        return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.BOOLEAN);
    } else if (value instanceof String) {
        return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.STRING);
    } else if (value == null) {
        return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.NULL);
    }
    return new ConfigEntry.UnknownValueType(value);
}
 
Example 2
Source File: AbstractConfigurateStorage.java    From LuckPerms with MIT License 6 votes vote down vote up
private static ImmutableContextSet readContexts(ConfigurationNode attributes) {
    ImmutableContextSet.Builder contextBuilder = new ImmutableContextSetImpl.BuilderImpl();
    ConfigurationNode contextMap = attributes.getNode("context");
    if (!contextMap.isVirtual() && contextMap.hasMapChildren()) {
        contextBuilder.addAll(ContextSetConfigurateSerializer.deserializeContextSet(contextMap));
    }

    String server = attributes.getNode("server").getString("global");
    if (!server.equals("global")) {
        contextBuilder.add(DefaultContextKeys.SERVER_KEY, server);
    }

    String world = attributes.getNode("world").getString("global");
    if (!world.equals("global")) {
        contextBuilder.add(DefaultContextKeys.WORLD_KEY, world);
    }

    return contextBuilder.build();
}
 
Example 3
Source File: GsonTypeSerializer.java    From helper with MIT License 5 votes vote down vote up
@Override
public JsonElement deserialize(TypeToken<?> type, ConfigurationNode from) throws ObjectMappingException {
    if (from.getValue() == null) {
        return JsonNull.INSTANCE;
    }

    if (from.hasListChildren()) {
        List<? extends ConfigurationNode> childrenList = from.getChildrenList();
        JsonArray array = new JsonArray();
        for (ConfigurationNode node : childrenList) {
            array.add(node.getValue(TYPE));
        }
        return array;
    }

    if (from.hasMapChildren()) {
        Map<Object, ? extends ConfigurationNode> childrenMap = from.getChildrenMap();
        JsonObject object = new JsonObject();
        for (Map.Entry<Object, ? extends ConfigurationNode> ent : childrenMap.entrySet()) {
            object.add(ent.getKey().toString(), ent.getValue().getValue(TYPE));
        }
        return object;
    }

    Object val = from.getValue();
    try {
        return GsonConverters.IMMUTABLE.wrap(val);
    } catch (IllegalArgumentException e) {
        throw new ObjectMappingException(e);
    }
}
 
Example 4
Source File: NodeBuilder.java    From ChatUI with MIT License 5 votes vote down vote up
public static NodeBuilder forNode(ConfigurationNode node, ConfigEditTab tab) {
    if (node.hasListChildren()) {
        return new ListNodeBuilder(tab);
    } else if (node.hasMapChildren()) {
        return new NodeBuilder(tab);
    }
    return null;
}
 
Example 5
Source File: ConfigurateConfigAdapter.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public List<String> getKeys(String path, List<String> def) {
    ConfigurationNode node = resolvePath(path);
    if (node.isVirtual() || !node.hasMapChildren()) {
        return def;
    }

    return node.getChildrenMap().keySet().stream().map(Object::toString).collect(Collectors.toList());
}
 
Example 6
Source File: SecurityService.java    From Web-API with MIT License 5 votes vote down vote up
/**
 * Returns a permissions tree representing the passed configuration node
 * @param config The configuration node which represents a permission set
 * @return A tree structure representing the config node
 */
public static TreeNode permissionTreeFromConfig(ConfigurationNode config) {
    if (config == null || config.getValue() == null) {
        return new TreeNode(false);
    }

    if (!config.hasMapChildren()) {
        if (config.getValue().getClass() == Boolean.class)
            return new TreeNode(config.getKey().toString(), config.getBoolean());
        else {
            TreeNode node = new TreeNode(config.getKey().toString(), true);
            node.addChild(new TreeNode("*", true));
            return node;
        }
    }

    TreeNode root = new TreeNode(config.getKey().toString(), true);
    for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) {
        if (entry.getKey().toString().equalsIgnoreCase(".")) {
            root.setValue(entry.getValue().getBoolean());
            continue;
        }

        root.addChild(permissionTreeFromConfig(entry.getValue()));
    }
    return root;
}