mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Add set-primary-group option to the default assignments
This commit is contained in:
parent
a4c872f1e8
commit
7b655d12df
@ -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.<name>" 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: <skyblock/group.sb_level1> & <skyblock/group.sb_level2> & <skyblock/group.sb_level3>
|
||||
# give:
|
||||
# - skyblock/group.sb_level1
|
||||
# - skyblock/group.sb_level1
|
||||
# rule3:
|
||||
# if:
|
||||
# has-true: <group.default>
|
||||
# take:
|
||||
# - group.default
|
||||
# give:
|
||||
# - group.member
|
||||
# set-primary-group: member
|
@ -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.<name>" 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: <skyblock/group.sb_level1> & <skyblock/group.sb_level2> & <skyblock/group.sb_level3>
|
||||
# give:
|
||||
# - skyblock/group.sb_level1
|
||||
# - skyblock/group.sb_level1
|
||||
# rule3:
|
||||
# if:
|
||||
# has-true: <group.default>
|
||||
# take:
|
||||
# - group.default
|
||||
# give:
|
||||
# - group.member
|
||||
# set-primary-group: member
|
@ -121,7 +121,8 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
|
||||
String lacks = getString("default-assignments." + ruleName + ".if.lacks", null);
|
||||
List<String> give = getList("default-assignments." + ruleName + ".give", new ArrayList<>());
|
||||
List<String> 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();
|
||||
|
||||
|
@ -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<String> toGive;
|
||||
private final List<String> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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.<name>" 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="<group.default>"
|
||||
# }
|
||||
# take = [
|
||||
# "group.default"
|
||||
# ]
|
||||
# give = [
|
||||
# "group.member"
|
||||
# ]
|
||||
# set-primary-group="member"
|
||||
# }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user