refactor contexts slightly

This commit is contained in:
Luck 2016-11-18 22:39:00 +00:00
parent c60067e733
commit c0734fc29e
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
8 changed files with 121 additions and 59 deletions

View File

@ -32,6 +32,7 @@ import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.chat.Chat;
@ -214,7 +215,8 @@ public class VaultChatHook extends Chat {
context.put("world", world); context.put("world", world);
} }
for (Node n : group.getAllNodes(null, new Contexts(ContextSet.fromMap(context), perms.isIncludeGlobal(), true, true, true, true, false))) { ExtractedContexts ec = ExtractedContexts.generate(new Contexts(ContextSet.fromMap(context), perms.isIncludeGlobal(), true, true, true, true, false));
for (Node n : group.getAllNodes(null, ec)) {
if (!n.getValue()) { if (!n.getValue()) {
continue; continue;
} }

View File

@ -26,6 +26,7 @@ import lombok.AllArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import me.lucko.luckperms.api.*; import me.lucko.luckperms.api.*;
import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -64,17 +65,17 @@ public class PermissionHolderLink implements PermissionHolder {
@Override @Override
public Set<Node> getAllNodes() { public Set<Node> getAllNodes() {
return Collections.unmodifiableSet(master.getAllNodes(null, Contexts.allowAll())); return Collections.unmodifiableSet(master.getAllNodes(null, ExtractedContexts.generate(Contexts.allowAll())));
} }
@Override @Override
public SortedSet<LocalizedNode> getAllNodes(@NonNull Contexts contexts) { public SortedSet<LocalizedNode> getAllNodes(@NonNull Contexts contexts) {
return master.getAllNodes(null, contexts); return master.getAllNodes(null, ExtractedContexts.generate(contexts));
} }
@Override @Override
public Set<LocalizedNode> getAllNodesFiltered(@NonNull Contexts contexts) { public Set<LocalizedNode> getAllNodesFiltered(@NonNull Contexts contexts) {
return master.getAllNodesFiltered(contexts); return master.getAllNodesFiltered(ExtractedContexts.generate(contexts));
} }
@Override @Override

View File

@ -36,6 +36,7 @@ import me.lucko.luckperms.api.caching.PermissionData;
import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.common.users.User;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import java.util.Set; import java.util.Set;
@ -78,7 +79,7 @@ public class UserCache implements UserData {
@Override @Override
public ListenableFuture<MetaCache> reload(Contexts contexts, MetaCache oldData) { public ListenableFuture<MetaCache> reload(Contexts contexts, MetaCache oldData) {
oldData.loadMeta(user.accumulateMeta(null, null, contexts)); oldData.loadMeta(user.accumulateMeta(null, null, ExtractedContexts.generate(contexts)));
return Futures.immediateFuture(oldData); return Futures.immediateFuture(oldData);
} }
}); });
@ -103,7 +104,7 @@ public class UserCache implements UserData {
@Override @Override
public MetaCache calculateMeta(@NonNull Contexts contexts) { public MetaCache calculateMeta(@NonNull Contexts contexts) {
MetaCache data = new MetaCache(); MetaCache data = new MetaCache();
data.loadMeta(user.accumulateMeta(null, null, contexts)); data.loadMeta(user.accumulateMeta(null, null, ExtractedContexts.generate(contexts)));
return data; return data;
} }

View File

@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.Predicates;
import java.util.*; import java.util.*;
@ -49,7 +50,7 @@ public class MetaInfo extends SharedSubCommand {
Set<LocalizedNode> meta = new HashSet<>(); Set<LocalizedNode> meta = new HashSet<>();
// Collect data // Collect data
for (LocalizedNode node : holder.getAllNodes(null, Contexts.allowAll())) { for (LocalizedNode node : holder.getAllNodes(null, ExtractedContexts.generate(Contexts.allowAll()))) {
if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) { if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) {
continue; continue;
} }

View File

@ -33,7 +33,6 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.api.event.events.*; import me.lucko.luckperms.api.event.events.*;
import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.api.internal.GroupLink; import me.lucko.luckperms.common.api.internal.GroupLink;
@ -42,6 +41,7 @@ import me.lucko.luckperms.common.caching.MetaHolder;
import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.Cache; import me.lucko.luckperms.common.utils.Cache;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -241,10 +241,10 @@ public abstract class PermissionHolder {
/** /**
* Resolves inherited nodes and returns them * Resolves inherited nodes and returns them
* @param excludedGroups a list of groups to exclude * @param excludedGroups a list of groups to exclude
* @param context context to decide if groups should be applied * @param contexts context to decide if groups should be applied
* @return a set of nodes * @return a set of nodes
*/ */
public SortedSet<LocalizedNode> getAllNodes(List<String> excludedGroups, Contexts context) { public SortedSet<LocalizedNode> getAllNodes(List<String> excludedGroups, ExtractedContexts contexts) {
SortedSet<LocalizedNode> all = new TreeSet<>((SortedSet<LocalizedNode>) getPermissions(true)); SortedSet<LocalizedNode> all = new TreeSet<>((SortedSet<LocalizedNode>) getPermissions(true));
if (excludedGroups == null) { if (excludedGroups == null) {
@ -259,16 +259,14 @@ public abstract class PermissionHolder {
.filter(Node::isGroupNode) .filter(Node::isGroupNode)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
MutableContextSet contexts = MutableContextSet.fromSet(context.getContexts()); Contexts context = contexts.getContexts();
String server = contexts.getValues("server").stream().findAny().orElse(null); String server = contexts.getServer();
String world = contexts.getValues("world").stream().findAny().orElse(null); String world = contexts.getWorld();
contexts.removeAll("server");
contexts.removeAll("world");
parents.removeIf(node -> parents.removeIf(node ->
!node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) || !node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) || !node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyWithContext(contexts, false) !node.shouldApplyWithContext(contexts.getContextSet(), false)
); );
TreeSet<Map.Entry<Integer, Node>> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed()); TreeSet<Map.Entry<Integer, Node>> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed());
@ -293,7 +291,7 @@ public abstract class PermissionHolder {
} }
inherited: inherited:
for (LocalizedNode inherited : group.getAllNodes(excludedGroups, context)) { for (LocalizedNode inherited : group.getAllNodes(excludedGroups, contexts)) {
for (LocalizedNode existing : all) { for (LocalizedNode existing : all) {
if (existing.getNode().almostEquals(inherited.getNode())) { if (existing.getNode().almostEquals(inherited.getNode())) {
continue inherited; continue inherited;
@ -307,7 +305,7 @@ public abstract class PermissionHolder {
return all; return all;
} }
public MetaHolder accumulateMeta(MetaHolder holder, List<String> excludedGroups, Contexts context) { public MetaHolder accumulateMeta(MetaHolder holder, List<String> excludedGroups, ExtractedContexts contexts) {
if (holder == null) { if (holder == null) {
holder = new MetaHolder(); holder = new MetaHolder();
} }
@ -318,11 +316,9 @@ public abstract class PermissionHolder {
excludedGroups.add(getObjectName().toLowerCase()); excludedGroups.add(getObjectName().toLowerCase());
MutableContextSet contexts = MutableContextSet.fromSet(context.getContexts()); Contexts context = contexts.getContexts();
String server = contexts.getValues("server").stream().findAny().orElse(null); String server = contexts.getServer();
String world = contexts.getValues("world").stream().findAny().orElse(null); String world = contexts.getWorld();
contexts.removeAll("server");
contexts.removeAll("world");
SortedSet<LocalizedNode> all = new TreeSet<>((SortedSet<LocalizedNode>) getPermissions(true)); SortedSet<LocalizedNode> all = new TreeSet<>((SortedSet<LocalizedNode>) getPermissions(true));
for (LocalizedNode ln : all) { for (LocalizedNode ln : all) {
@ -332,7 +328,7 @@ public abstract class PermissionHolder {
if (!n.isMeta() && !n.isPrefix() && !n.isSuffix()) continue; if (!n.isMeta() && !n.isPrefix() && !n.isSuffix()) continue;
if (!n.shouldApplyOnServer(server, context.isIncludeGlobal(), false)) continue; if (!n.shouldApplyOnServer(server, context.isIncludeGlobal(), false)) continue;
if (!n.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), false)) continue; if (!n.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), false)) continue;
if (!n.shouldApplyWithContext(contexts, false)) continue; if (!n.shouldApplyWithContext(contexts.getContextSet(), false)) continue;
holder.accumulateNode(n); holder.accumulateNode(n);
} }
@ -346,7 +342,7 @@ public abstract class PermissionHolder {
parents.removeIf(node -> parents.removeIf(node ->
!node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) || !node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) || !node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyWithContext(contexts, false) !node.shouldApplyWithContext(contexts.getContextSet(), false)
); );
TreeSet<Map.Entry<Integer, Node>> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed()); TreeSet<Map.Entry<Integer, Node>> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed());
@ -370,7 +366,7 @@ public abstract class PermissionHolder {
continue; continue;
} }
group.accumulateMeta(holder, excludedGroups, context); group.accumulateMeta(holder, excludedGroups, contexts);
} }
return holder; return holder;
@ -378,28 +374,26 @@ public abstract class PermissionHolder {
/** /**
* Gets all of the nodes that this holder has (and inherits), given the context * Gets all of the nodes that this holder has (and inherits), given the context
* @param context the context for this request * @param contexts the context for this request
* @return a map of permissions * @return a map of permissions
*/ */
public Set<LocalizedNode> getAllNodesFiltered(Contexts context) { public Set<LocalizedNode> getAllNodesFiltered(ExtractedContexts contexts) {
SortedSet<LocalizedNode> allNodes; SortedSet<LocalizedNode> allNodes;
Contexts context = contexts.getContexts();
String server = contexts.getServer();
String world = contexts.getWorld();
if (context.isApplyGroups()) { if (context.isApplyGroups()) {
allNodes = getAllNodes(null, context); allNodes = getAllNodes(null, contexts);
} else { } else {
allNodes = new TreeSet<>((SortedSet<LocalizedNode>) getPermissions(true)); allNodes = new TreeSet<>((SortedSet<LocalizedNode>) getPermissions(true));
} }
MutableContextSet contexts = MutableContextSet.fromSet(context.getContexts());
String server = contexts.getValues("server").stream().findAny().orElse(null);
String world = contexts.getValues("world").stream().findAny().orElse(null);
contexts.removeAll("server");
contexts.removeAll("world");
allNodes.removeIf(node -> allNodes.removeIf(node ->
!node.shouldApplyOnServer(server, context.isIncludeGlobal(), plugin.getConfiguration().isApplyingRegex()) || !node.shouldApplyOnServer(server, context.isIncludeGlobal(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), plugin.getConfiguration().isApplyingRegex()) || !node.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyWithContext(contexts, false) !node.shouldApplyWithContext(contexts.getContextSet(), false)
); );
Set<LocalizedNode> perms = ConcurrentHashMap.newKeySet(); Set<LocalizedNode> perms = ConcurrentHashMap.newKeySet();
@ -420,14 +414,14 @@ public abstract class PermissionHolder {
} }
/** /**
* Converts the output of {@link #getAllNodesFiltered(Contexts)}, and expands shorthand perms * Converts the output of {@link #getAllNodesFiltered(ExtractedContexts)}, and expands shorthand perms
* @param context the context for this request * @param context the context for this request
* @return a map of permissions * @return a map of permissions
*/ */
public Map<String, Boolean> exportNodes(Contexts context, boolean lowerCase) { public Map<String, Boolean> exportNodes(Contexts context, boolean lowerCase) {
Map<String, Boolean> perms = new HashMap<>(); Map<String, Boolean> perms = new HashMap<>();
for (LocalizedNode ln : getAllNodesFiltered(context)) { for (LocalizedNode ln : getAllNodesFiltered(ExtractedContexts.generate(context))) {
Node node = ln.getNode(); Node node = ln.getNode();
perms.put(lowerCase ? node.getPermission().toLowerCase() : node.getPermission(), node.getValue()); perms.put(lowerCase ? node.getPermission().toLowerCase() : node.getPermission(), node.getValue());
@ -527,7 +521,7 @@ public abstract class PermissionHolder {
* @return the result of the lookup * @return the result of the lookup
*/ */
public InheritanceInfo inheritsPermissionInfo(Node node) { public InheritanceInfo inheritsPermissionInfo(Node node) {
for (LocalizedNode n : getAllNodes(null, Contexts.allowAll())) { for (LocalizedNode n : getAllNodes(null, ExtractedContexts.generate(Contexts.allowAll()))) {
if (n.getNode().almostEquals(node)) { if (n.getNode().almostEquals(node)) {
return InheritanceInfo.of(n); return InheritanceInfo.of(n);
} }

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.utils;
import lombok.Getter;
import lombok.ToString;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.MutableContextSet;
@Getter
@ToString
public class ExtractedContexts {
public static ExtractedContexts generate(Contexts contexts) {
return new ExtractedContexts(contexts);
}
public static ExtractedContexts generate(ContextSet contexts) {
return new ExtractedContexts(contexts);
}
private Contexts contexts;
private ContextSet contextSet;
private String server;
private String world;
private ExtractedContexts(Contexts context) {
this.contexts = context;
setup(context.getContexts());
}
private ExtractedContexts(ContextSet contexts) {
setup(contexts);
}
private void setup(ContextSet contexts) {
MutableContextSet contextSet = MutableContextSet.fromSet(contexts);
server = contextSet.getValues("server").stream().findAny().orElse(null);
world = contextSet.getValues("world").stream().findAny().orElse(null);
contextSet.removeAll("server");
contextSet.removeAll("world");
this.contextSet = contextSet.makeImmutable();
}
}

View File

@ -24,10 +24,10 @@ package me.lucko.luckperms.sponge.migration;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.MutableContextSet;
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;
import me.lucko.luckperms.common.core.PermissionHolder; import me.lucko.luckperms.common.core.PermissionHolder;
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.LuckPermsService; import me.lucko.luckperms.sponge.service.LuckPermsService;
import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.context.Context;
@ -47,11 +47,10 @@ public class MigrationUtils {
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : perms.entrySet()) { for (Map.Entry<Set<Context>, Map<String, Boolean>> e : perms.entrySet()) {
ContextSet context = LuckPermsService.convertContexts(e.getKey()); ContextSet context = LuckPermsService.convertContexts(e.getKey());
MutableContextSet contexts = MutableContextSet.fromSet(context); ExtractedContexts extractedContexts = ExtractedContexts.generate(context);
String server = contexts.getValues("server").stream().findAny().orElse(null); ContextSet contexts = extractedContexts.getContextSet();
String world = contexts.getValues("world").stream().findAny().orElse(null); String server = extractedContexts.getServer();
contexts.removeAll("server"); String world = extractedContexts.getWorld();
contexts.removeAll("world");
for (Map.Entry<String, Boolean> perm : e.getValue().entrySet()) { for (Map.Entry<String, Boolean> perm : e.getValue().entrySet()) {
try { try {
@ -66,11 +65,10 @@ public class MigrationUtils {
for (Map.Entry<Set<Context>, Map<String, String>> e : opts.entrySet()) { for (Map.Entry<Set<Context>, Map<String, String>> e : opts.entrySet()) {
ContextSet context = LuckPermsService.convertContexts(e.getKey()); ContextSet context = LuckPermsService.convertContexts(e.getKey());
MutableContextSet contexts = MutableContextSet.fromSet(context); ExtractedContexts extractedContexts = ExtractedContexts.generate(context);
String server = contexts.getValues("server").stream().findAny().orElse(null); ContextSet contexts = extractedContexts.getContextSet();
String world = contexts.getValues("world").stream().findAny().orElse(null); String server = extractedContexts.getServer();
contexts.removeAll("server"); String world = extractedContexts.getWorld();
contexts.removeAll("world");
for (Map.Entry<String, String> opt : e.getValue().entrySet()) { for (Map.Entry<String, String> opt : e.getValue().entrySet()) {
if (opt.getKey().equalsIgnoreCase("prefix")) { if (opt.getKey().equalsIgnoreCase("prefix")) {
@ -98,11 +96,10 @@ public class MigrationUtils {
for (Map.Entry<Set<Context>, List<Subject>> e : parents.entrySet()) { for (Map.Entry<Set<Context>, List<Subject>> e : parents.entrySet()) {
ContextSet context = LuckPermsService.convertContexts(e.getKey()); ContextSet context = LuckPermsService.convertContexts(e.getKey());
MutableContextSet contexts = MutableContextSet.fromSet(context); ExtractedContexts extractedContexts = ExtractedContexts.generate(context);
String server = contexts.getValues("server").stream().findAny().orElse(null); ContextSet contexts = extractedContexts.getContextSet();
String world = contexts.getValues("world").stream().findAny().orElse(null); String server = extractedContexts.getServer();
contexts.removeAll("server"); String world = extractedContexts.getWorld();
contexts.removeAll("world");
for (Subject s : e.getValue()) { for (Subject s : e.getValue()) {
if (!s.getContainingCollection().getIdentifier().equalsIgnoreCase(PermissionService.SUBJECTS_GROUP)) { if (!s.getContainingCollection().getIdentifier().equalsIgnoreCase(PermissionService.SUBJECTS_GROUP)) {

View File

@ -31,6 +31,7 @@ import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.sponge.timings.LPTiming; import me.lucko.luckperms.sponge.timings.LPTiming;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.permission.NodeTree; import org.spongepowered.api.service.permission.NodeTree;
@ -84,7 +85,7 @@ public class LuckPermsGroupSubject extends LuckPermsSubject {
@Override @Override
public Tristate getPermissionValue(ContextSet contexts, String permission) { public Tristate getPermissionValue(ContextSet contexts, String permission) {
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.GROUP_GET_PERMISSION_VALUE)) { try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.GROUP_GET_PERMISSION_VALUE)) {
Map<String, Boolean> permissions = group.getAllNodesFiltered(service.calculateContexts(contexts)).stream() Map<String, Boolean> permissions = group.getAllNodesFiltered(ExtractedContexts.generate(service.calculateContexts(contexts))).stream()
.map(LocalizedNode::getNode) .map(LocalizedNode::getNode)
.collect(Collectors.toMap(Node::getPermission, Node::getValue)); .collect(Collectors.toMap(Node::getPermission, Node::getValue));
@ -113,7 +114,7 @@ public class LuckPermsGroupSubject extends LuckPermsSubject {
@Override @Override
public List<Subject> getParents(ContextSet contexts) { public List<Subject> getParents(ContextSet contexts) {
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.GROUP_GET_PARENTS)) { try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.GROUP_GET_PARENTS)) {
List<Subject> subjects = group.getAllNodesFiltered(service.calculateContexts(contexts)).stream() List<Subject> subjects = group.getAllNodesFiltered(ExtractedContexts.generate(service.calculateContexts(contexts))).stream()
.map(LocalizedNode::getNode) .map(LocalizedNode::getNode)
.filter(Node::isGroupNode) .filter(Node::isGroupNode)
.map(Node::getGroupName) .map(Node::getGroupName)
@ -165,7 +166,7 @@ public class LuckPermsGroupSubject extends LuckPermsSubject {
int priority = Integer.MIN_VALUE; int priority = Integer.MIN_VALUE;
String meta = null; String meta = null;
for (Node n : group.getAllNodesFiltered(service.calculateContexts(contexts))) { for (Node n : group.getAllNodesFiltered(ExtractedContexts.generate(service.calculateContexts(contexts)))) {
if (!n.getValue()) { if (!n.getValue()) {
continue; continue;
} }
@ -185,7 +186,7 @@ public class LuckPermsGroupSubject extends LuckPermsSubject {
} }
private Optional<String> getMeta(ContextSet contexts, String key) { private Optional<String> getMeta(ContextSet contexts, String key) {
for (Node n : group.getAllNodesFiltered(service.calculateContexts(contexts))) { for (Node n : group.getAllNodesFiltered(ExtractedContexts.generate(service.calculateContexts(contexts)))) {
if (!n.getValue()) { if (!n.getValue()) {
continue; continue;
} }