mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Try to find the most appropriate primary group before just adding a user to default - closes #506
This commit is contained in:
parent
5ac0f93214
commit
1baefaade4
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.managers;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
@ -128,22 +129,28 @@ public class GenericUserManager extends AbstractManager<UserIdentifier, User> im
|
|||||||
String pg = user.getPrimaryGroup().getValue();
|
String pg = user.getPrimaryGroup().getValue();
|
||||||
boolean has = false;
|
boolean has = false;
|
||||||
|
|
||||||
for (Node node : user.getEnduringNodes().values()) {
|
for (Node node : user.getEnduringNodes().get(ImmutableContextSet.empty())) {
|
||||||
if (node.hasSpecificContext()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.isGroupNode() && node.getGroupName().equalsIgnoreCase(pg)) {
|
if (node.isGroupNode() && node.getGroupName().equalsIgnoreCase(pg)) {
|
||||||
has = true;
|
has = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// need to find a new primary group for the user.
|
||||||
if (!has) {
|
if (!has) {
|
||||||
user.getPrimaryGroup().setStoredValue("default");
|
String group = user.getEnduringNodes().get(ImmutableContextSet.empty()).stream()
|
||||||
|
.filter(Node::isGroupNode)
|
||||||
|
.findFirst()
|
||||||
|
.map(Node::getGroupName)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
// if the group is null, it'll be resolved in the next step
|
||||||
|
if (group != null) {
|
||||||
|
user.getPrimaryGroup().setStoredValue(group);
|
||||||
work = true;
|
work = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check that all users are member of at least one group
|
// check that all users are member of at least one group
|
||||||
boolean hasGroup = false;
|
boolean hasGroup = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user