Search in sources :

Example 1 with Permission

use of de.bananaco.bpermissions.api.Permission in project LuckPerms by lucko.

the class MigrationBPermissions method migrateHolder.

private static void migrateHolder(World world, Calculable c, PermissionHolder holder) {
    // Migrate the groups permissions in this world
    for (Permission p : c.getPermissions()) {
        if (p.name().isEmpty()) {
            continue;
        }
        holder.setPermission(NodeFactory.make(p.name(), p.isTrue(), "global", world.getName()));
        // Include any child permissions
        for (Map.Entry<String, Boolean> child : p.getChildren().entrySet()) {
            if (child.getKey().isEmpty()) {
                continue;
            }
            holder.setPermission(NodeFactory.make(child.getKey(), child.getValue(), "global", world.getName()));
        }
    }
    // Migrate any inherited groups
    c.getGroups().forEach(parent -> {
        String parentName = MigrationUtils.standardizeName(parent.getName());
        if (parent.getName().equalsIgnoreCase(world.getDefaultGroup())) {
            parentName = NodeFactory.DEFAULT_GROUP_NAME;
        }
        holder.setPermission(NodeFactory.make(NodeFactory.groupNode(parentName), true, "global", world.getName()));
    });
    // Migrate existing meta
    for (Map.Entry<String, String> meta : c.getMeta().entrySet()) {
        if (meta.getKey().isEmpty() || meta.getValue().isEmpty()) {
            continue;
        }
        if (meta.getKey().equalsIgnoreCase(NodeFactory.PREFIX_KEY) || meta.getKey().equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
            ChatMetaType type = ChatMetaType.valueOf(meta.getKey().toUpperCase());
            holder.setPermission(NodeFactory.buildChatMetaNode(type, c.getPriority(), meta.getValue()).setWorld(world.getName()).build());
            continue;
        }
        holder.setPermission(NodeFactory.buildMetaNode(meta.getKey(), meta.getValue()).setWorld(world.getName()).build());
    }
}
Also used : Permission(de.bananaco.bpermissions.api.Permission) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Map(java.util.Map)

Aggregations

Permission (de.bananaco.bpermissions.api.Permission)1 Map (java.util.Map)1 ChatMetaType (me.lucko.luckperms.api.ChatMetaType)1