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

The following examples show how to use ninja.leaping.configurate.ConfigurationNode#hasListChildren() . 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: ConfigUtils.java    From BlueMap with MIT License 6 votes vote down vote up
public static Vector3i readVector3i(ConfigurationNode vectorNode){
	if (vectorNode.hasListChildren()){
		List<? extends ConfigurationNode> list = vectorNode.getChildrenList();
		return new Vector3i(
				list.get(0).getInt(),
				list.get(1).getInt(),
				list.get(2).getInt()
			);
	}
	
	return new Vector3i(
			vectorNode.getNode("x").getInt(),
			vectorNode.getNode("y").getInt(),
			vectorNode.getNode("z").getInt()
		);
}
 
Example 2
Source File: ConfigUtils.java    From BlueMap with MIT License 6 votes vote down vote up
public static Vector3f readVector3f(ConfigurationNode vectorNode){
	if (vectorNode.hasListChildren()){
		List<? extends ConfigurationNode> list = vectorNode.getChildrenList();
		return new Vector3f(
				list.get(0).getFloat(),
				list.get(1).getFloat(),
				list.get(2).getFloat()
			);
	}
	
	return new Vector3f(
			vectorNode.getNode("x").getFloat(),
			vectorNode.getNode("y").getFloat(),
			vectorNode.getNode("z").getFloat()
		);
}
 
Example 3
Source File: ConfigUtils.java    From BlueMap with MIT License 6 votes vote down vote up
public static Vector4i readVector4i(ConfigurationNode vectorNode){
	if (vectorNode.hasListChildren()){
		List<? extends ConfigurationNode> list = vectorNode.getChildrenList();
		return new Vector4i(
				list.get(0).getInt(),
				list.get(1).getInt(),
				list.get(2).getInt(),
				list.get(3).getInt()
			);
	}
	
	return new Vector4i(
			vectorNode.getNode("x").getInt(),
			vectorNode.getNode("y").getInt(),
			vectorNode.getNode("z").getInt(),
			vectorNode.getNode("w").getInt()
		);
}
 
Example 4
Source File: ConfigUtils.java    From BlueMap with MIT License 6 votes vote down vote up
public static Vector4f readVector4f(ConfigurationNode vectorNode){
	if (vectorNode.hasListChildren()){
		List<? extends ConfigurationNode> list = vectorNode.getChildrenList();
		return new Vector4f(
				list.get(0).getFloat(),
				list.get(1).getFloat(),
				list.get(2).getFloat(),
				list.get(3).getFloat()
			);
	}
	
	return new Vector4f(
			vectorNode.getNode("x").getFloat(),
			vectorNode.getNode("y").getFloat(),
			vectorNode.getNode("z").getFloat(),
			vectorNode.getNode("w").getFloat()
		);
}
 
Example 5
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 6
Source File: ContextSetConfigurateSerializer.java    From LuckPerms with MIT License 6 votes vote down vote up
public static ContextSet deserializeContextSet(ConfigurationNode data) {
    Preconditions.checkArgument(data.hasMapChildren());
    Map<Object, ? extends ConfigurationNode> dataMap = data.getChildrenMap();

    if (dataMap.isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }

    MutableContextSet map = new MutableContextSetImpl();
    for (Map.Entry<Object, ? extends ConfigurationNode> e : dataMap.entrySet()) {
        String k = e.getKey().toString();
        ConfigurationNode v = e.getValue();

        if (v.hasListChildren()) {
            List<? extends ConfigurationNode> values = v.getChildrenList();
            for (ConfigurationNode value : values) {
                map.add(k, value.getString());
            }
        } else {
            map.add(k, v.getString());
        }
    }

    return map;
}
 
Example 7
Source File: BlockStateResource.java    From BlueMap with MIT License 5 votes vote down vote up
private boolean isForgeStraightVariant(ConfigurationNode node) {
	if (node.hasListChildren())
		return true;

	for (Entry<Object, ? extends ConfigurationNode> entry : node.getChildrenMap().entrySet()) {
		if (entry.getKey().equals(JSON_COMMENT)) continue;
		if (!entry.getValue().hasMapChildren()) return true;
	}

	return false;
}
 
Example 8
Source File: ConfigUtils.java    From BlueMap with MIT License 5 votes vote down vote up
public static Vector2i readVector2i(ConfigurationNode vectorNode){
	if (vectorNode.hasListChildren()){
		List<? extends ConfigurationNode> list = vectorNode.getChildrenList();
		return new Vector2i(
				list.get(0).getInt(),
				list.get(1).getInt()
			);
	}
	
	return new Vector2i(
			vectorNode.getNode("x").getInt(),
			vectorNode.getNode("y").getInt()
		);
}
 
Example 9
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 10
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 11
Source File: ConfigurateConfigAdapter.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public List<String> getStringList(String path, List<String> def) {
    ConfigurationNode node = resolvePath(path);
    if (node.isVirtual() || !node.hasListChildren()) {
        return def;
    }

    return node.getList(Object::toString);
}