Try to find the most appropriate primary group before just adding a user to default - closes #506

This commit is contained in:
Luck 2017-10-22 09:16:04 +01:00
parent 5ac0f93214
commit 1baefaade4
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -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,20 +129,26 @@ 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()
work = true; .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;
}
} }
} }