mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Ensure holder state is always declared
This commit is contained in:
parent
257f426ab9
commit
6760a96527
@ -119,7 +119,11 @@ public class CachedStateManager {
|
||||
|
||||
public void invalidateInheritances(HolderReference holder) {
|
||||
Set<HolderReference> toInvalidate = getInheritances(holder);
|
||||
toInvalidate.forEach(hr -> hr.apply(plugin, INVALIDATE_CONSUMER));
|
||||
invalidateInheritances(plugin, toInvalidate);
|
||||
}
|
||||
|
||||
public static void invalidateInheritances(LuckPermsPlugin plugin, Set<HolderReference> references) {
|
||||
references.forEach(hr -> hr.apply(plugin, INVALIDATE_CONSUMER));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,9 @@
|
||||
package me.lucko.luckperms.common.caching.handlers;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
@ -32,6 +34,8 @@ import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class GroupReference implements HolderReference<String> {
|
||||
|
||||
|
@ -23,7 +23,9 @@
|
||||
package me.lucko.luckperms.common.caching.handlers;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.core.UserIdentifier;
|
||||
@ -33,6 +35,8 @@ import me.lucko.luckperms.common.core.model.User;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class UserReference implements HolderReference<UserIdentifier> {
|
||||
private final UserIdentifier id;
|
||||
|
@ -48,6 +48,8 @@ import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.api.internal.GroupLink;
|
||||
import me.lucko.luckperms.common.api.internal.PermissionHolderLink;
|
||||
import me.lucko.luckperms.common.caching.MetaHolder;
|
||||
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
|
||||
import me.lucko.luckperms.common.caching.handlers.GroupReference;
|
||||
import me.lucko.luckperms.common.caching.handlers.HolderReference;
|
||||
import me.lucko.luckperms.common.caching.holder.ExportNodesHolder;
|
||||
import me.lucko.luckperms.common.caching.holder.GetAllNodesHolder;
|
||||
@ -169,8 +171,23 @@ public abstract class PermissionHolder {
|
||||
}
|
||||
cache.invalidate();
|
||||
mergedCache.invalidate();
|
||||
invalidateInheritanceCaches();
|
||||
plugin.getCachedStateManager().invalidateInheritances(toReference());
|
||||
|
||||
// Invalidate inheritance caches
|
||||
getAllNodesCache.invalidateAll();
|
||||
getAllNodesFilteredCache.invalidateAll();
|
||||
exportNodesCache.invalidateAll();
|
||||
|
||||
// Get previous references
|
||||
Set<HolderReference> refs = plugin.getCachedStateManager().getInheritances(toReference());
|
||||
|
||||
// Declare new state to the state manager
|
||||
declareState();
|
||||
|
||||
// Add all new references affected by the state change.
|
||||
refs.addAll(plugin.getCachedStateManager().getInheritances(toReference()));
|
||||
|
||||
// Invalidate all affected children.
|
||||
CachedStateManager.invalidateInheritances(plugin, refs);
|
||||
}
|
||||
|
||||
private ImmutableSortedSet<LocalizedNode> cacheApply() {
|
||||
@ -241,12 +258,6 @@ public abstract class PermissionHolder {
|
||||
return ImmutableSortedSet.copyOfSorted(combined);
|
||||
}
|
||||
|
||||
public void invalidateInheritanceCaches() {
|
||||
getAllNodesCache.invalidateAll();
|
||||
getAllNodesFilteredCache.invalidateAll();
|
||||
exportNodesCache.invalidateAll();
|
||||
}
|
||||
|
||||
private SortedSet<LocalizedNode> getAllNodesCacheApply(GetAllNodesHolder getAllNodesHolder) {
|
||||
List<String> excludedGroups = new ArrayList<>(getAllNodesHolder.getExcludedGroups());
|
||||
ExtractedContexts contexts = getAllNodesHolder.getContexts();
|
||||
@ -367,6 +378,9 @@ public abstract class PermissionHolder {
|
||||
return ImmutableMap.copyOf(perms);
|
||||
}
|
||||
|
||||
protected void declareState() {
|
||||
plugin.getCachedStateManager().putAll(toReference(), getGroupReferences());
|
||||
}
|
||||
|
||||
public abstract String getFriendlyName();
|
||||
public abstract HolderReference<?> toReference();
|
||||
@ -1048,6 +1062,15 @@ public abstract class PermissionHolder {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Set<HolderReference> getGroupReferences() {
|
||||
return getNodes().stream()
|
||||
.filter(Node::isGroupNode)
|
||||
.map(Node::getGroupName)
|
||||
.map(String::toLowerCase)
|
||||
.map(GroupReference::of)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link List} of the groups the holder inherits on a specific server and world
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user