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;
}
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;
}
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;
}
Aggregations