From ce42573f4336c72b375008881ec6bf1ba3eda76b Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 15 Jan 2017 17:47:59 +0000 Subject: [PATCH] Properly invalidate user caches when defaults chance - fixes #118 --- .../luckperms/sponge/model/SpongeGroup.java | 10 ++++---- .../sponge/service/LuckPermsService.java | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java index 887f8b07..f546ac93 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java @@ -117,10 +117,12 @@ public class SpongeGroup extends Group { this.subjectData = new LuckPermsSubjectData(true, plugin.getService(), parent, this); this.transientSubjectData = new LuckPermsSubjectData(false, plugin.getService(), parent, this); - parent.getStateListeners().add(() -> { - permissionCache.invalidateAll(); - parentCache.invalidateAll(); - }); + parent.getStateListeners().add(this::invalidateCaches); + } + + public void invalidateCaches() { + permissionCache.invalidateAll(); + parentCache.invalidateAll(); } @Override diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java index d6b8e69e..063912ea 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java @@ -43,11 +43,14 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.common.caching.UserCache; +import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink; import me.lucko.luckperms.sponge.managers.SpongeGroupManager; import me.lucko.luckperms.sponge.managers.SpongeUserManager; +import me.lucko.luckperms.sponge.model.SpongeGroup; import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.base.LPSubjectCollection; import me.lucko.luckperms.sponge.service.base.LPSubjectData; @@ -225,6 +228,19 @@ public class LuckPermsService implements PermissionService { for (CalculatedSubjectData subjectData : localDataCaches) { subjectData.invalidateLookupCache(); } + + plugin.getCalculatorFactory().invalidateAll(); + + for (User user : plugin.getUserManager().getAll().values()) { + UserCache userCache = user.getUserData(); + if (userCache == null) continue; + + userCache.invalidateCache(); + } + + for (SpongeGroup group : plugin.getGroupManager().getAll().values()) { + group.getSpongeData().invalidateCaches(); + } } public void invalidateParentCaches() { @@ -239,6 +255,13 @@ public class LuckPermsService implements PermissionService { for (LoadingCache> c : localOptionCaches) { c.invalidateAll(); } + + for (User user : plugin.getUserManager().getAll().values()) { + UserCache userCache = user.getUserData(); + if (userCache == null) continue; + + userCache.invalidateCache(); + } } @RequiredArgsConstructor