Search in sources :

Example 1 with PermissionUser

use of ru.tehkode.permissions.PermissionUser in project AuthMeReloaded by AuthMe.

the class PermissionsExHandler method addToGroup.

@Override
public boolean addToGroup(Player player, String group) {
    if (!PermissionsEx.getPermissionManager().getGroupNames().contains(group)) {
        return false;
    }
    PermissionUser user = PermissionsEx.getUser(player);
    user.addGroup(group);
    return true;
}
Also used : PermissionUser(ru.tehkode.permissions.PermissionUser)

Example 2 with PermissionUser

use of ru.tehkode.permissions.PermissionUser in project AuthMeReloaded by AuthMe.

the class PermissionsExHandler method setGroup.

@Override
public boolean setGroup(Player player, String group) {
    List<String> groups = new ArrayList<>();
    groups.add(group);
    PermissionUser user = permissionManager.getUser(player);
    user.setParentsIdentifier(groups);
    return true;
}
Also used : PermissionUser(ru.tehkode.permissions.PermissionUser) ArrayList(java.util.ArrayList)

Example 3 with PermissionUser

use of ru.tehkode.permissions.PermissionUser in project LuckPerms by lucko.

the class MigrationPermissionsEx method migrateEntity.

private static void migrateEntity(PermissionEntity entity, PermissionHolder holder, int weight) {
    // migrate permanent permissions
    for (Map.Entry<String, List<String>> worldData : getPermanentPermissions(entity).entrySet()) {
        String world = standardizeWorld(worldData.getKey());
        for (String node : worldData.getValue()) {
            if (node.isEmpty())
                continue;
            holder.setPermission(MigrationUtils.parseNode(node, true).setWorld(world).build());
        }
    }
    // migrate temporary permissions
    Map<String, List<String>> timedPermissions;
    Map<String, Long> timedPermissionsTime;
    try {
        // noinspection unchecked
        timedPermissions = (Map<String, List<String>>) TIMED_PERMISSIONS_FIELD.get(entity);
        // noinspection unchecked
        timedPermissionsTime = (Map<String, Long>) TIMED_PERMISSIONS_TIME_FIELD.get(entity);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    for (Map.Entry<String, List<String>> worldData : timedPermissions.entrySet()) {
        String world = standardizeWorld(worldData.getKey());
        for (String node : worldData.getValue()) {
            if (node.isEmpty())
                continue;
            long expiry = timedPermissionsTime.getOrDefault(Strings.nullToEmpty(world) + ":" + node, 0L);
            holder.setPermission(MigrationUtils.parseNode(node, true).setWorld(world).setExpiry(expiry).build());
        }
    }
    // migrate parents
    for (Map.Entry<String, List<PermissionGroup>> worldData : entity.getAllParents().entrySet()) {
        String world = standardizeWorld(worldData.getKey());
        // keep track of primary group
        String primary = null;
        int primaryWeight = Integer.MAX_VALUE;
        for (PermissionGroup parent : worldData.getValue()) {
            String parentName = parent.getName();
            long expiry = 0L;
            // check for temporary parent
            if (entity instanceof PermissionUser) {
                String expiryOption = entity.getOption("group-" + parentName + "-until", world);
                if (expiryOption != null) {
                    try {
                        expiry = Long.parseLong(expiryOption);
                    } catch (NumberFormatException e) {
                    // ignore
                    }
                }
            }
            holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(parentName)).setWorld(world).setExpiry(expiry).build());
            // migrate primary groups
            if (world == null && holder instanceof User && expiry == 0) {
                if (parent.getRank() < primaryWeight) {
                    primary = parent.getName();
                    primaryWeight = parent.getRank();
                }
            }
        }
        if (primary != null && !primary.isEmpty() && !primary.equalsIgnoreCase(NodeFactory.DEFAULT_GROUP_NAME)) {
            User user = ((User) holder);
            user.getPrimaryGroup().setStoredValue(primary);
            user.unsetPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build());
        }
    }
    // migrate prefix / suffix
    String prefix = entity.getOwnPrefix();
    String suffix = entity.getOwnSuffix();
    if (prefix != null && !prefix.isEmpty()) {
        holder.setPermission(NodeFactory.buildPrefixNode(weight, prefix).build());
    }
    if (suffix != null && !suffix.isEmpty()) {
        holder.setPermission(NodeFactory.buildSuffixNode(weight, suffix).build());
    }
    // migrate options
    for (Map.Entry<String, Map<String, String>> worldData : entity.getAllOptions().entrySet()) {
        String world = standardizeWorld(worldData.getKey());
        for (Map.Entry<String, String> opt : worldData.getValue().entrySet()) {
            if (opt.getKey() == null || opt.getKey().isEmpty() || opt.getValue() == null || opt.getValue().isEmpty()) {
                continue;
            }
            String key = opt.getKey().toLowerCase();
            boolean ignore = key.equals(NodeFactory.PREFIX_KEY) || key.equals(NodeFactory.SUFFIX_KEY) || key.equals(NodeFactory.WEIGHT_KEY) || key.equals("rank") || key.equals("rank-ladder") || key.equals("name") || key.equals("username") || (key.startsWith("group-") && key.endsWith("-until"));
            if (ignore) {
                continue;
            }
            holder.setPermission(NodeFactory.buildMetaNode(opt.getKey(), opt.getValue()).setWorld(world).build());
        }
    }
}
Also used : PermissionUser(ru.tehkode.permissions.PermissionUser) User(me.lucko.luckperms.common.model.User) PermissionGroup(ru.tehkode.permissions.PermissionGroup) PermissionUser(ru.tehkode.permissions.PermissionUser) List(java.util.List) Map(java.util.Map)

Example 4 with PermissionUser

use of ru.tehkode.permissions.PermissionUser in project AuthMeReloaded by AuthMe.

the class PermissionsExHandler method addToGroup.

@Override
public boolean addToGroup(OfflinePlayer player, UserGroup group) {
    if (!PermissionsEx.getPermissionManager().getGroupNames().contains(group)) {
        return false;
    }
    PermissionUser user = PermissionsEx.getUser(player.getName());
    user.addGroup(group.getGroupName());
    return true;
}
Also used : PermissionUser(ru.tehkode.permissions.PermissionUser)

Example 5 with PermissionUser

use of ru.tehkode.permissions.PermissionUser in project AuthMeReloaded by AuthMe.

the class PermissionsExHandler method removeFromGroup.

@Override
public boolean removeFromGroup(Player player, String group) {
    PermissionUser user = permissionManager.getUser(player);
    user.removeGroup(group);
    return true;
}
Also used : PermissionUser(ru.tehkode.permissions.PermissionUser)

Aggregations

PermissionUser (ru.tehkode.permissions.PermissionUser)7 ArrayList (java.util.ArrayList)2 List (java.util.List)1 Map (java.util.Map)1 User (me.lucko.luckperms.common.model.User)1 PermissionGroup (ru.tehkode.permissions.PermissionGroup)1