Search in sources :

Example 1 with BungeePerms

use of net.alpenblock.bungeeperms.BungeePerms in project LuckPerms by lucko.

the class MigrationBungeePerms method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
    ProgressLogger log = new ProgressLogger("BungeePerms");
    log.addListener(plugin.getConsoleSender());
    log.addListener(sender);
    log.log("Starting.");
    // Get BungeePerms instance
    BungeePerms bp = BungeePerms.getInstance();
    if (bp == null) {
        log.logError("Plugin not loaded.");
        return CommandResult.STATE_ERROR;
    }
    List<Group> groups = bp.getPermissionsManager().getBackEnd().loadGroups();
    log.log("Calculating group weightings.");
    int i = 0;
    for (Group group : groups) {
        i = Math.max(i, group.getRank());
    }
    int maxWeight = i + 5;
    // Migrate all groups.
    log.log("Starting group migration.");
    AtomicInteger groupCount = new AtomicInteger(0);
    Iterators.iterate(groups, g -> {
        int groupWeight = maxWeight - g.getRank();
        // Make a LuckPerms group for the one being migrated
        String groupName = MigrationUtils.standardizeName(g.getName());
        me.lucko.luckperms.common.model.Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
        MigrationUtils.setGroupWeight(group, groupWeight);
        migrateHolder(g, g.getInheritances(), groupWeight, group);
        plugin.getStorage().saveGroup(group);
        log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
    });
    log.log("Migrated " + groupCount.get() + " groups");
    // Migrate all users.
    log.log("Starting user migration.");
    AtomicInteger userCount = new AtomicInteger(0);
    // Increment the max weight from the group migrations. All user meta should override.
    int userWeight = maxWeight + 5;
    Iterators.iterate(bp.getPermissionsManager().getBackEnd().loadUsers(), u -> {
        if (u.getUUID() == null) {
            log.logError("Could not parse UUID for user: " + u.getName());
            return;
        }
        // Make a LuckPerms user for the one being migrated.
        me.lucko.luckperms.common.model.User user = plugin.getStorage().loadUser(u.getUUID(), u.getName()).join();
        migrateHolder(u, u.getGroupsString(), userWeight, user);
        plugin.getStorage().saveUser(user);
        plugin.getUserManager().cleanup(user);
        log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
    });
    log.log("Migrated " + userCount.get() + " users.");
    log.log("Success! Migration complete.");
    return CommandResult.SUCCESS;
}
Also used : Group(net.alpenblock.bungeeperms.Group) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressLogger(me.lucko.luckperms.common.logging.ProgressLogger) BungeePerms(net.alpenblock.bungeeperms.BungeePerms)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ProgressLogger (me.lucko.luckperms.common.logging.ProgressLogger)1 BungeePerms (net.alpenblock.bungeeperms.BungeePerms)1 Group (net.alpenblock.bungeeperms.Group)1