Search in sources :

Example 1 with MutableContextSetImpl

use of me.lucko.luckperms.common.context.MutableContextSetImpl in project LuckPerms by lucko.

the class ContextSetJsonSerializer method deserialize.

public static ContextSet deserialize(JsonElement element) {
    Preconditions.checkArgument(element.isJsonObject());
    JsonObject jsonObject = element.getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entries = jsonObject.entrySet();
    if (entries.isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }
    MutableContextSet contextSet = new MutableContextSetImpl();
    for (Map.Entry<String, JsonElement> entry : entries) {
        String k = entry.getKey();
        JsonElement v = entry.getValue();
        if (v.isJsonArray()) {
            JsonArray values = v.getAsJsonArray();
            for (JsonElement value : values) {
                contextSet.add(k, value.getAsString());
            }
        } else {
            contextSet.add(k, v.getAsString());
        }
    }
    return contextSet;
}
Also used : JsonArray(com.google.gson.JsonArray) MutableContextSet(net.luckperms.api.context.MutableContextSet) JsonElement(com.google.gson.JsonElement) MutableContextSetImpl(me.lucko.luckperms.common.context.MutableContextSetImpl) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 2 with MutableContextSetImpl

use of me.lucko.luckperms.common.context.MutableContextSetImpl in project LuckPerms by lucko.

the class ArgumentList method parseContext.

private MutableContextSet parseContext(int fromIndex) {
    MutableContextSet contextSet = new MutableContextSetImpl();
    List<String> entries = subList(fromIndex, size());
    for (int i = 0; i < entries.size(); i++) {
        String entry = entries.get(i);
        int sep = entry.indexOf('=');
        String key;
        String value;
        if (sep != -1) {
            key = entry.substring(0, sep);
            value = entry.substring(sep + 1);
        } else {
            key = i == 1 ? DefaultContextKeys.WORLD_KEY : DefaultContextKeys.SERVER_KEY;
            value = entry;
        }
        if (!Context.isValidKey(key) || !Context.isValidValue(value)) {
            continue;
        }
        contextSet.add(key, value);
    }
    return contextSet;
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) MutableContextSetImpl(me.lucko.luckperms.common.context.MutableContextSetImpl)

Example 3 with MutableContextSetImpl

use of me.lucko.luckperms.common.context.MutableContextSetImpl in project LuckPerms by lucko.

the class ContextSetConfigurateSerializer method deserializeContextSet.

public static ContextSet deserializeContextSet(ConfigurationNode data) {
    Preconditions.checkArgument(data.isMap());
    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.isList()) {
            for (ConfigurationNode value : v.getChildrenList()) {
                map.add(k, value.getString());
            }
        } else {
            map.add(k, v.getString());
        }
    }
    return map;
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) MutableContextSet(net.luckperms.api.context.MutableContextSet) MutableContextSetImpl(me.lucko.luckperms.common.context.MutableContextSetImpl) Map(java.util.Map)

Aggregations

MutableContextSetImpl (me.lucko.luckperms.common.context.MutableContextSetImpl)3 MutableContextSet (net.luckperms.api.context.MutableContextSet)3 Map (java.util.Map)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)1