Search in sources :

Example 1 with ChildCommand

use of me.lucko.luckperms.common.command.abstraction.ChildCommand in project LuckPerms by lucko.

the class SpongeParentCommand method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, Void v, ArgumentList args, String label) {
    LuckPermsService service = this.plugin.getService();
    if (args.size() < 1) {
        SpongeCommandUtils.sendPrefixed(sender, "&aCurrent Subject Collections:\n" + SpongeCommandUtils.toCommaSep(service.getLoadedCollections().keySet().stream().filter(s -> !s.equalsIgnoreCase("user") && !s.equalsIgnoreCase("group")).sorted().collect(Collectors.toList())));
        return;
    }
    String subjectCollection = args.get(0);
    if (subjectCollection.equalsIgnoreCase("user") || subjectCollection.equalsIgnoreCase("group")) {
        SpongeCommandUtils.sendPrefixed(sender, "Please use the main LuckPerms commands to edit users and groups.");
        return;
    }
    if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(subjectCollection))) {
        SpongeCommandUtils.sendPrefixed(sender, "Warning: SubjectCollection '&4" + subjectCollection + "&c' doesn't already exist. Creating it now.");
    }
    LPSubjectCollection collection = service.getCollection(subjectCollection);
    if (args.size() < 2) {
        List<String> subjects = collection.getLoadedSubjects().stream().map(lpSubject -> lpSubject.getIdentifier().getName()).collect(Collectors.toList());
        if (subjects.size() > 50) {
            List<String> extra = subjects.subList(50, subjects.size());
            int overflow = extra.size();
            extra.clear();
            SpongeCommandUtils.sendPrefixed(sender, "&aCurrent Subjects:\n" + SpongeCommandUtils.toCommaSep(subjects) + "&b ... and &a" + overflow + " &bmore.");
        } else {
            SpongeCommandUtils.sendPrefixed(sender, "&aCurrent Subjects:\n" + SpongeCommandUtils.toCommaSep(subjects));
        }
        return;
    }
    if (args.size() < 4) {
        sendDetailedUsage(sender, label);
        return;
    }
    boolean persistent = true;
    if (args.get(2).toLowerCase(Locale.ROOT).startsWith("-t")) {
        persistent = false;
        args.remove(2);
    }
    String type = args.get(2).toLowerCase(Locale.ROOT);
    if (!type.equals("permission") && !type.equals("parent") && !type.equals("option")) {
        sendDetailedUsage(sender, label);
        return;
    }
    String cmd = args.get(3);
    ChildCommand<LPSubjectData> sub = this.children.get(type).stream().filter(s -> s.getName().equalsIgnoreCase(cmd)).findAny().orElse(null);
    if (sub == null) {
        sendDetailedUsage(sender, label);
        return;
    }
    if (!sub.isAuthorized(sender)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    if (sub.getArgumentCheck().test(args.size() - 4)) {
        sub.sendDetailedUsage(sender, label);
        return;
    }
    String subjectId = args.get(1);
    if (!collection.hasRegistered(subjectId).join()) {
        SpongeCommandUtils.sendPrefixed(sender, "Warning: Subject '&4" + subjectId + "&c' doesn't already exist. Creating it now.");
    }
    LPSubject subject = collection.loadSubject(subjectId).join();
    LPSubjectData subjectData = persistent ? subject.getSubjectData() : subject.getTransientSubjectData();
    try {
        sub.execute(plugin, sender, subjectData, args.subList(4, args.size()), label);
    } catch (CommandException e) {
        e.handle(sender, label, sub);
    }
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) Arrays(java.util.Arrays) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) ImmutableMap(com.google.common.collect.ImmutableMap) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) Sender(me.lucko.luckperms.common.sender.Sender) Command(me.lucko.luckperms.common.command.abstraction.Command) Collectors(java.util.stream.Collectors) Message(me.lucko.luckperms.common.locale.Message) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) Map(java.util.Map) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ChildCommand(me.lucko.luckperms.common.command.abstraction.ChildCommand) LPSpongePlugin(me.lucko.luckperms.sponge.LPSpongePlugin) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 ChildCommand (me.lucko.luckperms.common.command.abstraction.ChildCommand)1 Command (me.lucko.luckperms.common.command.abstraction.Command)1 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)1 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)1 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)1 Message (me.lucko.luckperms.common.locale.Message)1 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)1 Sender (me.lucko.luckperms.common.sender.Sender)1 Predicates (me.lucko.luckperms.common.util.Predicates)1 LPSpongePlugin (me.lucko.luckperms.sponge.LPSpongePlugin)1 LuckPermsService (me.lucko.luckperms.sponge.service.LuckPermsService)1 LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)1 LPSubjectCollection (me.lucko.luckperms.sponge.service.model.LPSubjectCollection)1