use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class SubjectDataContainer method serialize.
/**
* Converts this container to json
*
* @return a json serialisation of the data in this container
*/
public JsonObject serialize() {
JsonObject root = new JsonObject();
JsonArray permissions = new JsonArray();
for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> e : sortContextMap(this.permissions)) {
if (e.getValue().isEmpty()) {
continue;
}
JsonObject section = new JsonObject();
section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
JsonObject data = new JsonObject();
// sort alphabetically.
List<Map.Entry<String, Boolean>> perms = new ArrayList<>(e.getValue().entrySet());
perms.sort(Map.Entry.comparingByKey(CollationKeyCache.comparator()));
for (Map.Entry<String, Boolean> ent : perms) {
data.addProperty(ent.getKey(), ent.getValue());
}
section.add("data", data);
permissions.add(section);
}
root.add("permissions", permissions);
JsonArray options = new JsonArray();
for (Map.Entry<ImmutableContextSet, Map<String, String>> e : sortContextMap(this.options)) {
if (e.getValue().isEmpty()) {
continue;
}
JsonObject section = new JsonObject();
section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
JsonObject data = new JsonObject();
// sort alphabetically.
List<Map.Entry<String, String>> opts = new ArrayList<>(e.getValue().entrySet());
opts.sort(Map.Entry.comparingByKey(CollationKeyCache.comparator()));
for (Map.Entry<String, String> ent : opts) {
data.addProperty(ent.getKey(), ent.getValue());
}
section.add("data", data);
options.add(section);
}
root.add("options", options);
JsonArray parents = new JsonArray();
for (Map.Entry<ImmutableContextSet, List<LPSubjectReference>> e : sortContextMap(this.parents)) {
if (e.getValue().isEmpty()) {
continue;
}
JsonObject section = new JsonObject();
section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
JsonArray data = new JsonArray();
for (LPSubjectReference ref : e.getValue()) {
JsonObject parent = new JsonObject();
parent.addProperty("collection", ref.getCollectionIdentifier());
parent.addProperty("subject", ref.getSubjectIdentifier());
data.add(parent);
}
section.add("data", data);
options.add(section);
}
root.add("parents", parents);
return root;
}
use of me.lucko.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class CalculatedSubjectData method resolveParents.
public Set<LPSubjectReference> resolveParents(ContextSet filter) {
// get relevant entries
SortedMap<ImmutableContextSet, Set<LPSubjectReference>> sorted = new TreeMap<>(ContextSetComparator.reverse());
for (Map.Entry<ImmutableContextSet, Set<LPSubjectReference>> entry : this.parents.entrySet()) {
if (!entry.getKey().isSatisfiedBy(filter)) {
continue;
}
sorted.put(entry.getKey(), entry.getValue());
}
// flatten
Set<LPSubjectReference> result = new LinkedHashSet<>();
for (Set<LPSubjectReference> set : sorted.values()) {
for (LPSubjectReference e : set) {
if (!result.contains(e)) {
result.add(e);
}
}
}
return result;
}
Aggregations