diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index b5c53bb51..e74d9b85c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -25,11 +25,9 @@ package me.lucko.luckperms.common.config; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import me.lucko.luckperms.common.command.utils.ArgumentParser; -import me.lucko.luckperms.common.defaultassignments.AssignmentRule; import me.lucko.luckperms.common.graph.TraversalAlgorithm; import me.lucko.luckperms.common.metastacking.SimpleMetaStackDefinition; import me.lucko.luckperms.common.metastacking.StandardStackElements; @@ -423,21 +421,6 @@ public final class ConfigKeys { */ public static final ConfigKey> GROUP_NAME_REWRITES = mapKey("group-name-rewrite"); - /** - * The default assignments being applied by the plugin - */ - public static final ConfigKey> DEFAULT_ASSIGNMENTS = customKey(c -> { - return c.getKeys("default-assignments", ImmutableList.of()).stream().map(name -> { - String hasTrue = c.getString("default-assignments." + name + ".if.has-true", null); - String hasFalse = c.getString("default-assignments." + name + ".if.has-false", null); - String lacks = c.getString("default-assignments." + name + ".if.lacks", null); - List give = ImmutableList.copyOf(c.getStringList("default-assignments." + name + ".give", ImmutableList.of())); - List take = ImmutableList.copyOf(c.getStringList("default-assignments." + name + ".take", ImmutableList.of())); - String pg = c.getString("default-assignments." + name + ".set-primary-group", null); - return new AssignmentRule(hasTrue, hasFalse, lacks, give, take, pg); - }).collect(ImmutableCollectors.toList()); - }); - /** * The database settings, username, password, etc for use by any database */ diff --git a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentExpression.java b/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentExpression.java deleted file mode 100644 index 791a2c129..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentExpression.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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.defaultassignments; - -import com.google.common.collect.ImmutableList; - -import me.lucko.luckperms.common.model.PermissionHolder; -import me.lucko.luckperms.common.node.factory.NodeFactory; -import me.lucko.luckperms.common.util.Scripting; - -import net.luckperms.api.model.DataType; -import net.luckperms.api.node.Node; -import net.luckperms.api.node.NodeEqualityPredicate; -import net.luckperms.api.node.Tristate; - -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import javax.script.ScriptEngine; - -public class AssignmentExpression { - - public static AssignmentExpression compile(String expression) { - if (expression == null) { - return null; - } - return new AssignmentExpression(expression); - } - - private final List expression; - - private AssignmentExpression(String expression) { - this.expression = generateExpression(expression); - } - - public boolean eval(PermissionHolder holder, Tristate tristate) throws IllegalArgumentException { - ScriptEngine engine = Scripting.getScriptEngine(); - if (engine == null) { - throw new NullPointerException("script engine"); - } - - Predicate checker = node -> holder.hasPermission(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY) == tristate; - - String exp = this.expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining()) - .replace("&", "&&").replace("|", "||"); - - try { - String result = engine.eval(exp).toString(); - - if (!result.equals("true") && !result.equals("false")) { - throw new IllegalArgumentException(); - } - - return Boolean.parseBoolean(result); - - } catch (Throwable t) { - throw new IllegalArgumentException(exp, t); - } - } - - private static List generateExpression(String input) { - ImmutableList.Builder exp = ImmutableList.builder(); - - while (true) { - int start = input.indexOf("<"); - int end = input.indexOf(">"); - if (start == -1 || end == -1) { - break; - } - - if (start != 0) { - Token before = new StringToken(input.substring(0, start)); - exp.add(before); - } - - String match = input.substring(start, end + 1); - String matchContent = match.substring(1, match.length() - 1); - - Token permission = new PermissionToken(matchContent); - exp.add(permission); - - input = input.substring(end + 1); - } - - if (!input.isEmpty()) { - exp.add(new StringToken(input)); - } - - return exp.build(); - } - - private interface Token { - String forExpression(Predicate checker); - } - - private static final class StringToken implements Token { - private final String string; - - private StringToken(String string) { - this.string = string; - } - - @Override - public String forExpression(Predicate checker) { - return this.string; - } - - @Override - public String toString() { - return this.string; - } - } - - private static final class PermissionToken implements Token { - private final String permission; - private final Node node; - - private PermissionToken(String permission) { - this.permission = permission; - this.node = NodeFactory.make(permission); - } - - @Override - public String forExpression(Predicate checker) { - return Boolean.toString(checker.test(this.node)); - } - - @Override - public String toString() { - return "<" + this.permission + ">"; - } - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentRule.java b/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentRule.java deleted file mode 100644 index 9af1d62f8..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/defaultassignments/AssignmentRule.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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.defaultassignments; - -import me.lucko.luckperms.common.model.User; -import me.lucko.luckperms.common.node.factory.NodeFactory; -import me.lucko.luckperms.common.util.ImmutableCollectors; - -import net.luckperms.api.model.DataType; -import net.luckperms.api.node.Node; -import net.luckperms.api.node.Tristate; - -import java.util.List; - -public class AssignmentRule { - private final AssignmentExpression hasTrueExpression; - private final AssignmentExpression hasFalseExpression; - private final AssignmentExpression lacksExpression; - - private final List toGive; - private final List toTake; - private final String setPrimaryGroup; - - public AssignmentRule(String hasTrueExpression, String hasFalseExpression, String lacksExpression, List toGive, List toTake, String setPrimaryGroup) { - this.hasTrueExpression = AssignmentExpression.compile(hasTrueExpression); - this.hasFalseExpression = AssignmentExpression.compile(hasFalseExpression); - this.lacksExpression = AssignmentExpression.compile(lacksExpression); - this.toGive = toGive.stream().map(s -> NodeFactory.make(s, true)).collect(ImmutableCollectors.toList()); - this.toTake = toTake.stream().map(s -> NodeFactory.make(s, true)).collect(ImmutableCollectors.toList()); - this.setPrimaryGroup = setPrimaryGroup; - } - - public boolean apply(User user) { - if (this.hasTrueExpression != null) { - try { - boolean b = this.hasTrueExpression.eval(user, Tristate.TRUE); - if (!b) { - // The holder does not meet this requirement - return false; - } - } catch (IllegalArgumentException e) { - // Couldn't parse - e.printStackTrace(); - return false; - } - } - - if (this.hasFalseExpression != null) { - try { - boolean b = this.hasFalseExpression.eval(user, Tristate.FALSE); - if (!b) { - // The holder does not meet this requirement - return false; - } - } catch (IllegalArgumentException e) { - // Couldn't parse - e.printStackTrace(); - return false; - } - } - - if (this.lacksExpression != null) { - try { - boolean b = this.lacksExpression.eval(user, Tristate.UNDEFINED); - if (!b) { - // The holder does not meet this requirement - return false; - } - } catch (IllegalArgumentException e) { - // Couldn't parse - e.printStackTrace(); - return false; - } - } - - // The holder meets all of the requirements of this rule. - for (Node n : this.toTake) { - user.unsetPermission(DataType.NORMAL, n); - } - - for (Node n : this.toGive) { - user.setPermission(DataType.NORMAL, n, true); - } - - if (this.setPrimaryGroup != null) { - user.getPrimaryGroup().setStoredValue(this.setPrimaryGroup); - } - - return true; - } - - public AssignmentExpression getHasTrueExpression() { - return this.hasTrueExpression; - } - - public AssignmentExpression getHasFalseExpression() { - return this.hasFalseExpression; - } - - public AssignmentExpression getLacksExpression() { - return this.lacksExpression; - } - - public List getToGive() { - return this.toGive; - } - - public List getToTake() { - return this.toTake; - } - - public String getSetPrimaryGroup() { - return this.setPrimaryGroup; - } - - @Override - public String toString() { - return "AssignmentRule(" + - "hasTrueExpression=" + this.getHasTrueExpression() + ", " + - "hasFalseExpression=" + this.getHasFalseExpression() + ", " + - "lacksExpression=" + this.getLacksExpression() + ", " + - "toGive=" + this.getToGive() + ", " + - "toTake=" + this.getToTake() + ", " + - "setPrimaryGroup=" + this.getSetPrimaryGroup() + ")"; - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java b/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java index 8cffe7010..2501bbf2b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/util/AbstractConnectionListener.java @@ -25,8 +25,6 @@ package me.lucko.luckperms.common.plugin.util; -import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.defaultassignments.AssignmentRule; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -106,19 +104,6 @@ public abstract class AbstractConnectionListener { throw new NullPointerException("User is null"); } - // Setup defaults for the user - boolean saveRequired = false; - for (AssignmentRule rule : this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_ASSIGNMENTS)) { - if (rule.apply(user)) { - saveRequired = true; - } - } - - // If they were given a default, persist the new assignments back to the storage. - if (saveRequired) { - this.plugin.getStorage().saveUser(user).join(); - } - final long time = System.currentTimeMillis() - startTime; if (time >= 1000) { this.plugin.getLogger().warn("Processing login for " + username + " took " + time + "ms.");