use of net.luckperms.api.model.user.User in project AuthMeReloaded by AuthMe.
the class LuckPermsHandler method hasPermissionOffline.
@Override
public boolean hasPermissionOffline(String name, PermissionNode node) {
User user = luckPerms.getUserManager().getUser(name);
if (user == null) {
logger.warning("LuckPermsHandler: tried to check permission for offline user " + name + " but it isn't loaded!");
return false;
}
CachedPermissionData permissionData = user.getCachedData().getPermissionData(QueryOptions.builder(QueryMode.CONTEXTUAL).build());
return permissionData.checkPermission(node.getNode()).asBoolean();
}
use of net.luckperms.api.model.user.User 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.user.User in project Almura by AlmuraDev.
the class PermissionsManager method onMovePlayerTeleport.
// This method is for new players getting started at Almura castle, once they leave there it will promose them to Survivor.
@Listener(order = Order.LAST)
public void onMovePlayerTeleport(final MoveEntityEvent.Teleport event, @Getter("getTargetEntity") final Player player) {
if (this.permApi != null && differentExtent(event.getFromTransform(), event.getToTransform())) {
final User user = this.permApi.getUserManager().getUser(player.getUniqueId());
// The purpose of this method is to upgrade people out of the default permissions group once they teleport off of Asgard (starting world).
if (user != null && user.getPrimaryGroup().equalsIgnoreCase(LUCK_PERMS_DEFAULT_GROUP)) {
final String command = "lp user " + player.getName() + " promote members";
this.commandManager.process(Sponge.getServer().getConsole(), command);
}
}
}
use of net.luckperms.api.model.user.User in project AuthMeReloaded by AuthMe.
the class LuckPermsHandler method setGroup.
@Override
public boolean setGroup(OfflinePlayer player, UserGroup group) {
String playerName = player.getName();
if (playerName == null) {
return false;
}
User user = luckPerms.getUserManager().getUser(playerName);
if (user == null) {
logger.warning("LuckPermsHandler: tried to set group for offline user " + player.getName() + " but it isn't loaded!");
return false;
}
InheritanceNode groupNode = buildGroupNode(group);
DataMutateResult result = user.data().add(groupNode);
if (result == DataMutateResult.FAIL) {
return false;
}
user.data().clear(node -> {
if (!(node instanceof InheritanceNode)) {
return false;
}
InheritanceNode inheritanceNode = (InheritanceNode) node;
return !inheritanceNode.equals(groupNode);
});
luckPerms.getUserManager().saveUser(user);
return true;
}
use of net.luckperms.api.model.user.User in project AuthMeReloaded by AuthMe.
the class LuckPermsHandler method isInGroup.
@Override
public boolean isInGroup(OfflinePlayer player, UserGroup group) {
String playerName = player.getName();
if (playerName == null) {
return false;
}
User user = luckPerms.getUserManager().getUser(playerName);
if (user == null) {
logger.warning("LuckPermsHandler: tried to check group for offline user " + player.getName() + " but it isn't loaded!");
return false;
}
InheritanceNode inheritanceNode = InheritanceNode.builder(group.getGroupName()).build();
return user.data().contains(inheritanceNode, NodeEqualityPredicate.EXACT).asBoolean();
}
Aggregations