mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-08 20:09:59 +01:00
Invalidate all user/group caches after node changes are made to groups via the API
This commit is contained in:
parent
d3b3a8af38
commit
b2593d409e
@ -82,6 +82,14 @@ public class ApiGroup extends ApiPermissionHolder implements net.luckperms.api.m
|
||||
return this.handle.getCachedData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNodeChange() {
|
||||
// invalidate caches - they have potentially been affected by
|
||||
// this change.
|
||||
this.handle.getPlugin().getGroupManager().invalidateAllGroupCaches();
|
||||
this.handle.getPlugin().getUserManager().invalidateAllUserCaches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
|
@ -75,12 +75,7 @@ public class ApiGroupManager extends ApiAbstractManager<Group, net.luckperms.api
|
||||
@Override
|
||||
public @NonNull CompletableFuture<Void> saveGroup(net.luckperms.api.model.group.@NonNull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.plugin.getStorage().saveGroup(ApiGroup.cast(group)).thenRun(() -> {
|
||||
// invalidate caches - they have potentially been affected by
|
||||
// this change.
|
||||
this.plugin.getGroupManager().invalidateAllGroupCaches();
|
||||
this.plugin.getUserManager().invalidateAllUserCaches();
|
||||
});
|
||||
return this.plugin.getStorage().saveGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,12 +85,7 @@ public class ApiGroupManager extends ApiAbstractManager<Group, net.luckperms.api
|
||||
throw new IllegalArgumentException("Cannot delete the default group.");
|
||||
}
|
||||
|
||||
return this.plugin.getStorage().deleteGroup(ApiGroup.cast(group), DeletionCause.API).thenRun(() -> {
|
||||
// invalidate caches - they have potentially been affected by
|
||||
// this change.
|
||||
this.plugin.getGroupManager().invalidateAllGroupCaches();
|
||||
this.plugin.getUserManager().invalidateAllUserCaches();
|
||||
});
|
||||
return this.plugin.getStorage().deleteGroup(ApiGroup.cast(group), DeletionCause.API);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +65,12 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
protected void onNodeChange() {
|
||||
// overridden by groups
|
||||
// when a node is changed on a group, it could potentially affect other groups/users,
|
||||
// so their caches need to be invalidated too. we handle this automatically for API users.
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Identifier getIdentifier() {
|
||||
return this.handle.getIdentifier();
|
||||
@ -151,38 +157,58 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
|
||||
|
||||
@Override
|
||||
public @NonNull DataMutateResult add(@NonNull Node node) {
|
||||
return ApiPermissionHolder.this.handle.setNode(this.dataType, node, true);
|
||||
DataMutateResult result = ApiPermissionHolder.this.handle.setNode(this.dataType, node, true);
|
||||
if (result.wasSuccessful()) {
|
||||
onNodeChange();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult.@NonNull WithMergedNode add(@NonNull Node node, @NonNull TemporaryNodeMergeStrategy temporaryNodeMergeStrategy) {
|
||||
return ApiPermissionHolder.this.handle.setNode(this.dataType, node, temporaryNodeMergeStrategy);
|
||||
DataMutateResult.WithMergedNode result = ApiPermissionHolder.this.handle.setNode(this.dataType, node, temporaryNodeMergeStrategy);
|
||||
if (result.getResult().wasSuccessful()) {
|
||||
onNodeChange();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull DataMutateResult remove(@NonNull Node node) {
|
||||
return ApiPermissionHolder.this.handle.unsetNode(this.dataType, node);
|
||||
DataMutateResult result = ApiPermissionHolder.this.handle.unsetNode(this.dataType, node);
|
||||
if (result.wasSuccessful()) {
|
||||
onNodeChange();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
ApiPermissionHolder.this.handle.clearNodes(this.dataType, null, true);
|
||||
if (ApiPermissionHolder.this.handle.clearNodes(this.dataType, null, true)) {
|
||||
onNodeChange();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(@NonNull Predicate<? super Node> test) {
|
||||
ApiPermissionHolder.this.handle.removeIf(this.dataType, null, test, true);
|
||||
if (ApiPermissionHolder.this.handle.removeIf(this.dataType, null, test, true)) {
|
||||
onNodeChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear(@NonNull ContextSet contextSet) {
|
||||
ApiPermissionHolder.this.handle.clearNodes(this.dataType, contextSet, true);
|
||||
if (ApiPermissionHolder.this.handle.clearNodes(this.dataType, contextSet, true)) {
|
||||
onNodeChange();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(@NonNull ContextSet contextSet, @NonNull Predicate<? super Node> test) {
|
||||
ApiPermissionHolder.this.handle.removeIf(this.dataType, contextSet, test, true);
|
||||
if (ApiPermissionHolder.this.handle.removeIf(this.dataType, contextSet, test, true)) {
|
||||
onNodeChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user