diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroup.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroup.java index 83e4f53f7..5441d4238 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroup.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroupManager.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroupManager.java index 3e660e9a3..ceafcfccf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroupManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiGroupManager.java @@ -75,12 +75,7 @@ public class ApiGroupManager extends ApiAbstractManager 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 { - // 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java index 0ad8ca085..ddb158328 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java @@ -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 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 test) { - ApiPermissionHolder.this.handle.removeIf(this.dataType, contextSet, test, true); + if (ApiPermissionHolder.this.handle.removeIf(this.dataType, contextSet, test, true)) { + onNodeChange(); + } } }