use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class PermissionHolder method exportNodesAndShorthand.
public Map<String, Boolean> exportNodesAndShorthand(Contexts context, boolean lowerCase) {
List<LocalizedNode> entries = getAllEntries(context);
Map<String, Boolean> perms = new HashMap<>();
boolean applyShorthand = this.plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND);
for (Node node : entries) {
String perm = lowerCase ? node.getPermission().toLowerCase() : node.getPermission();
if (perms.putIfAbsent(perm, node.getValuePrimitive()) == null) {
if (applyShorthand) {
List<String> shorthand = node.resolveShorthand();
if (!shorthand.isEmpty()) {
for (String s : shorthand) {
perms.putIfAbsent(lowerCase ? s.toLowerCase() : s, node.getValuePrimitive());
}
}
}
}
}
return ImmutableMap.copyOf(perms);
}
use of me.lucko.luckperms.api.Node 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.api.Node 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);
}
}
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class PermissionHolder method getAllEntries.
private List<LocalizedNode> getAllEntries(Contexts context) {
List<LocalizedNode> entries = new LinkedList<>();
if (context.hasSetting(LookupSetting.RESOLVE_INHERITANCE)) {
accumulateInheritancesTo(entries, context);
} else {
for (Node n : getOwnNodes(context.getContexts())) {
ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(n, getObjectName());
entries.add(localizedNode);
}
}
if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER)) {
entries.removeIf(n -> !n.isGroupNode() && !n.isServerSpecific());
}
if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD)) {
entries.removeIf(n -> !n.isGroupNode() && !n.isWorldSpecific());
}
return entries;
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class PermissionHolder method setPermission.
/**
* Sets a permission node, applying a temporary modifier if the node is temporary.
* @param node the node to set
* @param modifier the modifier to use for the operation
* @return the node that was actually set, respective of the modifier
*/
public Map.Entry<DataMutateResult, Node> setPermission(Node node, TemporaryModifier modifier) {
// If the node is temporary, we should take note of the modifier
if (node.isTemporary()) {
if (modifier == TemporaryModifier.ACCUMULATE) {
// Try to accumulate with an existing node
Optional<Node> existing = searchForMatch(NodeMapType.ENDURING, node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE);
// An existing node was found
if (existing.isPresent()) {
Node previous = existing.get();
// Create a new node with the same properties, but add the expiry dates together
Node newNode = node.toBuilder().setExpiry(previous.getExpiryUnixTime() + node.getSecondsTilExpiry()).build();
// Remove the old node & add the new one.
ImmutableCollection<Node> before = getEnduringNodes().values();
this.enduringNodes.replace(newNode, previous);
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeAdd(newNode, this, before, after);
return Maps.immutableEntry(DataMutateResult.SUCCESS, newNode);
}
} else if (modifier == TemporaryModifier.REPLACE) {
// Try to replace an existing node
Optional<Node> existing = searchForMatch(NodeMapType.ENDURING, node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE);
// An existing node was found
if (existing.isPresent()) {
Node previous = existing.get();
// Only replace if the new expiry time is greater than the old one.
if (node.getExpiryUnixTime() > previous.getExpiryUnixTime()) {
ImmutableCollection<Node> before = getEnduringNodes().values();
this.enduringNodes.replace(node, previous);
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
this.plugin.getEventFactory().handleNodeAdd(node, this, before, after);
return Maps.immutableEntry(DataMutateResult.SUCCESS, node);
}
}
}
// DENY behaviour is the default anyways.
}
// Fallback to the normal handling.
return Maps.immutableEntry(setPermission(node), node);
}
Aggregations