use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class AbstractConfigurateStorage method readAttributes.
private static Node readAttributes(NodeBuilder<?, ?> builder, ConfigurationNode attributes) {
long expiryVal = attributes.getNode("expiry").getLong(0L);
Instant expiry = expiryVal == 0L ? null : Instant.ofEpochSecond(expiryVal);
ImmutableContextSet context = readContexts(attributes);
return builder.expiry(expiry).context(context).build();
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class AbstractConfigurateStorage method readContexts.
private static ImmutableContextSet readContexts(ConfigurationNode attributes) {
ImmutableContextSet.Builder contextBuilder = new ImmutableContextSetImpl.BuilderImpl();
ConfigurationNode contextMap = attributes.getNode("context");
if (!contextMap.isVirtual() && contextMap.isMap()) {
contextBuilder.addAll(ContextSetConfigurateSerializer.deserializeContextSet(contextMap));
}
String server = attributes.getNode("server").getString("global");
contextBuilder.add(DefaultContextKeys.SERVER_KEY, server);
String world = attributes.getNode("world").getString("global");
contextBuilder.add(DefaultContextKeys.WORLD_KEY, world);
return contextBuilder.build();
}
use of net.luckperms.api.context.ImmutableContextSet 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.context.ImmutableContextSet 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.context.ImmutableContextSet 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