use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class PermissionClear method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
ImmutableContextSet contextSet = args.getContextOrEmpty(0);
if (contextSet.isEmpty()) {
subjectData.clearPermissions();
SpongeCommandUtils.sendPrefixed(sender, "&aCleared permissions matching contexts &bANY&a.");
} else {
subjectData.clearPermissions(contextSet);
SpongeCommandUtils.sendPrefixed(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
}
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class CalculatedSubjectData method resolvePermissions.
public Map<String, Node> resolvePermissions(QueryOptions filter) {
// get relevant entries
SortedMap<ImmutableContextSet, Map<String, Node>> sorted = new TreeMap<>(ContextSetComparator.reverse());
for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> entry : this.permissions.entrySet()) {
if (!filter.satisfies(entry.getKey(), defaultSatisfyMode())) {
continue;
}
Map<String, Node> nodeMap = new HashMap<>();
entry.getValue().forEach((key, value) -> {
PermissionNode node = Permission.builder().permission(key).value(value).context(entry.getKey()).withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin).build();
nodeMap.put(key, node);
});
sorted.put(entry.getKey(), nodeMap);
}
// flatten
Map<String, Node> result = new HashMap<>();
for (Map<String, Node> map : sorted.values()) {
for (Map.Entry<String, Node> e : map.entrySet()) {
result.putIfAbsent(e.getKey(), e.getValue());
}
}
return result;
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class CalculatedSubjectData method resolveOptions.
public Map<String, MetaNode> resolveOptions(QueryOptions filter) {
// get relevant entries
SortedMap<ImmutableContextSet, Map<String, MetaNode>> sorted = new TreeMap<>(ContextSetComparator.reverse());
for (Map.Entry<ImmutableContextSet, Map<String, String>> entry : this.options.entrySet()) {
if (!filter.satisfies(entry.getKey(), defaultSatisfyMode())) {
continue;
}
Map<String, MetaNode> nodeMap = new HashMap<>();
entry.getValue().forEach((key, value) -> {
MetaNode node = Meta.builder().key(key).value(value).context(entry.getKey()).withMetadata(InheritanceOriginMetadata.KEY, this.inheritanceOrigin).build();
nodeMap.put(key, node);
});
sorted.put(entry.getKey(), nodeMap);
}
// flatten
Map<String, MetaNode> result = new HashMap<>();
for (Map<String, MetaNode> map : sorted.values()) {
for (Map.Entry<String, MetaNode> e : map.entrySet()) {
result.putIfAbsent(e.getKey(), e.getValue());
}
}
return result;
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class PermissionHolderSubjectData method getAllParents.
@Override
public ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents() {
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<LPSubjectReference>> parents = ImmutableMap.builder();
for (Map.Entry<ImmutableContextSet, Collection<InheritanceNode>> entry : this.holder.getData(this.type).inheritanceAsMap().entrySet()) {
ImmutableList.Builder<LPSubjectReference> builder = ImmutableList.builder();
for (InheritanceNode n : entry.getValue()) {
builder.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
}
parents.put(entry.getKey(), builder.build());
}
return parents.build();
}
use of net.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.serialize(e.getKey()));
JsonObject data = new JsonObject();
// sort alphabetically.
List<Map.Entry<String, Boolean>> perms = new ArrayList<>(e.getValue().entrySet());
perms.sort(Map.Entry.comparingByKey());
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.serialize(e.getKey()));
JsonObject data = new JsonObject();
// sort alphabetically.
List<Map.Entry<String, String>> opts = new ArrayList<>(e.getValue().entrySet());
opts.sort(Map.Entry.comparingByKey());
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.serialize(e.getKey()));
JsonArray data = new JsonArray();
for (LPSubjectReference ref : e.getValue()) {
JsonObject parent = new JsonObject();
parent.addProperty("collection", ref.collectionIdentifier());
parent.addProperty("subject", ref.subjectIdentifier());
data.add(parent);
}
section.add("data", data);
options.add(section);
}
root.add("parents", parents);
return root;
}
Aggregations