From 7b655d12dfc8eb74249d89c9fc2f178b1239404b Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 17 Oct 2016 18:23:41 +0100 Subject: [PATCH] Add set-primary-group option to the default assignments --- bukkit/src/main/resources/config.yml | 20 ++++++++++++++++- bungee/src/main/resources/config.yml | 20 ++++++++++++++++- .../common/config/AbstractConfiguration.java | 3 ++- .../lucko/luckperms/common/defaults/Rule.java | 19 ++++++++++------ sponge/src/main/resources/luckperms.conf | 22 +++++++++++++++++++ 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index b2f5b2f70..bf9fd8af8 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -197,6 +197,16 @@ data: # rule2: # If the user isn't in any of the following groups on the skyblock server: sb_level1, sb_level2, sb_level3, then add # them to sb_level1 on the skyblock server. +# +# rule3: +# If the user is a member of the default group, remove them from default, add them to member, and set their primary group +# to member. +# +# WARNING: Unlike internal commands, this system does not ensure that a group exists before adding a user to it. +# It also does not unsure that a user is a member of a group before making that group their primary group. +# +# Before you use "give: group." or "set-primary-group", make sure that the group exists, and that the user is +# a member of the group. default-assignments: # rule1: # if: @@ -211,4 +221,12 @@ default-assignments: # if: # lacks: & & # give: -# - skyblock/group.sb_level1 \ No newline at end of file +# - skyblock/group.sb_level1 +# rule3: +# if: +# has-true: +# take: +# - group.default +# give: +# - group.member +# set-primary-group: member \ No newline at end of file diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml index f546e424d..0ccba752d 100644 --- a/bungee/src/main/resources/config.yml +++ b/bungee/src/main/resources/config.yml @@ -155,6 +155,16 @@ data: # rule2: # If the user isn't in any of the following groups on the skyblock server: sb_level1, sb_level2, sb_level3, then add # them to sb_level1 on the skyblock server. +# +# rule3: +# If the user is a member of the default group, remove them from default, add them to member, and set their primary group +# to member. +# +# WARNING: Unlike internal commands, this system does not ensure that a group exists before adding a user to it. +# It also does not unsure that a user is a member of a group before making that group their primary group. +# +# Before you use "give: group." or "set-primary-group", make sure that the group exists, and that the user is +# a member of the group. default-assignments: # rule1: # if: @@ -169,4 +179,12 @@ default-assignments: # if: # lacks: & & # give: -# - skyblock/group.sb_level1 \ No newline at end of file +# - skyblock/group.sb_level1 +# rule3: +# if: +# has-true: +# take: +# - group.default +# give: +# - group.member +# set-primary-group: member \ No newline at end of file diff --git a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java index 907accaee..87787fa7c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java @@ -121,7 +121,8 @@ public abstract class AbstractConfiguration implement String lacks = getString("default-assignments." + ruleName + ".if.lacks", null); List give = getList("default-assignments." + ruleName + ".give", new ArrayList<>()); List take = getList("default-assignments." + ruleName + ".take", new ArrayList<>()); - defs.add(new Rule(hasTrue, hasFalse, lacks, give, take)); + String pg = getString("default-assignments." + ruleName + ".set-primary-group", null); + defs.add(new Rule(hasTrue, hasFalse, lacks, give, take, pg)); } defaultAssignments = defs.build(); diff --git a/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java b/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java index 17ca9ff71..5bcfe0aa1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java +++ b/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java @@ -27,7 +27,7 @@ import lombok.Getter; import lombok.ToString; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.core.Node; -import me.lucko.luckperms.common.core.PermissionHolder; +import me.lucko.luckperms.common.users.User; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; @@ -43,11 +43,12 @@ public class Rule { private final List toGive; private final List toTake; + private final String setPrimaryGroup; - public boolean apply(PermissionHolder holder) { + public boolean apply(User user) { if (hasTrueExpression != null) { try { - boolean b = LogicParser.parse(hasTrueExpression, holder, Tristate.TRUE); + boolean b = LogicParser.parse(hasTrueExpression, user, Tristate.TRUE); if (!b) { // The holder does not meet this requirement return false; @@ -61,7 +62,7 @@ public class Rule { if (hasFalseExpression != null) { try { - boolean b = LogicParser.parse(hasFalseExpression, holder, Tristate.FALSE); + boolean b = LogicParser.parse(hasFalseExpression, user, Tristate.FALSE); if (!b) { // The holder does not meet this requirement return false; @@ -75,7 +76,7 @@ public class Rule { if (lacksExpression != null) { try { - boolean b = LogicParser.parse(lacksExpression, holder, Tristate.UNDEFINED); + boolean b = LogicParser.parse(lacksExpression, user, Tristate.UNDEFINED); if (!b) { // The holder does not meet this requirement return false; @@ -90,16 +91,20 @@ public class Rule { // The holder meets all of the requirements of this rule. for (String s : toTake) { try { - holder.unsetPermission(Node.fromSerialisedNode(s, true)); + user.unsetPermission(Node.fromSerialisedNode(s, true)); } catch (ObjectLacksException ignored) {} } for (String s : toGive) { try { - holder.setPermission(Node.fromSerialisedNode(s, true)); + user.setPermission(Node.fromSerialisedNode(s, true)); } catch (ObjectAlreadyHasException ignored) {} } + if (setPrimaryGroup != null) { + user.setPrimaryGroup(setPrimaryGroup); + } + return true; } } diff --git a/sponge/src/main/resources/luckperms.conf b/sponge/src/main/resources/luckperms.conf index 67f50d4d0..51387731a 100644 --- a/sponge/src/main/resources/luckperms.conf +++ b/sponge/src/main/resources/luckperms.conf @@ -156,6 +156,16 @@ data { # rule2: # If the user isn't in any of the following groups on the skyblock server: sb_level1, sb_level2, sb_level3, then add # them to sb_level1 on the skyblock server. +# +# rule3: +# If the user is a member of the default group, remove them from default, add them to member, and set their primary group +# to member. +# +# WARNING: Unlike internal commands, this system does not ensure that a group exists before adding a user to it. +# It also does not unsure that a user is a member of a group before making that group their primary group. +# +# Before you use "give: group." or "set-primary-group", make sure that the group exists, and that the user is +# a member of the group. default-assignments { # rule1 { # if { @@ -178,4 +188,16 @@ default-assignments { # "skyblock/group.sb_level1" # ] # } +# rule3 { +# if { +# has-true="" +# } +# take = [ +# "group.default" +# ] +# give = [ +# "group.member" +# ] +# set-primary-group="member" +# } }