Refactor Contexts class
This commit is contained in:
@@ -29,6 +29,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.caching.MetaContexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
@@ -215,14 +216,12 @@ public class DebugCommand extends SingleCommand {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static JObject serializeContextsSettings(Contexts contexts) {
|
||||
return new JObject()
|
||||
.add("op", contexts.isOp())
|
||||
.add("includeGlobal", contexts.isIncludeGlobal())
|
||||
.add("includeGlobalWorld", contexts.isIncludeGlobalWorld())
|
||||
.add("applyGroups", contexts.isApplyGroups())
|
||||
.add("applyGlobalGroups", contexts.isApplyGlobalGroups())
|
||||
.add("applyGlobalWorldGroups", contexts.isApplyGlobalWorldGroups());
|
||||
private static JArray serializeContextsSettings(Contexts contexts) {
|
||||
JArray array = new JArray();
|
||||
for (LookupSetting setting : contexts.getSettings()) {
|
||||
array.add(setting.name());
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static JObject serializeMetaContextsSettings(MetaContexts metaContexts) {
|
||||
|
||||
@@ -147,7 +147,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.common.inheritance;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.graph.Graph;
|
||||
import me.lucko.luckperms.common.graph.GraphTraversers;
|
||||
@@ -95,7 +96,7 @@ public interface InheritanceGraph extends Graph<PermissionHolder> {
|
||||
List<Node> nodes = holder.getOwnGroupNodes(this.context.getContexts());
|
||||
for (Node n : nodes) {
|
||||
// effectively: if not (we're applying global groups or it's specific anyways)
|
||||
if (!((this.context.isApplyGlobalGroups() || n.isServerSpecific()) && (this.context.isApplyGlobalWorldGroups() || n.isWorldSpecific()))) {
|
||||
if (!((this.context.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER) || n.isServerSpecific()) && (this.context.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD) || n.isWorldSpecific()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.google.common.collect.Multimap;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.NodeEqualityPredicate;
|
||||
import me.lucko.luckperms.api.StandardNodeEquality;
|
||||
@@ -422,7 +423,7 @@ public abstract class PermissionHolder {
|
||||
|
||||
private List<LocalizedNode> getAllEntries(Contexts context) {
|
||||
List<LocalizedNode> entries = new LinkedList<>();
|
||||
if (context.isApplyGroups()) {
|
||||
if (context.hasSetting(LookupSetting.RESOLVE_INHERITANCE)) {
|
||||
accumulateInheritancesTo(entries, context);
|
||||
} else {
|
||||
for (Node n : getOwnNodes(context.getContexts())) {
|
||||
@@ -431,10 +432,10 @@ public abstract class PermissionHolder {
|
||||
}
|
||||
}
|
||||
|
||||
if (!context.isIncludeGlobal()) {
|
||||
if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER)) {
|
||||
entries.removeIf(n -> !n.isGroupNode() && !n.isServerSpecific());
|
||||
}
|
||||
if (!context.isApplyGlobalWorldGroups()) {
|
||||
if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD)) {
|
||||
entries.removeIf(n -> !n.isGroupNode() && !n.isWorldSpecific());
|
||||
}
|
||||
|
||||
@@ -507,7 +508,7 @@ public abstract class PermissionHolder {
|
||||
if (!node.getValuePrimitive()) continue;
|
||||
if (!node.isMeta() && !node.isPrefix() && !node.isSuffix()) continue;
|
||||
|
||||
if (!((context.isIncludeGlobal() || node.isServerSpecific()) && (context.isIncludeGlobalWorld() || node.isWorldSpecific()))) {
|
||||
if (!((context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER) || node.isServerSpecific()) && (context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD) || node.isWorldSpecific()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user