Fix issue with permissions sometimes not being removed

This commit is contained in:
Luck 2016-10-02 10:33:58 +01:00
parent c88600adda
commit 18e126b781
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -111,31 +111,28 @@ public abstract class PermissionHolder {
* @return true if permissions had expired and were removed * @return true if permissions had expired and were removed
*/ */
public boolean auditTemporaryPermissions() { public boolean auditTemporaryPermissions() {
boolean work = false; final boolean[] work = {false};
final PermissionHolder instance = this;
Iterator<Node> iterator = nodes.iterator(); nodes.removeIf(node -> {
while (iterator.hasNext()) { if (node.hasExpired()) {
Node element = iterator.next(); work[0] = true;
if (element.hasExpired()) { plugin.getApiProvider().fireEventAsync(new PermissionNodeExpireEvent(new PermissionHolderLink(instance), node));
iterator.remove(); return true;
work = true;
plugin.getApiProvider().fireEventAsync(new PermissionNodeExpireEvent(new PermissionHolderLink(this), element));
}
} }
return false;
});
Iterator<Node> iterator2 = transientNodes.iterator(); transientNodes.removeIf(node -> {
while (iterator2.hasNext()) { if (node.hasExpired()) {
Node element = iterator2.next(); work[0] = true;
if (element.hasExpired()) { plugin.getApiProvider().fireEventAsync(new PermissionNodeExpireEvent(new PermissionHolderLink(instance), node));
iterator2.remove(); return true;
work = true;
plugin.getApiProvider().fireEventAsync(new PermissionNodeExpireEvent(new PermissionHolderLink(this), element));
}
} }
return false;
});
return work; return work[0];
} }
/** /**
@ -163,25 +160,11 @@ public abstract class PermissionHolder {
contexts.remove("server"); contexts.remove("server");
contexts.remove("world"); contexts.remove("world");
Iterator<Node> iterator = parents.iterator(); parents.removeIf(node ->
while (iterator.hasNext()) { !node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) ||
Node node = iterator.next(); !node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyWithContext(contexts, false)
if (!node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex())) { );
iterator.remove();
continue;
}
if (!node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex())) {
iterator.remove();
continue;
}
if (!node.shouldApplyWithContext(contexts, false)) {
iterator.remove();
continue;
}
}
for (Node parent : parents) { for (Node parent : parents) {
Group group = plugin.getGroupManager().get(parent.getGroupName()); Group group = plugin.getGroupManager().get(parent.getGroupName());
@ -488,13 +471,7 @@ public abstract class PermissionHolder {
throw new ObjectLacksException(); throw new ObjectLacksException();
} }
Iterator<Node> iterator = nodes.iterator(); nodes.removeIf(e -> e.almostEquals(node));
while (iterator.hasNext()) {
Node entry = iterator.next();
if (entry.almostEquals(node)) {
iterator.remove();
}
}
if (node.isGroupNode()) { if (node.isGroupNode()) {
plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderLink(this), plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderLink(this),
@ -514,13 +491,7 @@ public abstract class PermissionHolder {
throw new ObjectLacksException(); throw new ObjectLacksException();
} }
Iterator<Node> iterator = transientNodes.iterator(); transientNodes.removeIf(e -> e.almostEquals(node));
while (iterator.hasNext()) {
Node entry = iterator.next();
if (entry.almostEquals(node)) {
iterator.remove();
}
}
if (node.isGroupNode()) { if (node.isGroupNode()) {
plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderLink(this), plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderLink(this),