use of me.lucko.luckperms.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.
the class CalculatedSubject method getCombinedParents.
public Set<LPSubjectReference> getCombinedParents(ContextSet filter) {
Set<LPSubjectReference> parents;
Set<LPSubjectReference> merging;
switch(getParentCollection().getResolutionOrder()) {
case TRANSIENT_FIRST:
parents = getTransientSubjectData().resolveParents(filter);
merging = getSubjectData().resolveParents(filter);
break;
case TRANSIENT_LAST:
parents = getSubjectData().resolveParents(filter);
merging = getTransientSubjectData().resolveParents(filter);
break;
default:
throw new AssertionError();
}
for (LPSubjectReference entry : merging) {
if (!parents.contains(entry)) {
parents.add(entry);
}
}
return parents;
}
use of me.lucko.luckperms.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.
the class ParentInfo method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(0, args);
if (contextSet.isEmpty()) {
MessageUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a.");
Map<ImmutableContextSet, ImmutableList<LPSubjectReference>> parents = subjectData.getAllParents();
if (parents.isEmpty()) {
MessageUtils.sendPluginMessage(sender, "That subject does not have any parents defined.");
return CommandResult.SUCCESS;
}
for (Map.Entry<ImmutableContextSet, ImmutableList<LPSubjectReference>> e : parents.entrySet()) {
MessageUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
}
} else {
List<LPSubjectReference> parents = subjectData.getParents(contextSet);
if (parents.isEmpty()) {
MessageUtils.sendPluginMessage(sender, "That subject does not have any parents defined in those contexts.");
return CommandResult.SUCCESS;
}
MessageUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.parentsToString(parents));
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.
the class HolderSubjectData method getAllParents.
@Override
public ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents() {
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<LPSubjectReference>> ret = ImmutableMap.builder();
for (Map.Entry<ImmutableContextSet, Collection<Node>> entry : this.holder.getNodes(this.type).asMap().entrySet()) {
ImmutableList.Builder<LPSubjectReference> builder = ImmutableList.builder();
for (Node n : entry.getValue()) {
if (n.isGroupNode()) {
builder.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
}
}
ret.put(entry.getKey(), builder.build());
}
return ret.build();
}
use of me.lucko.luckperms.sponge.service.model.LPSubjectReference 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.sponge.service.model.LPSubjectReference in project LuckPerms by lucko.
the class CalculatedSubject method resolveAllParents.
public Set<LPSubjectReference> resolveAllParents() {
SubjectInheritanceGraph graph = SubjectInheritanceGraphs.getGraph();
Set<LPSubjectReference> result = new LinkedHashSet<>();
Iterable<CalculatedSubject> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this);
for (CalculatedSubject subject : traversal) {
for (LPSubjectReference entry : subject.getCombinedParents()) {
if (!result.contains(entry)) {
result.add(entry);
}
}
}
return result;
}
Aggregations