Search in sources :

Example 1 with PermissionsPlugin

use of com.platymuus.bukkit.permissions.PermissionsPlugin in project LuckPerms by lucko.

the class MigrationPermissionsBukkit method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
    ProgressLogger log = new ProgressLogger("PermissionsBukkit");
    log.addListener(plugin.getConsoleSender());
    log.addListener(sender);
    log.log("Starting.");
    if (!Bukkit.getPluginManager().isPluginEnabled("PermissionsBukkit")) {
        log.logError("Plugin not loaded.");
        return CommandResult.STATE_ERROR;
    }
    PermissionsPlugin permissionsBukkit = (PermissionsPlugin) Bukkit.getPluginManager().getPlugin("PermissionsBukkit");
    FileConfiguration config = permissionsBukkit.getConfig();
    // Migrate all groups
    log.log("Starting group migration.");
    AtomicInteger groupCount = new AtomicInteger(0);
    ConfigurationSection groupsSection = config.getConfigurationSection("groups");
    Iterators.iterate(groupsSection.getKeys(false), key -> {
        final String groupName = MigrationUtils.standardizeName(key);
        Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
        // migrate data
        if (groupsSection.isConfigurationSection(key)) {
            migrate(lpGroup, groupsSection.getConfigurationSection(key));
        }
        plugin.getStorage().saveGroup(lpGroup).join();
        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);
    ConfigurationSection usersSection = config.getConfigurationSection("users");
    Iterators.iterate(usersSection.getKeys(false), key -> {
        UUID uuid = BukkitMigrationUtils.lookupUuid(log, key);
        if (uuid == null) {
            return;
        }
        User lpUser = plugin.getStorage().loadUser(uuid, null).join();
        // migrate data
        if (usersSection.isConfigurationSection(key)) {
            migrate(lpUser, usersSection.getConfigurationSection(key));
        }
        plugin.getUserManager().cleanup(lpUser);
        plugin.getStorage().saveUser(lpUser);
        log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
    });
    log.log("Migrated " + userCount.get() + " users.");
    log.log("Success! Migration complete.");
    return CommandResult.SUCCESS;
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User) PermissionsPlugin(com.platymuus.bukkit.permissions.PermissionsPlugin) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressLogger(me.lucko.luckperms.common.logging.ProgressLogger) UUID(java.util.UUID) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

PermissionsPlugin (com.platymuus.bukkit.permissions.PermissionsPlugin)1 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ProgressLogger (me.lucko.luckperms.common.logging.ProgressLogger)1 Group (me.lucko.luckperms.common.model.Group)1 User (me.lucko.luckperms.common.model.User)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1