use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class AbstractConfigurateStorage method readNodes.
protected static Set<Node> readNodes(ConfigurationNode data) {
Set<Node> nodes = new HashSet<>();
for (ConfigurationNode appended : data.getNode("permissions").getChildrenList()) {
String plainValue = appended.getValue(Types::strictAsString);
if (plainValue != null && !plainValue.isEmpty()) {
nodes.add(NodeBuilders.determineMostApplicable(plainValue).build());
continue;
}
NodeEntry entry = parseNode(appended, "permission");
if (entry == null || entry.key.isEmpty()) {
continue;
}
nodes.add(readAttributes(NodeBuilders.determineMostApplicable(entry.key).value(entry.attributes.getNode("value").getBoolean(true)), entry.attributes));
}
for (ConfigurationNode appended : data.getNode("parents").getChildrenList()) {
String plainValue = appended.getValue(Types::strictAsString);
if (plainValue != null) {
nodes.add(Inheritance.builder(plainValue).build());
continue;
}
NodeEntry entry = parseNode(appended, "group");
if (entry == null || entry.key.isEmpty()) {
continue;
}
nodes.add(readAttributes(Inheritance.builder(entry.key), entry.attributes));
}
for (ConfigurationNode appended : data.getNode("prefixes").getChildrenList()) {
NodeEntry entry = parseNode(appended, "prefix");
if (entry == null) {
continue;
}
nodes.add(readAttributes(Prefix.builder(entry.key, entry.attributes.getNode("priority").getInt(0)), entry.attributes));
}
for (ConfigurationNode appended : data.getNode("suffixes").getChildrenList()) {
NodeEntry entry = parseNode(appended, "suffix");
if (entry == null) {
continue;
}
nodes.add(readAttributes(Suffix.builder(entry.key, entry.attributes.getNode("priority").getInt(0)), entry.attributes));
}
for (ConfigurationNode appended : data.getNode("meta").getChildrenList()) {
NodeEntry entry = parseNode(appended, "key");
if (entry == null || entry.key.isEmpty()) {
continue;
}
nodes.add(readAttributes(Meta.builder(entry.key, entry.attributes.getNode("value").getString("null")), entry.attributes));
}
return nodes;
}
use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class NodeMapMutable method removeMatchingButNotSame.
private static void removeMatchingButNotSame(Iterator<Node> it, Node node, Difference<Node> result) {
while (it.hasNext()) {
Node el = it.next();
if (el != node && node.equals(el, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE)) {
it.remove();
result.recordChange(ChangeType.REMOVE, el);
}
}
}
use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class NodeMapMutable method removeExact.
@Override
public Difference<Node> removeExact(Node node) {
ImmutableContextSet context = node.getContexts();
Difference<Node> result = new Difference<>();
this.lock.lock();
try {
SortedSet<Node> nodes = this.map.get(context);
if (nodes == null) {
return result;
}
// try to remove an exact match
if (nodes.remove(node)) {
// if we removed something, record to results
result.recordChange(ChangeType.REMOVE, node);
// update inheritance map too if necessary
if (node instanceof InheritanceNode && node.getValue()) {
SortedSet<InheritanceNode> inhNodes = this.inheritanceMap.get(context);
if (inhNodes != null) {
inhNodes.remove(node);
}
}
}
} finally {
this.lock.unlock();
}
return result;
}
use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class NodeMapMutable method removeIf.
@Override
public Difference<Node> removeIf(ContextSet contextSet, Predicate<? super Node> predicate) {
ImmutableContextSet context = contextSet.immutableCopy();
Difference<Node> result = new Difference<>();
this.lock.lock();
try {
SortedSet<Node> nodes = this.map.get(context);
if (nodes == null) {
return result;
}
removeMatching(nodes.iterator(), predicate, result);
} finally {
this.lock.unlock();
}
return result;
}
use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class NodeMapMutable method remove.
@Override
public Difference<Node> remove(Node node) {
ImmutableContextSet context = node.getContexts();
Difference<Node> result = new Difference<>();
this.lock.lock();
try {
SortedSet<Node> nodes = this.map.get(context);
if (nodes == null) {
return result;
}
// remove any nodes that match, record to results
removeMatching(nodes.iterator(), node, result);
// update inheritance map too
if (node instanceof InheritanceNode) {
SortedSet<InheritanceNode> inhNodes = this.inheritanceMap.get(context);
if (inhNodes != null) {
inhNodes.removeIf(el -> node.equals(el, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
}
}
} finally {
this.lock.unlock();
}
return result;
}
Aggregations