use of me.lucko.luckperms.api.Node 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.api.Node in project LuckPerms by lucko.
the class WeightCache method supply.
@Override
protected OptionalInt supply() {
boolean seen = false;
int best = 0;
for (Node n : this.group.getOwnNodes(ImmutableContextSet.empty())) {
Integer weight = NodeFactory.parseWeightNode(n.getPermission());
if (weight == null) {
continue;
}
if (!seen || weight > best) {
seen = true;
best = weight;
}
}
OptionalInt weight = seen ? OptionalInt.of(best) : OptionalInt.empty();
if (!weight.isPresent()) {
Map<String, Integer> configWeights = this.group.getPlugin().getConfiguration().get(ConfigKeys.GROUP_WEIGHTS);
Integer w = configWeights.get(this.group.getObjectName().toLowerCase());
if (w != null) {
weight = OptionalInt.of(w);
}
}
return weight;
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class HolderSubjectData method getAllOptions.
@Override
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, String>> getAllOptions() {
Map<ImmutableContextSet, Map<String, String>> options = new HashMap<>();
Map<ImmutableContextSet, Integer> minPrefixPriority = new HashMap<>();
Map<ImmutableContextSet, Integer> minSuffixPriority = new HashMap<>();
for (Node n : this.holder.getNodes(this.type).values()) {
if (!n.getValuePrimitive())
continue;
if (!n.isMeta() && !n.isPrefix() && !n.isSuffix())
continue;
ImmutableContextSet immutableContexts = n.getFullContexts().makeImmutable();
if (!options.containsKey(immutableContexts)) {
options.put(immutableContexts, new HashMap<>());
minPrefixPriority.put(immutableContexts, Integer.MIN_VALUE);
minSuffixPriority.put(immutableContexts, Integer.MIN_VALUE);
}
if (n.isPrefix()) {
Map.Entry<Integer, String> value = n.getPrefix();
if (value.getKey() > minPrefixPriority.get(immutableContexts)) {
options.get(immutableContexts).put(NodeFactory.PREFIX_KEY, value.getValue());
minPrefixPriority.put(immutableContexts, value.getKey());
}
continue;
}
if (n.isSuffix()) {
Map.Entry<Integer, String> value = n.getSuffix();
if (value.getKey() > minSuffixPriority.get(immutableContexts)) {
options.get(immutableContexts).put(NodeFactory.SUFFIX_KEY, value.getValue());
minSuffixPriority.put(immutableContexts, value.getKey());
}
continue;
}
if (n.isMeta()) {
Map.Entry<String, String> meta = n.getMeta();
options.get(immutableContexts).put(meta.getKey(), meta.getValue());
}
}
ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, String>> map = ImmutableMap.builder();
for (Map.Entry<ImmutableContextSet, Map<String, String>> e : options.entrySet()) {
map.put(e.getKey(), ImmutableMap.copyOf(e.getValue()));
}
return map.build();
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class HolderSubjectData method setPermission.
@Override
public CompletableFuture<Boolean> setPermission(ImmutableContextSet contexts, String permission, Tristate tristate) {
Objects.requireNonNull(contexts, "contexts");
Objects.requireNonNull(permission, "permission");
Objects.requireNonNull(tristate, "tristate");
if (tristate == Tristate.UNDEFINED) {
// Unset
Node node = NodeFactory.builder(permission).withExtraContext(contexts).build();
this.type.run(() -> this.holder.unsetPermission(node), () -> this.holder.unsetTransientPermission(node));
return objectSave(this.holder).thenApply(v -> true);
}
Node node = NodeFactory.builder(permission).setValue(tristate.asBoolean()).withExtraContext(contexts).build();
this.type.run(() -> {
// unset the inverse, to allow false -> true, true -> false overrides.
this.holder.unsetPermission(node);
this.holder.setPermission(node);
}, () -> {
// unset the inverse, to allow false -> true, true -> false overrides.
this.holder.unsetTransientPermission(node);
this.holder.setTransientPermission(node);
});
return objectSave(this.holder).thenApply(v -> true);
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class SearchCommand method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> " + (perm.asNode().getValuePrimitive() ? "&a" : "&c") + perm.asNode().getPermission(), " ", "&7Click to remove this node from " + holderName), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
Aggregations