mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Cleanup sponge delegate classes
This commit is contained in:
parent
4cfd8a7e2c
commit
25f31d0bb8
@ -992,33 +992,44 @@ public abstract class PermissionHolder {
|
||||
/**
|
||||
* Clear all of the holders permission nodes
|
||||
*/
|
||||
public void clearNodes() {
|
||||
public boolean clearNodes() {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
synchronized (nodes) {
|
||||
nodes.clear();
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
|
||||
if (before.size() == after.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearNodes(ContextSet contextSet) {
|
||||
public boolean clearNodes(ContextSet contextSet) {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
synchronized (nodes) {
|
||||
nodes.removeAll(contextSet.makeImmutable());
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
|
||||
if (before.size() == after.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearParents(boolean giveDefault) {
|
||||
public boolean clearParents(boolean giveDefault) {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
|
||||
synchronized (nodes) {
|
||||
boolean b = nodes.values().removeIf(Node::isGroupNode);
|
||||
if (!b) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this instanceof User && giveDefault) {
|
||||
@ -1027,19 +1038,20 @@ public abstract class PermissionHolder {
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearParents(ContextSet contextSet, boolean giveDefault) {
|
||||
public boolean clearParents(ContextSet contextSet, boolean giveDefault) {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
synchronized (nodes) {
|
||||
SortedSet<Node> nodes = this.nodes.get(contextSet.makeImmutable());
|
||||
if (nodes == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean b = nodes.removeIf(Node::isGroupNode);
|
||||
if (!b) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this instanceof User && giveDefault) {
|
||||
@ -1048,80 +1060,90 @@ public abstract class PermissionHolder {
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearMeta() {
|
||||
public boolean clearMeta() {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
|
||||
synchronized (nodes) {
|
||||
if (!nodes.values().removeIf(n -> n.isMeta() || n.isPrefix() || n.isSuffix())) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearMeta(ContextSet contextSet) {
|
||||
public boolean clearMeta(ContextSet contextSet) {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
synchronized (nodes) {
|
||||
SortedSet<Node> nodes = this.nodes.get(contextSet.makeImmutable());
|
||||
if (nodes == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean b = nodes.removeIf(n -> n.isMeta() || n.isPrefix() || n.isSuffix());
|
||||
if (!b) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearMetaKeys(String key, boolean temp) {
|
||||
public boolean clearMetaKeys(String key, boolean temp) {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
synchronized (nodes) {
|
||||
boolean b = this.nodes.values().removeIf(n -> n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key));
|
||||
if (!b) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearMetaKeys(String key, ContextSet contextSet, boolean temp) {
|
||||
public boolean clearMetaKeys(String key, ContextSet contextSet, boolean temp) {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes().values());
|
||||
synchronized (nodes) {
|
||||
|
||||
SortedSet<Node> nodes = this.nodes.get(contextSet.makeImmutable());
|
||||
if (nodes == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean b = nodes.removeIf(n -> n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key));
|
||||
if (!b) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes().values());
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearTransientNodes() {
|
||||
public boolean clearTransientNodes() {
|
||||
ImmutableSet<Node> before = ImmutableSet.copyOf(getTransientNodes().values());
|
||||
|
||||
synchronized (transientNodes) {
|
||||
transientNodes.clear();
|
||||
}
|
||||
invalidateCache();
|
||||
ImmutableSet<Node> after = ImmutableSet.copyOf(getTransientNodes().values());
|
||||
|
||||
if (before.size() == after.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,9 +154,14 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
|
||||
* Clear all of the users permission nodes
|
||||
*/
|
||||
@Override
|
||||
public void clearNodes() {
|
||||
super.clearNodes();
|
||||
public boolean clearNodes() {
|
||||
boolean ret = super.clearNodes();
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
getPlugin().getUserManager().giveDefaultIfNeeded(this, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearNodes(boolean giveDefault) {
|
||||
|
@ -29,7 +29,6 @@ import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.sponge.service.proxy.Util;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@ -46,7 +45,6 @@ import java.util.Set;
|
||||
public class SpongeMigrationUtils {
|
||||
|
||||
public static void migrateSubject(Subject subject, PermissionHolder holder, int priority) {
|
||||
|
||||
if (holder instanceof Group) {
|
||||
MigrationUtils.setGroupWeight((Group) holder, priority);
|
||||
}
|
||||
@ -56,13 +54,8 @@ public class SpongeMigrationUtils {
|
||||
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : perms.entrySet()) {
|
||||
ContextSet context = Util.convertContexts(e.getKey());
|
||||
|
||||
ExtractedContexts extractedContexts = ExtractedContexts.generate(context);
|
||||
ContextSet contexts = extractedContexts.getContextSet();
|
||||
String server = extractedContexts.getServer();
|
||||
String world = extractedContexts.getWorld();
|
||||
|
||||
for (Map.Entry<String, Boolean> perm : e.getValue().entrySet()) {
|
||||
holder.setPermission(NodeFactory.newBuilder(perm.getKey()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build());
|
||||
holder.setPermission(NodeFactory.newBuilder(perm.getKey()).withExtraContext(context).setValue(perm.getValue()).build());
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,18 +64,13 @@ public class SpongeMigrationUtils {
|
||||
for (Map.Entry<Set<Context>, Map<String, String>> e : opts.entrySet()) {
|
||||
ContextSet context = Util.convertContexts(e.getKey());
|
||||
|
||||
ExtractedContexts extractedContexts = ExtractedContexts.generate(context);
|
||||
ContextSet contexts = extractedContexts.getContextSet();
|
||||
String server = extractedContexts.getServer();
|
||||
String world = extractedContexts.getWorld();
|
||||
|
||||
for (Map.Entry<String, String> opt : e.getValue().entrySet()) {
|
||||
if (opt.getKey().equalsIgnoreCase("prefix")) {
|
||||
holder.setPermission(NodeFactory.makePrefixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(NodeFactory.makePrefixNode(priority, opt.getValue()).withExtraContext(context).setValue(true).build());
|
||||
} else if (opt.getKey().equalsIgnoreCase("suffix")) {
|
||||
holder.setPermission(NodeFactory.makeSuffixNode(priority, opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(NodeFactory.makeSuffixNode(priority, opt.getValue()).withExtraContext(context).setValue(true).build());
|
||||
} else {
|
||||
holder.setPermission(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).withExtraContext(context).setValue(true).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,34 +80,29 @@ public class SpongeMigrationUtils {
|
||||
for (Map.Entry<Set<Context>, List<Subject>> e : parents.entrySet()) {
|
||||
ContextSet context = Util.convertContexts(e.getKey());
|
||||
|
||||
ExtractedContexts extractedContexts = ExtractedContexts.generate(context);
|
||||
ContextSet contexts = extractedContexts.getContextSet();
|
||||
String server = extractedContexts.getServer();
|
||||
String world = extractedContexts.getWorld();
|
||||
|
||||
for (Subject s : e.getValue()) {
|
||||
if (!s.getContainingCollection().getIdentifier().equalsIgnoreCase(PermissionService.SUBJECTS_GROUP)) {
|
||||
continue; // LuckPerms does not support persisting other subject types.
|
||||
}
|
||||
|
||||
holder.setPermission(NodeFactory.newBuilder("group." + MigrationUtils.standardizeName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermission(NodeFactory.newBuilder("group." + MigrationUtils.standardizeName(s.getIdentifier())).withExtraContext(context).setValue(true).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void migrateSubjectData(SubjectData from, SubjectData to) {
|
||||
for (Map.Entry<Set<Context>, Map<String, String>> e : from.getAllOptions().entrySet()) {
|
||||
for (Map.Entry<String, String> e1 : e.getValue().entrySet()) {
|
||||
to.setOption(e.getKey(), e1.getKey(), e1.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : from.getAllPermissions().entrySet()) {
|
||||
for (Map.Entry<String, Boolean> e1 : e.getValue().entrySet()) {
|
||||
to.setPermission(e.getKey(), e1.getKey(), Tristate.fromBoolean(e1.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Set<Context>, Map<String, String>> e : from.getAllOptions().entrySet()) {
|
||||
for (Map.Entry<String, String> e1 : e.getValue().entrySet()) {
|
||||
to.setOption(e.getKey(), e1.getKey(), e1.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Set<Context>, List<Subject>> e : from.getAllParents().entrySet()) {
|
||||
for (Subject s : e.getValue()) {
|
||||
to.addParent(e.getKey(), s);
|
||||
|
@ -34,6 +34,7 @@ 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.MetaAccumulator;
|
||||
import me.lucko.luckperms.common.core.DataMutateResult;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
@ -48,8 +49,8 @@ import org.spongepowered.api.service.permission.PermissionService;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -72,16 +73,19 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public Map<ImmutableContextSet, Map<String, Boolean>> getPermissions() {
|
||||
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_GET_PERMISSIONS)) {
|
||||
Map<ImmutableContextSet, Map<String, Boolean>> perms = new HashMap<>();
|
||||
Map<ImmutableContextSet, ImmutableMap.Builder<String, Boolean>> perms = new HashMap<>();
|
||||
|
||||
for (Node n : enduring ? holder.getNodes().values() : holder.getTransientNodes().values()) {
|
||||
ContextSet contexts = n.getFullContexts();
|
||||
perms.computeIfAbsent(contexts.makeImmutable(), cs -> new HashMap<>()).put(n.getPermission(), n.getValue());
|
||||
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (enduring ? holder.getNodes() : holder.getTransientNodes()).asMap().entrySet()) {
|
||||
ImmutableMap.Builder<String, Boolean> results = ImmutableMap.builder();
|
||||
for (Node n : e.getValue()) {
|
||||
results.put(n.getPermission(), n.getValue());
|
||||
}
|
||||
perms.put(e.getKey(), results);
|
||||
}
|
||||
|
||||
ImmutableMap.Builder<ImmutableContextSet, Map<String, Boolean>> map = ImmutableMap.builder();
|
||||
for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> e : perms.entrySet()) {
|
||||
map.put(e.getKey(), ImmutableMap.copyOf(e.getValue()));
|
||||
for (Map.Entry<ImmutableContextSet, ImmutableMap.Builder<String, Boolean>> e : perms.entrySet()) {
|
||||
map.put(e.getKey(), e.getValue().build());
|
||||
}
|
||||
return map.build();
|
||||
}
|
||||
@ -127,10 +131,15 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public boolean clearPermissions() {
|
||||
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PERMISSIONS)) {
|
||||
boolean ret;
|
||||
if (enduring) {
|
||||
holder.clearNodes();
|
||||
ret = holder.clearNodes();
|
||||
} else {
|
||||
holder.clearTransientNodes();
|
||||
ret = holder.clearTransientNodes();
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (holder instanceof User) {
|
||||
@ -145,36 +154,50 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public boolean clearPermissions(@NonNull ContextSet set) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PERMISSIONS)) {
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.collect(Collectors.toList());
|
||||
boolean ret;
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
if (enduring) {
|
||||
ret = holder.clearNodes(set);
|
||||
} else {
|
||||
List<Node> toRemove = streamNodes(false)
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(false));
|
||||
ret = !toRemove.isEmpty();
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (holder instanceof User) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
}
|
||||
|
||||
objectSave(holder);
|
||||
return !toRemove.isEmpty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ImmutableContextSet, Set<SubjectReference>> getParents() {
|
||||
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_GET_PARENTS)) {
|
||||
Map<ImmutableContextSet, Set<SubjectReference>> parents = new HashMap<>();
|
||||
Map<ImmutableContextSet, ImmutableSet.Builder<SubjectReference>> parents = new HashMap<>();
|
||||
|
||||
for (Node n : enduring ? holder.getNodes().values() : holder.getTransientNodes().values()) {
|
||||
if (!n.isGroupNode()) continue;
|
||||
|
||||
ContextSet contexts = n.getFullContexts();
|
||||
parents.computeIfAbsent(contexts.makeImmutable(), cs -> new HashSet<>()).add(service.getGroupSubjects().get(n.getGroupName()).toReference());
|
||||
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (enduring ? holder.getNodes() : holder.getTransientNodes()).asMap().entrySet()) {
|
||||
ImmutableSet.Builder<SubjectReference> results = ImmutableSet.builder();
|
||||
for (Node n : e.getValue()) {
|
||||
if (n.isGroupNode()) {
|
||||
results.add(service.getGroupSubjects().get(n.getGroupName()).toReference());
|
||||
}
|
||||
}
|
||||
parents.put(e.getKey(), results);
|
||||
}
|
||||
|
||||
ImmutableMap.Builder<ImmutableContextSet, Set<SubjectReference>> map = ImmutableMap.builder();
|
||||
for (Map.Entry<ImmutableContextSet, Set<SubjectReference>> e : parents.entrySet()) {
|
||||
map.put(e.getKey(), ImmutableSet.copyOf(e.getValue()));
|
||||
for (Map.Entry<ImmutableContextSet, ImmutableSet.Builder<SubjectReference>> e : parents.entrySet()) {
|
||||
map.put(e.getKey(), e.getValue().build());
|
||||
}
|
||||
return map.build();
|
||||
}
|
||||
@ -185,17 +208,22 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_ADD_PARENT)) {
|
||||
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
LPSubject permsSubject = subject.resolve(service);
|
||||
DataMutateResult result;
|
||||
|
||||
if (enduring) {
|
||||
holder.setPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
result = holder.setPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
} else {
|
||||
holder.setTransientPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
result = holder.setTransientPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
}
|
||||
|
||||
if (!result.asBoolean()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
objectSave(holder);
|
||||
return true;
|
||||
}
|
||||
@ -208,17 +236,22 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_REMOVE_PARENT)) {
|
||||
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
LPSubject permsSubject = subject.resolve(service);
|
||||
DataMutateResult result;
|
||||
|
||||
if (enduring) {
|
||||
holder.unsetPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
result = holder.unsetPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
} else {
|
||||
holder.unsetTransientPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
result = holder.unsetTransientPermission(NodeFactory.newBuilder("group." + permsSubject.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
}
|
||||
|
||||
if (!result.asBoolean()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
objectSave(holder);
|
||||
return true;
|
||||
}
|
||||
@ -229,37 +262,58 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public boolean clearParents() {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PARENTS)) {
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
.filter(Node::isGroupNode)
|
||||
.collect(Collectors.toList());
|
||||
boolean ret;
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
if (enduring) {
|
||||
ret = holder.clearParents(true);
|
||||
} else {
|
||||
List<Node> toRemove = streamNodes(false)
|
||||
.filter(Node::isGroupNode)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (holder instanceof User) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
toRemove.forEach(makeUnsetConsumer(false));
|
||||
ret = !toRemove.isEmpty();
|
||||
|
||||
if (ret && holder instanceof User) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
objectSave(holder);
|
||||
return !toRemove.isEmpty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearParents(@NonNull ContextSet set) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PARENTS)) {
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.collect(Collectors.toList());
|
||||
boolean ret;
|
||||
if (enduring) {
|
||||
ret = holder.clearParents(set, true);
|
||||
} else {
|
||||
List<Node> toRemove = streamNodes(false)
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
toRemove.forEach(makeUnsetConsumer(false));
|
||||
ret = !toRemove.isEmpty();
|
||||
|
||||
if (holder instanceof User) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
if (ret && holder instanceof User) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
objectSave(holder);
|
||||
return !toRemove.isEmpty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,13 +483,21 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
}
|
||||
|
||||
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());
|
||||
if (!enduring) {
|
||||
// don't bother saving to primary storage. just refresh
|
||||
if (t instanceof User) {
|
||||
((User) t).getRefreshBuffer().request();
|
||||
} else {
|
||||
service.getPlugin().getUpdateTaskBuffer().request();
|
||||
}
|
||||
} else {
|
||||
if (t instanceof User) {
|
||||
service.getPlugin().getStorage().saveUser(((User) t))
|
||||
.thenRunAsync(() -> ((User) t).getRefreshBuffer().request(), service.getPlugin().getScheduler().getAsyncExecutor());
|
||||
} else {
|
||||
service.getPlugin().getStorage().saveGroup((Group) t)
|
||||
.thenRunAsync(() -> service.getPlugin().getUpdateTaskBuffer().request(), service.getPlugin().getScheduler().getAsyncExecutor());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,43 +59,6 @@ import java.util.concurrent.TimeUnit;
|
||||
public class CalculatedSubjectData implements LPSubjectData {
|
||||
private static final ContextComparator CONTEXT_COMPARATOR = new ContextComparator();
|
||||
|
||||
private static <V> Map<String, V> flattenMap(ContextSet contexts, Map<ContextSet, Map<String, V>> source) {
|
||||
Map<String, V> map = new HashMap<>();
|
||||
|
||||
SortedMap<ContextSet, Map<String, V>> ret = getRelevantEntries(contexts, source);
|
||||
for (Map<String, V> m : ret.values()) {
|
||||
for (Map.Entry<String, V> e : m.entrySet()) {
|
||||
if (!map.containsKey(e.getKey())) {
|
||||
map.put(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
private static <K, V> SortedMap<ContextSet, Map<K, V>> getRelevantEntries(ContextSet set, Map<ContextSet, Map<K, V>> map) {
|
||||
ImmutableSortedMap.Builder<ContextSet, Map<K, V>> perms = ImmutableSortedMap.orderedBy(CONTEXT_COMPARATOR);
|
||||
|
||||
loop:
|
||||
for (Map.Entry<ContextSet, Map<K, V>> e : map.entrySet()) {
|
||||
|
||||
for (Map.Entry<String, String> c : e.getKey().toSet()) {
|
||||
if (!set.has(c.getKey(), c.getValue())) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
|
||||
perms.put(e.getKey().makeImmutable(), ImmutableMap.copyOf(e.getValue()));
|
||||
}
|
||||
|
||||
return perms.build();
|
||||
}
|
||||
|
||||
private static boolean stringEquals(String a, String b) {
|
||||
return a == null && b == null || a != null && b != null && a.equalsIgnoreCase(b);
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final LPSubject parentSubject;
|
||||
|
||||
@ -342,6 +305,39 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
return !map.isEmpty();
|
||||
}
|
||||
|
||||
private static <V> Map<String, V> flattenMap(ContextSet contexts, Map<ContextSet, Map<String, V>> source) {
|
||||
Map<String, V> map = new HashMap<>();
|
||||
|
||||
SortedMap<ContextSet, Map<String, V>> ret = getRelevantEntries(contexts, source);
|
||||
for (Map<String, V> m : ret.values()) {
|
||||
for (Map.Entry<String, V> e : m.entrySet()) {
|
||||
if (!map.containsKey(e.getKey())) {
|
||||
map.put(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
private static <K, V> SortedMap<ContextSet, Map<K, V>> getRelevantEntries(ContextSet set, Map<ContextSet, Map<K, V>> map) {
|
||||
ImmutableSortedMap.Builder<ContextSet, Map<K, V>> perms = ImmutableSortedMap.orderedBy(CONTEXT_COMPARATOR);
|
||||
|
||||
for (Map.Entry<ContextSet, Map<K, V>> e : map.entrySet()) {
|
||||
if (!e.getKey().isSatisfiedBy(set)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
perms.put(e.getKey().makeImmutable(), ImmutableMap.copyOf(e.getValue()));
|
||||
}
|
||||
|
||||
return perms.build();
|
||||
}
|
||||
|
||||
private static boolean stringEquals(String a, String b) {
|
||||
return a == null && b == null || a != null && b != null && a.equalsIgnoreCase(b);
|
||||
}
|
||||
|
||||
private static class ContextComparator implements Comparator<ContextSet> {
|
||||
|
||||
@Override
|
||||
|
@ -32,13 +32,14 @@ import me.lucko.luckperms.sponge.service.proxy.LPSubjectCollection;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@ToString(of = "collection")
|
||||
@EqualsAndHashCode(of = "collection")
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class SubjectCollectionReference {
|
||||
|
||||
@Getter
|
||||
private final String collection;
|
||||
|
||||
private WeakReference<LPSubjectCollection> ref = null;
|
||||
|
||||
public synchronized LPSubjectCollection resolve(LuckPermsService service) {
|
||||
|
@ -37,9 +37,8 @@ import org.spongepowered.api.service.permission.Subject;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@ToString(of = {"collection", "identifier"})
|
||||
@EqualsAndHashCode(of = {"collection", "identifier"})
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class SubjectReference {
|
||||
public static SubjectReference deserialize(String s) {
|
||||
@ -51,7 +50,10 @@ public class SubjectReference {
|
||||
return of(subject.getContainingCollection().getIdentifier(), subject.getIdentifier());
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final String collection;
|
||||
|
||||
@Getter
|
||||
private final String identifier;
|
||||
|
||||
private WeakReference<LPSubject> ref = null;
|
||||
@ -69,8 +71,4 @@ public class SubjectReference {
|
||||
return s;
|
||||
}
|
||||
|
||||
public String serialize() {
|
||||
return collection + "/" + identifier;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user