From 030fb1262e549f190769e9fbf02c584c62a4a85a Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 8 May 2017 22:27:46 +0100 Subject: [PATCH] Fix being able to negate permissions/parents/meta in specific contexts --- .../common/core/model/PermissionHolder.java | 13 ++++++++----- .../luckperms/common/defaults/LogicParser.java | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index 9ff20761..84481f3c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -489,8 +489,9 @@ public abstract class PermissionHolder { List finalAccumulator = accumulator; // this allows you to negate parent permissions lower down the inheritance tree. + // we can negate parent groups in a specific context at this level and prevent them from being applied. // there's no way to distinct the stream below based on a custom comparator. - NodeTools.removeIgnoreValue(nodes.iterator()); + NodeTools.removeSamePermission(nodes.iterator()); nodes.stream() .filter(Node::getValue) @@ -612,6 +613,12 @@ public abstract class PermissionHolder { // get and add the objects own nodes List nodes = flattenAndMergeNodesToList(context.getContextSet()); + + // this allows you to negate parent permissions lower down the inheritance tree. + // it also allows you to negate meta in specific contexts and have it override. + // there's no way to distinct the stream below based on a custom comparator. + NodeTools.removeSamePermission(nodes.iterator()); + nodes.stream() .filter(Node::getValue) .filter(n -> n.isMeta() || n.isPrefix() || n.isSuffix()) @@ -623,10 +630,6 @@ public abstract class PermissionHolder { accumulator.accumulateWeight(w.getAsInt()); } - // this allows you to negate parent permissions lower down the inheritance tree. - // there's no way to distinct the stream below based on a custom comparator. - NodeTools.removeIgnoreValue(nodes.iterator()); - nodes.stream() .filter(Node::getValue) .filter(Node::isGroupNode) diff --git a/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java b/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java index 442723c8..83a53ace 100644 --- a/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java +++ b/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java @@ -39,11 +39,11 @@ public class LogicParser { public static boolean parse(String s, PermissionHolder holder, Tristate tristate) throws IllegalArgumentException { try { ScriptEngine engine = Scripting.getScriptEngine(); - - String expression = generateExpression(s, s1 -> holder.hasPermission(NodeFactory.fromSerializedNode(s1, true)) == tristate); if (engine == null) { throw new NullPointerException("script engine"); } + + String expression = generateExpression(s, s1 -> holder.hasPermission(NodeFactory.fromSerializedNode(s1, true)) == tristate); String result = engine.eval(expression).toString(); if (!result.equals("true") && !result.equals("false")) {