use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.
the class AllParentsByWeightHolder method calculateValue.
@Override
protected String calculateValue() {
Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
if (contexts == null) {
contexts = this.user.getPlugin().getContextManager().getStaticContexts();
}
InheritanceGraph graph = this.user.getPlugin().getInheritanceHandler().getGraph(contexts);
// fully traverse the graph, obtain a list of permission holders the user inherits from
List<PermissionHolder> traversal = ImmutableList.copyOf(graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this.user));
Group bestGroup = null;
if (!traversal.isEmpty()) {
int best = 0;
for (PermissionHolder holder : traversal) {
if (!(holder instanceof Group)) {
continue;
}
Group g = ((Group) holder);
int weight = g.getWeight().orElse(0);
if (bestGroup == null || g.getWeight().orElse(0) > best) {
bestGroup = g;
best = weight;
}
}
}
return bestGroup == null ? null : bestGroup.getName();
}
use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.
the class PermissionHolder method accumulateInheritancesTo.
private void accumulateInheritancesTo(List<LocalizedNode> accumulator, Contexts context) {
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(context);
Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
for (PermissionHolder holder : traversal) {
List<Node> nodes = holder.getOwnNodes(context.getContexts());
for (Node node : nodes) {
ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(node, holder.getObjectName());
accumulator.add(localizedNode);
}
}
}
use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.
the class HolderSubject method getParents.
@Override
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(this.plugin.getContextManager().formContexts(contexts));
Iterable<PermissionHolder> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this.parent);
ImmutableList.Builder<LPSubjectReference> subjects = ImmutableList.builder();
for (PermissionHolder parent : traversal) {
if (!(parent instanceof Group)) {
continue;
}
subjects.add(((SpongeGroup) parent).sponge().toReference());
}
return subjects.build();
}
use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.
the class PermissionHolder method accumulateMeta.
public MetaAccumulator accumulateMeta(MetaAccumulator accumulator, Contexts context) {
if (accumulator == null) {
accumulator = MetaAccumulator.makeFromConfig(this.plugin);
}
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(context);
Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
for (PermissionHolder holder : traversal) {
List<Node> nodes = holder.getOwnNodes(context.getContexts());
for (Node node : nodes) {
if (!node.getValuePrimitive())
continue;
if (!node.isMeta() && !node.isPrefix() && !node.isSuffix())
continue;
if (!((context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER) || node.isServerSpecific()) && (context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD) || node.isWorldSpecific()))) {
continue;
}
accumulator.accumulateNode(ImmutableLocalizedNode.of(node, holder.getObjectName()));
}
OptionalInt w = holder.getWeight();
if (w.isPresent()) {
accumulator.accumulateWeight(w.getAsInt());
}
}
return accumulator;
}
use of me.lucko.luckperms.common.inheritance.InheritanceGraph in project LuckPerms by lucko.
the class PermissionHolder method accumulateInheritancesTo.
private void accumulateInheritancesTo(List<LocalizedNode> accumulator) {
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph();
Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
for (PermissionHolder holder : traversal) {
List<Node> nodes = holder.getOwnNodes();
for (Node node : nodes) {
ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(node, holder.getObjectName());
accumulator.add(localizedNode);
}
}
}
Aggregations