use of me.lucko.luckperms.common.util.Difference 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 me.lucko.luckperms.common.util.Difference 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 me.lucko.luckperms.common.util.Difference 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;
}
use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.
the class NodeMapMutable method addAll.
@Override
public Difference<Node> addAll(Iterable<? extends Node> set) {
Difference<Node> result = new Difference<>();
this.lock.lock();
try {
for (Node n : set) {
result.mergeFrom(add(n));
}
} finally {
this.lock.unlock();
}
return result;
}
use of me.lucko.luckperms.common.util.Difference in project LuckPerms by lucko.
the class SqlStorage method saveUser.
@Override
public void saveUser(User user) throws SQLException {
Difference<Node> changes = user.normalData().exportChanges(results -> {
if (this.plugin.getUserManager().isNonDefaultUser(user)) {
return true;
}
// if the only change is adding the default node, we don't need to export
if (results.getChanges().size() == 1) {
Difference.Change<Node> onlyChange = results.getChanges().iterator().next();
return !(onlyChange.type() == Difference.ChangeType.ADD && this.plugin.getUserManager().isDefaultNode(onlyChange.value()));
}
return true;
});
if (changes == null) {
try (Connection c = this.connectionFactory.getConnection()) {
deleteUser(c, user.getUniqueId());
}
return;
}
try (Connection c = this.connectionFactory.getConnection()) {
updateUserPermissions(c, user.getUniqueId(), changes.getAdded(), changes.getRemoved());
insertPlayerData(c, user.getUniqueId(), new SqlPlayerData(user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME), user.getUsername().orElse("null").toLowerCase(Locale.ROOT)));
}
}
Aggregations