Search in sources :

Example 16 with Sender

use of me.lucko.luckperms.common.sender.Sender in project LuckPerms by lucko.

the class MigrationPermissionsEx method execute.

@SuppressWarnings("deprecation")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
    ProgressLogger log = new ProgressLogger("PermissionsEx");
    log.addListener(plugin.getConsoleSender());
    log.addListener(sender);
    log.log("Starting.");
    if (!Bukkit.getPluginManager().isPluginEnabled("PermissionsEx")) {
        log.logError("Plugin not loaded.");
        return CommandResult.STATE_ERROR;
    }
    PermissionsEx pex = (PermissionsEx) Bukkit.getPluginManager().getPlugin("PermissionsEx");
    PermissionManager manager = pex.getPermissionsManager();
    log.log("Calculating group weightings.");
    int i = 0;
    for (PermissionGroup group : manager.getGroupList()) {
        i = Math.max(i, group.getRank());
    }
    int maxWeight = i + 5;
    // Migrate all groups.
    log.log("Starting group migration.");
    AtomicInteger groupCount = new AtomicInteger(0);
    Set<String> ladders = new HashSet<>();
    Iterators.iterate(manager.getGroupList(), group -> {
        int groupWeight = maxWeight - group.getRank();
        final String groupName = MigrationUtils.standardizeName(group.getName());
        Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
        MigrationUtils.setGroupWeight(lpGroup, groupWeight);
        // migrate data
        migrateEntity(group, lpGroup, groupWeight);
        // remember known ladders
        if (group.isRanked()) {
            ladders.add(group.getRankLadder().toLowerCase());
        }
        plugin.getStorage().saveGroup(lpGroup).join();
        log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
    });
    log.log("Migrated " + groupCount.get() + " groups");
    // Migrate all ladders/tracks.
    log.log("Starting tracks migration.");
    for (String rankLadder : ladders) {
        Track track = plugin.getStorage().createAndLoadTrack(rankLadder, CreationCause.INTERNAL).join();
        // Get a list of all groups in a ladder
        List<String> ladder = manager.getRankLadder(rankLadder).entrySet().stream().sorted(Comparator.<Map.Entry<Integer, PermissionGroup>>comparingInt(Map.Entry::getKey).reversed()).map(e -> MigrationUtils.standardizeName(e.getValue().getName())).collect(Collectors.toList());
        track.setGroups(ladder);
        plugin.getStorage().saveTrack(track);
    }
    log.log("Migrated " + ladders.size() + " tracks");
    // 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(manager.getUsers(), user -> {
        UUID u = BukkitMigrationUtils.lookupUuid(log, user.getIdentifier());
        if (u == null) {
            return;
        }
        // load in a user instance
        User lpUser = plugin.getStorage().loadUser(u, user.getName()).join();
        // migrate data
        migrateEntity(user, lpUser, userWeight);
        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 : SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) PermissionEntity(ru.tehkode.permissions.PermissionEntity) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) PermissionsEx(ru.tehkode.permissions.bukkit.PermissionsEx) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ProgressLogger(me.lucko.luckperms.common.logging.ProgressLogger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Method(java.lang.reflect.Method) Bukkit(org.bukkit.Bukkit) PermissionsData(ru.tehkode.permissions.PermissionsData) CreationCause(me.lucko.luckperms.api.event.cause.CreationCause) MigrationUtils(me.lucko.luckperms.common.commands.migration.MigrationUtils) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) PermissionGroup(ru.tehkode.permissions.PermissionGroup) Set(java.util.Set) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) PermissionManager(ru.tehkode.permissions.PermissionManager) UUID(java.util.UUID) Iterators(me.lucko.luckperms.common.utils.Iterators) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) PermissionUser(ru.tehkode.permissions.PermissionUser) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Track(me.lucko.luckperms.common.model.Track) List(java.util.List) Group(me.lucko.luckperms.common.model.Group) Comparator(java.util.Comparator) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) PermissionGroup(ru.tehkode.permissions.PermissionGroup) Group(me.lucko.luckperms.common.model.Group) PermissionUser(ru.tehkode.permissions.PermissionUser) User(me.lucko.luckperms.common.model.User) PermissionManager(ru.tehkode.permissions.PermissionManager) PermissionGroup(ru.tehkode.permissions.PermissionGroup) ProgressLogger(me.lucko.luckperms.common.logging.ProgressLogger) PermissionsEx(ru.tehkode.permissions.bukkit.PermissionsEx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UUID(java.util.UUID) Track(me.lucko.luckperms.common.model.Track) HashSet(java.util.HashSet)

Example 17 with Sender

use of me.lucko.luckperms.common.sender.Sender in project LuckPerms by lucko.

the class BungeeCommandExecutor method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
    List<String> arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
    this.manager.onCommand(lpSender, "lpb", arguments);
}
Also used : CommandSender(net.md_5.bungee.api.CommandSender) Sender(me.lucko.luckperms.common.sender.Sender)

Example 18 with Sender

use of me.lucko.luckperms.common.sender.Sender in project LuckPerms by lucko.

the class SpongeCommandExecutor method process.

@Nonnull
@Override
public CommandResult process(@Nonnull CommandSource source, @Nonnull String s) {
    Sender lpSender = this.plugin.getSenderFactory().wrap(source);
    List<String> arguments = processSelectors(source, CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(s)));
    onCommand(lpSender, "lp", arguments);
    return CommandResult.success();
}
Also used : Sender(me.lucko.luckperms.common.sender.Sender) Nonnull(javax.annotation.Nonnull)

Example 19 with Sender

use of me.lucko.luckperms.common.sender.Sender in project LuckPerms by lucko.

the class NukkitCommandExecutor method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
    onCommand(lpSender, label, new ArrayList<>(Arrays.asList(args)));
    return true;
}
Also used : Sender(me.lucko.luckperms.common.sender.Sender) CommandSender(cn.nukkit.command.CommandSender)

Aggregations

Sender (me.lucko.luckperms.common.sender.Sender)19 List (java.util.List)12 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)12 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)12 Collectors (java.util.stream.Collectors)11 CommandResult (me.lucko.luckperms.common.command.CommandResult)11 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)11 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)11 Predicates (me.lucko.luckperms.common.utils.Predicates)11 Message (me.lucko.luckperms.common.locale.message.Message)10 MessageUtils (me.lucko.luckperms.common.command.utils.MessageUtils)8 Map (java.util.Map)7 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 UUID (java.util.UUID)6 Node (me.lucko.luckperms.api.Node)6 SubCommand (me.lucko.luckperms.common.command.abstraction.SubCommand)6 ArgumentParser (me.lucko.luckperms.common.command.utils.ArgumentParser)6 Group (me.lucko.luckperms.common.model.Group)6 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)6