use of net.luckperms.api.model.group.Group in project AuthMeReloaded by AuthMe.
the class LuckPermsHandler method sortGroups.
private int sortGroups(User user, LuckPermGroup o1, LuckPermGroup o2) {
Group group1 = o1.getGroup();
Group group2 = o2.getGroup();
if (group1.getName().equals(user.getPrimaryGroup()) || group2.getName().equals(user.getPrimaryGroup())) {
return group1.getName().equals(user.getPrimaryGroup()) ? 1 : -1;
}
int i = Integer.compare(group2.getWeight().orElse(0), group1.getWeight().orElse(0));
return i != 0 ? i : group1.getName().compareToIgnoreCase(group2.getName());
}
use of net.luckperms.api.model.group.Group in project AuthMeReloaded by AuthMe.
the class LuckPermsHandler method getGroups.
@Override
public List<UserGroup> getGroups(OfflinePlayer player) {
String playerName = player.getName();
if (playerName == null) {
return Collections.emptyList();
}
User user = luckPerms.getUserManager().getUser(playerName);
if (user == null) {
logger.warning("LuckPermsHandler: tried to get groups for offline user " + player.getName() + " but it isn't loaded!");
return Collections.emptyList();
}
return user.getDistinctNodes().stream().filter(node -> node instanceof InheritanceNode).map(node -> (InheritanceNode) node).map(node -> {
Group group = luckPerms.getGroupManager().getGroup(node.getGroupName());
if (group == null) {
return null;
}
return new LuckPermGroup(group, node.getContexts());
}).filter(Objects::nonNull).sorted((o1, o2) -> sortGroups(user, o1, o2)).map(g -> new UserGroup(g.getGroup().getName(), g.getContexts().toFlattenedMap())).collect(Collectors.toList());
}
use of net.luckperms.api.model.group.Group in project AuthMeReloaded by AuthMe.
the class LuckPermsHandler method addToGroup.
@Override
public boolean addToGroup(OfflinePlayer player, UserGroup group) {
Group newGroup = luckPerms.getGroupManager().getGroup(group.getGroupName());
if (newGroup == null) {
return false;
}
String playerName = player.getName();
if (playerName == null) {
return false;
}
User user = luckPerms.getUserManager().getUser(playerName);
if (user == null) {
return false;
}
InheritanceNode node = buildGroupNode(group);
DataMutateResult result = user.data().add(node);
if (result == DataMutateResult.FAIL) {
return false;
}
luckPerms.getUserManager().saveUser(user);
return true;
}
Aggregations