mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-01 05:57:51 +01:00
Cleanup LuckPermsSubjectData (fixes #194)
This commit is contained in:
parent
e8c0c43e9d
commit
26afb69a14
@ -203,11 +203,21 @@ public interface Node extends Map.Entry<String, Boolean> {
|
|||||||
boolean hasExpired();
|
boolean hasExpired();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the extra contexts required for this node to apply
|
||||||
|
*
|
||||||
* @return the extra contexts required for this node to apply
|
* @return the extra contexts required for this node to apply
|
||||||
* @since 2.13
|
* @since 2.13
|
||||||
*/
|
*/
|
||||||
ContextSet getContexts();
|
ContextSet getContexts();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same as {@link #getContexts()}, but also includes values for "server" and "world" keys if present.
|
||||||
|
*
|
||||||
|
* @return the full contexts required for this node to apply
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
ContextSet getFullContexts();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this node into a serialized form
|
* Converts this node into a serialized form
|
||||||
*
|
*
|
||||||
|
@ -36,6 +36,7 @@ import me.lucko.luckperms.api.Node;
|
|||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
import me.lucko.luckperms.common.constants.Patterns;
|
import me.lucko.luckperms.common.constants.Patterns;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.utils.ShorthandParser;
|
import me.lucko.luckperms.common.utils.ShorthandParser;
|
||||||
@ -148,6 +149,9 @@ public class ImmutableNode implements Node {
|
|||||||
@Getter
|
@Getter
|
||||||
private final ImmutableContextSet contexts;
|
private final ImmutableContextSet contexts;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final ImmutableContextSet fullContexts;
|
||||||
|
|
||||||
// Cached state
|
// Cached state
|
||||||
private final boolean isGroup;
|
private final boolean isGroup;
|
||||||
private String groupName;
|
private String groupName;
|
||||||
@ -234,6 +238,16 @@ public class ImmutableNode implements Node {
|
|||||||
|
|
||||||
resolvedShorthand = ImmutableList.copyOf(ShorthandParser.parseShorthand(getPermission()));
|
resolvedShorthand = ImmutableList.copyOf(ShorthandParser.parseShorthand(getPermission()));
|
||||||
serializedNode = calculateSerializedNode();
|
serializedNode = calculateSerializedNode();
|
||||||
|
|
||||||
|
MutableContextSet fullContexts = this.contexts.mutableCopy();
|
||||||
|
if (isServerSpecific()) {
|
||||||
|
fullContexts.add("server", this.server);
|
||||||
|
}
|
||||||
|
if (isWorldSpecific()) {
|
||||||
|
fullContexts.add("world", this.world);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fullContexts = fullContexts.makeImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -714,6 +714,12 @@ public abstract class PermissionHolder {
|
|||||||
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
|
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPermissionUnchecked(Node node) {
|
||||||
|
try {
|
||||||
|
setPermission(node);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a permission node, applying a temporary modifier if the node is temporary.
|
* Sets a permission node, applying a temporary modifier if the node is temporary.
|
||||||
* @param node the node to set
|
* @param node the node to set
|
||||||
@ -783,6 +789,12 @@ public abstract class PermissionHolder {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPermissionUnchecked(Node node, TemporaryModifier modifier) {
|
||||||
|
try {
|
||||||
|
setPermission(node, modifier);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a transient permission node
|
* Sets a transient permission node
|
||||||
*
|
*
|
||||||
@ -806,6 +818,12 @@ public abstract class PermissionHolder {
|
|||||||
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
|
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTransientPermissionUnchecked(Node node) {
|
||||||
|
try {
|
||||||
|
setTransientPermission(node);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
public void setPermission(String node, boolean value) throws ObjectAlreadyHasException {
|
public void setPermission(String node, boolean value) throws ObjectAlreadyHasException {
|
||||||
setPermission(buildNode(node).setValue(value).build());
|
setPermission(buildNode(node).setValue(value).build());
|
||||||
}
|
}
|
||||||
@ -852,6 +870,12 @@ public abstract class PermissionHolder {
|
|||||||
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
|
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsetPermissionUnchecked(Node node) {
|
||||||
|
try {
|
||||||
|
unsetPermission(node);
|
||||||
|
} catch (ObjectLacksException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets a transient permission node
|
* Unsets a transient permission node
|
||||||
*
|
*
|
||||||
@ -874,6 +898,12 @@ public abstract class PermissionHolder {
|
|||||||
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
|
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsetTransientPermissionUnchecked(Node node) {
|
||||||
|
try {
|
||||||
|
unsetTransientPermission(node);
|
||||||
|
} catch (ObjectLacksException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
public void unsetPermission(String node, boolean temporary) throws ObjectLacksException {
|
public void unsetPermission(String node, boolean temporary) throws ObjectLacksException {
|
||||||
unsetPermission(buildNode(node).setExpiry(temporary ? 10L : 0L).build());
|
unsetPermission(buildNode(node).setExpiry(temporary ? 10L : 0L).build());
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
|||||||
import me.lucko.luckperms.sponge.messaging.BungeeMessagingService;
|
import me.lucko.luckperms.sponge.messaging.BungeeMessagingService;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.ServiceCacheHousekeepingTask;
|
import me.lucko.luckperms.sponge.service.ServiceCacheHousekeepingTask;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
|
|
||||||
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTimings;
|
import me.lucko.luckperms.sponge.timings.LPTimings;
|
||||||
import me.lucko.luckperms.sponge.utils.VersionData;
|
import me.lucko.luckperms.sponge.utils.VersionData;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import lombok.AllArgsConstructor;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
import me.lucko.luckperms.sponge.service.base.Util;
|
import me.lucko.luckperms.sponge.service.proxy.Util;
|
||||||
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
@ -42,8 +42,8 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
|||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.model.SpongeGroup;
|
import me.lucko.luckperms.sponge.model.SpongeGroup;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
|||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.model.SpongeUser;
|
import me.lucko.luckperms.sponge.model.SpongeUser;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import me.lucko.luckperms.common.core.NodeFactory;
|
|||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.sponge.service.base.Util;
|
import me.lucko.luckperms.sponge.service.proxy.Util;
|
||||||
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
|
@ -39,8 +39,8 @@ import me.lucko.luckperms.common.utils.ExtractedContexts;
|
|||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.base.Util;
|
import me.lucko.luckperms.sponge.service.proxy.Util;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.common.core.model.User;
|
|||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||||
|
@ -54,14 +54,14 @@ import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink;
|
|||||||
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
||||||
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
||||||
import me.lucko.luckperms.sponge.model.SpongeGroup;
|
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;
|
|
||||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
|
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
|
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
|
||||||
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
||||||
import me.lucko.luckperms.sponge.service.persisted.SubjectStorage;
|
import me.lucko.luckperms.sponge.service.persisted.SubjectStorage;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ import me.lucko.luckperms.api.Node;
|
|||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
|
||||||
import me.lucko.luckperms.common.caching.MetaHolder;
|
import me.lucko.luckperms.common.caching.MetaHolder;
|
||||||
import me.lucko.luckperms.common.core.NodeBuilder;
|
import me.lucko.luckperms.common.core.NodeBuilder;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
@ -41,25 +40,23 @@ import me.lucko.luckperms.common.core.model.Group;
|
|||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectData;
|
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||||
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
|
|
||||||
import co.aikar.timings.Timing;
|
import co.aikar.timings.Timing;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@SuppressWarnings({"OptionalGetWithoutIsPresent", "unused"})
|
@SuppressWarnings({"OptionalGetWithoutIsPresent", "unused"})
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -73,33 +70,13 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
@Getter
|
@Getter
|
||||||
LPSubject parentSubject;
|
LPSubject parentSubject;
|
||||||
|
|
||||||
private void objectSave(PermissionHolder t) {
|
|
||||||
if (t instanceof User) {
|
|
||||||
service.getPlugin().getStorage().saveUser(((User) t))
|
|
||||||
.thenRunAsync(() -> ((User) t).getRefreshBuffer().request(), service.getPlugin().getScheduler().getAsyncExecutor());
|
|
||||||
}
|
|
||||||
if (t instanceof Group) {
|
|
||||||
service.getPlugin().getStorage().saveGroup((Group) t)
|
|
||||||
.thenRunAsync(() -> service.getPlugin().getUpdateTaskBuffer().request(), service.getPlugin().getScheduler().getAsyncExecutor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ImmutableContextSet, Map<String, Boolean>> getPermissions() {
|
public Map<ImmutableContextSet, Map<String, Boolean>> getPermissions() {
|
||||||
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_GET_PERMISSIONS)) {
|
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_GET_PERMISSIONS)) {
|
||||||
Map<ImmutableContextSet, Map<String, Boolean>> perms = new HashMap<>();
|
Map<ImmutableContextSet, Map<String, Boolean>> perms = new HashMap<>();
|
||||||
|
|
||||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
||||||
MutableContextSet contexts = MutableContextSet.fromSet(n.getContexts());
|
ContextSet contexts = n.getFullContexts();
|
||||||
|
|
||||||
if (n.isServerSpecific()) {
|
|
||||||
contexts.add(new Context(LuckPermsService.SERVER_CONTEXT, n.getServer().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.isWorldSpecific()) {
|
|
||||||
contexts.add(new Context(Context.WORLD_KEY, n.getWorld().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
perms.computeIfAbsent(contexts.makeImmutable(), cs -> new HashMap<>()).put(n.getPermission(), n.getValue());
|
perms.computeIfAbsent(contexts.makeImmutable(), cs -> new HashMap<>()).put(n.getPermission(), n.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +95,10 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
// Unset
|
// Unset
|
||||||
Node node = new NodeBuilder(permission).withExtraContext(contexts).build();
|
Node node = new NodeBuilder(permission).withExtraContext(contexts).build();
|
||||||
|
|
||||||
try {
|
if (enduring) {
|
||||||
if (enduring) {
|
holder.unsetPermissionUnchecked(node);
|
||||||
holder.unsetPermission(node);
|
} else {
|
||||||
} else {
|
holder.unsetTransientPermissionUnchecked(node);
|
||||||
holder.unsetTransientPermission(node);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
@ -134,22 +108,16 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
Node node = new NodeBuilder(permission).setValue(tristate.asBoolean()).withExtraContext(contexts).build();
|
Node node = new NodeBuilder(permission).setValue(tristate.asBoolean()).withExtraContext(contexts).build();
|
||||||
|
|
||||||
// Workaround: unset the inverse, to allow false -> true, true -> false overrides.
|
// Workaround: unset the inverse, to allow false -> true, true -> false overrides.
|
||||||
try {
|
if (enduring) {
|
||||||
if (enduring) {
|
holder.unsetPermissionUnchecked(node);
|
||||||
holder.unsetPermission(node);
|
} else {
|
||||||
} else {
|
holder.unsetTransientPermissionUnchecked(node);
|
||||||
holder.unsetTransientPermission(node);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (enduring) {
|
||||||
if (enduring) {
|
holder.setPermissionUnchecked(node);
|
||||||
holder.setPermission(node);
|
} else {
|
||||||
} else {
|
holder.setTransientPermissionUnchecked(node);
|
||||||
holder.setTransientPermission(node);
|
|
||||||
}
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
@ -165,41 +133,24 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
} else {
|
} else {
|
||||||
holder.clearTransientNodes();
|
holder.clearTransientNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (holder instanceof User) {
|
||||||
|
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||||
|
}
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean clearPermissions(@NonNull ContextSet c) {
|
public boolean clearPermissions(@NonNull ContextSet set) {
|
||||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PERMISSIONS)) {
|
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PERMISSIONS)) {
|
||||||
List<Node> toRemove = new ArrayList<>();
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
.filter(n -> n.getFullContexts().equals(set))
|
||||||
MutableContextSet contexts = MutableContextSet.fromSet(n.getContexts());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (n.isServerSpecific()) {
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
contexts.add(new Context(LuckPermsService.SERVER_CONTEXT, n.getServer().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.isWorldSpecific()) {
|
|
||||||
contexts.add(new Context(Context.WORLD_KEY, n.getWorld().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contexts.equals(c)) {
|
|
||||||
toRemove.add(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
|
||||||
try {
|
|
||||||
if (enduring) {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} else {
|
|
||||||
holder.unsetTransientPermission(n);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (holder instanceof User) {
|
if (holder instanceof User) {
|
||||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||||
@ -216,20 +167,9 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
Map<ImmutableContextSet, Set<SubjectReference>> parents = new HashMap<>();
|
Map<ImmutableContextSet, Set<SubjectReference>> parents = new HashMap<>();
|
||||||
|
|
||||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
||||||
if (!n.isGroupNode()) {
|
if (!n.isGroupNode()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MutableContextSet contexts = MutableContextSet.fromSet(n.getContexts());
|
|
||||||
|
|
||||||
if (n.isServerSpecific()) {
|
|
||||||
contexts.add(new Context(LuckPermsService.SERVER_CONTEXT, n.getServer().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.isWorldSpecific()) {
|
|
||||||
contexts.add(new Context(Context.WORLD_KEY, n.getWorld().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ContextSet contexts = n.getFullContexts();
|
||||||
parents.computeIfAbsent(contexts.makeImmutable(), cs -> new HashSet<>()).add(service.getGroupSubjects().get(n.getGroupName()).toReference());
|
parents.computeIfAbsent(contexts.makeImmutable(), cs -> new HashSet<>()).add(service.getGroupSubjects().get(n.getGroupName()).toReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,17 +187,14 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||||
LPSubject permsSubject = subject.resolve(service);
|
LPSubject permsSubject = subject.resolve(service);
|
||||||
|
|
||||||
try {
|
if (enduring) {
|
||||||
if (enduring) {
|
holder.setPermissionUnchecked(new NodeBuilder("group." + permsSubject.getIdentifier())
|
||||||
holder.setPermission(new NodeBuilder("group." + permsSubject.getIdentifier())
|
.withExtraContext(contexts)
|
||||||
.withExtraContext(contexts)
|
.build());
|
||||||
.build());
|
} else {
|
||||||
} else {
|
holder.setTransientPermissionUnchecked(new NodeBuilder("group." + permsSubject.getIdentifier())
|
||||||
holder.setTransientPermission(new NodeBuilder("group." + permsSubject.getIdentifier())
|
.withExtraContext(contexts)
|
||||||
.withExtraContext(contexts)
|
.build());
|
||||||
.build());
|
|
||||||
}
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
@ -273,17 +210,14 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||||
LPSubject permsSubject = subject.resolve(service);
|
LPSubject permsSubject = subject.resolve(service);
|
||||||
|
|
||||||
try {
|
if (enduring) {
|
||||||
if (enduring) {
|
holder.unsetPermissionUnchecked(new NodeBuilder("group." + permsSubject.getIdentifier())
|
||||||
holder.unsetPermission(new NodeBuilder("group." + permsSubject.getIdentifier())
|
.withExtraContext(contexts)
|
||||||
.withExtraContext(contexts)
|
.build());
|
||||||
.build());
|
} else {
|
||||||
} else {
|
holder.unsetTransientPermissionUnchecked(new NodeBuilder("group." + permsSubject.getIdentifier())
|
||||||
holder.unsetTransientPermission(new NodeBuilder("group." + permsSubject.getIdentifier())
|
.withExtraContext(contexts)
|
||||||
.withExtraContext(contexts)
|
.build());
|
||||||
.build());
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
@ -296,20 +230,11 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
@Override
|
@Override
|
||||||
public boolean clearParents() {
|
public boolean clearParents() {
|
||||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PARENTS)) {
|
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PARENTS)) {
|
||||||
List<Node> toRemove = (enduring ? holder.getNodes() : holder.getTransientNodes()).stream()
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
.filter(Node::isGroupNode)
|
.filter(Node::isGroupNode)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
try {
|
|
||||||
if (enduring) {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} else {
|
|
||||||
holder.unsetTransientPermission(n);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (holder instanceof User) {
|
if (holder instanceof User) {
|
||||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||||
@ -323,37 +248,12 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
@Override
|
@Override
|
||||||
public boolean clearParents(@NonNull ContextSet set) {
|
public boolean clearParents(@NonNull ContextSet set) {
|
||||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PARENTS)) {
|
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PARENTS)) {
|
||||||
List<Node> toRemove = new ArrayList<>();
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
.filter(Node::isGroupNode)
|
||||||
if (!n.isGroupNode()) {
|
.filter(n -> n.getFullContexts().equals(set))
|
||||||
continue;
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
|
|
||||||
MutableContextSet contexts = MutableContextSet.fromSet(n.getContexts());
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
|
|
||||||
if (n.isServerSpecific()) {
|
|
||||||
contexts.add(new Context(LuckPermsService.SERVER_CONTEXT, n.getServer().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.isWorldSpecific()) {
|
|
||||||
contexts.add(new Context(Context.WORLD_KEY, n.getWorld().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contexts.equals(set)) {
|
|
||||||
toRemove.add(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
|
||||||
try {
|
|
||||||
if (enduring) {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} else {
|
|
||||||
holder.unsetTransientPermission(n);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (holder instanceof User) {
|
if (holder instanceof User) {
|
||||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||||
@ -372,25 +272,10 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
Map<ImmutableContextSet, Integer> minSuffixPriority = new HashMap<>();
|
Map<ImmutableContextSet, Integer> minSuffixPriority = new HashMap<>();
|
||||||
|
|
||||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
||||||
if (!n.getValue()) {
|
if (!n.getValue()) continue;
|
||||||
continue;
|
if (!n.isMeta() && !n.isPrefix() && !n.isSuffix()) continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!n.isMeta() && !n.isPrefix() && !n.isSuffix()) {
|
ImmutableContextSet immutableContexts = n.getFullContexts().makeImmutable();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MutableContextSet contexts = MutableContextSet.fromSet(n.getContexts());
|
|
||||||
|
|
||||||
if (n.isServerSpecific()) {
|
|
||||||
contexts.add(new Context(LuckPermsService.SERVER_CONTEXT, n.getServer().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.isWorldSpecific()) {
|
|
||||||
contexts.add(new Context(Context.WORLD_KEY, n.getWorld().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImmutableContextSet immutableContexts = contexts.makeImmutable();
|
|
||||||
|
|
||||||
if (!options.containsKey(immutableContexts)) {
|
if (!options.containsKey(immutableContexts)) {
|
||||||
options.put(immutableContexts, new HashMap<>());
|
options.put(immutableContexts, new HashMap<>());
|
||||||
@ -436,54 +321,41 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
if (key.equalsIgnoreCase("prefix") || key.equalsIgnoreCase("suffix")) {
|
if (key.equalsIgnoreCase("prefix") || key.equalsIgnoreCase("suffix")) {
|
||||||
// special handling.
|
// special handling.
|
||||||
String type = key.toLowerCase();
|
String type = key.toLowerCase();
|
||||||
|
boolean prefix = type.equals("prefix");
|
||||||
|
|
||||||
// remove all prefixes/suffixes from the user
|
// remove all prefixes/suffixes from the user
|
||||||
List<Node> toRemove = holder.getNodes().stream()
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
.filter(n -> type.equals("prefix") ? n.isPrefix() : n.isSuffix())
|
.filter(n -> prefix ? n.isPrefix() : n.isSuffix())
|
||||||
|
.filter(n -> n.getFullContexts().equals(context))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
try {
|
|
||||||
if (enduring) {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} else {
|
|
||||||
holder.unsetTransientPermission(n);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
MetaHolder metaHolder = holder.accumulateMeta(null, null, ExtractedContexts.generate(service.calculateContexts(context)));
|
MetaHolder metaHolder = holder.accumulateMeta(null, null, ExtractedContexts.generate(service.calculateContexts(context)));
|
||||||
int priority = (type.equals("prefix") ? metaHolder.getPrefixes() : metaHolder.getSuffixes()).keySet().stream()
|
int priority = (type.equals("prefix") ? metaHolder.getPrefixes() : metaHolder.getSuffixes()).keySet().stream()
|
||||||
.mapToInt(e -> e).max().orElse(0);
|
.mapToInt(e -> e).max().orElse(0);
|
||||||
priority += 10;
|
priority += 10;
|
||||||
|
|
||||||
try {
|
if (enduring) {
|
||||||
if (enduring) {
|
holder.setPermissionUnchecked(NodeFactory.makeChatMetaNode(type.equals("prefix"), priority, value).withExtraContext(context).build());
|
||||||
holder.setPermission(NodeFactory.makeChatMetaNode(type.equals("prefix"), priority, value).withExtraContext(context).build());
|
} else {
|
||||||
} else {
|
holder.setTransientPermissionUnchecked(NodeFactory.makeChatMetaNode(type.equals("prefix"), priority, value).withExtraContext(context).build());
|
||||||
holder.setTransientPermission(NodeFactory.makeChatMetaNode(type.equals("prefix"), priority, value).withExtraContext(context).build());
|
}
|
||||||
}
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// standard remove
|
// standard remove
|
||||||
List<Node> toRemove = holder.getNodes().stream()
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
.filter(n -> n.isMeta() && n.getMeta().getKey().equals(key))
|
.filter(n -> n.isMeta() && n.getMeta().getKey().equals(key))
|
||||||
|
.filter(n -> n.getFullContexts().equals(context))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
try {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} catch (ObjectLacksException ignored) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
if (enduring) {
|
||||||
if (enduring) {
|
holder.setPermissionUnchecked(NodeFactory.makeMetaNode(key, value).withExtraContext(context).build());
|
||||||
holder.setPermission(NodeFactory.makeMetaNode(key, value).withExtraContext(context).build());
|
} else {
|
||||||
} else {
|
holder.setTransientPermissionUnchecked(NodeFactory.makeMetaNode(key, value).withExtraContext(context).build());
|
||||||
holder.setTransientPermission(NodeFactory.makeMetaNode(key, value).withExtraContext(context).build());
|
}
|
||||||
}
|
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
@ -492,21 +364,22 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean unsetOption(ContextSet contexts, String key) {
|
public boolean unsetOption(ContextSet set, String key) {
|
||||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_SET_OPTION)) {
|
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_SET_OPTION)) {
|
||||||
List<Node> toRemove = (enduring ? holder.getNodes() : holder.getTransientNodes()).stream()
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
.filter(n -> n.isMeta() && n.getMeta().getKey().equals(key))
|
.filter(n -> {
|
||||||
|
if (key.equalsIgnoreCase("prefix")) {
|
||||||
|
return n.isPrefix();
|
||||||
|
} else if (key.equalsIgnoreCase("suffix")) {
|
||||||
|
return n.isSuffix();
|
||||||
|
} else {
|
||||||
|
return n.isMeta() && n.getMeta().getKey().equals(key);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(n -> n.getFullContexts().equals(set))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
try {
|
|
||||||
if (enduring) {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} else {
|
|
||||||
holder.unsetTransientPermission(n);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
return true;
|
return true;
|
||||||
@ -516,36 +389,12 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
@Override
|
@Override
|
||||||
public boolean clearOptions(@NonNull ContextSet set) {
|
public boolean clearOptions(@NonNull ContextSet set) {
|
||||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_OPTIONS)) {
|
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_OPTIONS)) {
|
||||||
List<Node> toRemove = new ArrayList<>();
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
.filter(n -> n.isMeta() || n.isPrefix() || n.isSuffix())
|
||||||
if (!n.isMeta() && !n.isPrefix() && !n.isSuffix()) {
|
.filter(n -> n.getFullContexts().equals(set))
|
||||||
continue;
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
|
|
||||||
MutableContextSet contexts = MutableContextSet.fromSet(n.getContexts());
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
|
|
||||||
if (n.isServerSpecific()) {
|
|
||||||
contexts.add(new Context(LuckPermsService.SERVER_CONTEXT, n.getServer().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.isWorldSpecific()) {
|
|
||||||
contexts.add(new Context(Context.WORLD_KEY, n.getWorld().get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contexts.equals(set)) {
|
|
||||||
toRemove.add(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
|
||||||
try {
|
|
||||||
if (enduring) {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} else {
|
|
||||||
holder.unsetTransientPermission(n);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
return !toRemove.isEmpty();
|
return !toRemove.isEmpty();
|
||||||
@ -555,22 +404,39 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
@Override
|
@Override
|
||||||
public boolean clearOptions() {
|
public boolean clearOptions() {
|
||||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_OPTIONS)) {
|
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_OPTIONS)) {
|
||||||
List<Node> toRemove = (enduring ? holder.getNodes() : holder.getTransientNodes()).stream()
|
List<Node> toRemove = streamNodes(enduring)
|
||||||
.filter(n -> n.isMeta() || n.isPrefix() || n.isSuffix())
|
.filter(n -> n.isMeta() || n.isPrefix() || n.isSuffix())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
toRemove.forEach(n -> {
|
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||||
try {
|
|
||||||
if (enduring) {
|
|
||||||
holder.unsetPermission(n);
|
|
||||||
} else {
|
|
||||||
holder.unsetTransientPermission(n);
|
|
||||||
}
|
|
||||||
} catch (ObjectLacksException ignored) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
objectSave(holder);
|
objectSave(holder);
|
||||||
return !toRemove.isEmpty();
|
return !toRemove.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Stream<Node> streamNodes(boolean enduring) {
|
||||||
|
return (enduring ? holder.getNodes() : holder.getTransientNodes()).stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Consumer<Node> makeUnsetConsumer(boolean enduring) {
|
||||||
|
return n -> {
|
||||||
|
if (enduring) {
|
||||||
|
holder.unsetPermissionUnchecked(n);
|
||||||
|
} else {
|
||||||
|
holder.unsetTransientPermissionUnchecked(n);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void objectSave(PermissionHolder t) {
|
||||||
|
if (t instanceof User) {
|
||||||
|
service.getPlugin().getStorage().saveUser(((User) t))
|
||||||
|
.thenRunAsync(() -> ((User) t).getRefreshBuffer().request(), service.getPlugin().getScheduler().getAsyncExecutor());
|
||||||
|
}
|
||||||
|
if (t instanceof Group) {
|
||||||
|
service.getPlugin().getStorage().saveGroup((Group) t)
|
||||||
|
.thenRunAsync(() -> service.getPlugin().getUpdateTaskBuffer().request(), service.getPlugin().getScheduler().getAsyncExecutor());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ package me.lucko.luckperms.sponge.service;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ServiceCacheHousekeepingTask implements Runnable {
|
public class ServiceCacheHousekeepingTask implements Runnable {
|
||||||
|
@ -41,8 +41,8 @@ import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
|||||||
import me.lucko.luckperms.common.calculators.processors.MapProcessor;
|
import me.lucko.luckperms.common.calculators.processors.MapProcessor;
|
||||||
import me.lucko.luckperms.sponge.calculators.SpongeWildcardProcessor;
|
import me.lucko.luckperms.sponge.calculators.SpongeWildcardProcessor;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -36,8 +36,8 @@ import me.lucko.luckperms.api.Tristate;
|
|||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -35,10 +35,10 @@ import me.lucko.luckperms.api.context.ContextSet;
|
|||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
|
||||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
|
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
|
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
|
||||||
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference;
|
||||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.base;
|
package me.lucko.luckperms.sponge.service.proxy;
|
||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
@ -39,8 +39,8 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static me.lucko.luckperms.sponge.service.base.Util.convertContexts;
|
import static me.lucko.luckperms.sponge.service.proxy.Util.convertContexts;
|
||||||
import static me.lucko.luckperms.sponge.service.base.Util.convertTristate;
|
import static me.lucko.luckperms.sponge.service.proxy.Util.convertTristate;
|
||||||
|
|
||||||
public interface LPSubject extends Subject {
|
public interface LPSubject extends Subject {
|
||||||
|
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.base;
|
package me.lucko.luckperms.sponge.service.proxy;
|
||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static me.lucko.luckperms.sponge.service.base.Util.convertContexts;
|
import static me.lucko.luckperms.sponge.service.proxy.Util.convertContexts;
|
||||||
|
|
||||||
public interface LPSubjectCollection extends SubjectCollection {
|
public interface LPSubjectCollection extends SubjectCollection {
|
||||||
|
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.base;
|
package me.lucko.luckperms.sponge.service.proxy;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
@ -41,8 +41,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static me.lucko.luckperms.sponge.service.base.Util.convertContexts;
|
import static me.lucko.luckperms.sponge.service.proxy.Util.convertContexts;
|
||||||
import static me.lucko.luckperms.sponge.service.base.Util.convertTristate;
|
import static me.lucko.luckperms.sponge.service.proxy.Util.convertTristate;
|
||||||
|
|
||||||
public interface LPSubjectData extends SubjectData {
|
public interface LPSubjectData extends SubjectData {
|
||||||
|
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.base;
|
package me.lucko.luckperms.sponge.service.proxy;
|
||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
@ -28,7 +28,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import lombok.ToString;
|
|||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
import me.lucko.luckperms.sponge.service.proxy.LPSubject;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user