Search in sources :

Example 1 with LuckPermsPlugin

use of me.lucko.luckperms.common.plugin.LuckPermsPlugin in project LuckPerms by lucko.

the class SpongeMainCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) {
    LuckPermsService service = this.plugin.getService();
    if (args.size() < 1) {
        MessageUtils.sendPluginMessage(sender, "&aCurrent Subject Collections:\n" + MessageUtils.toCommaSep(service.getLoadedCollections().keySet().stream().filter(s -> !s.equalsIgnoreCase("user") && !s.equalsIgnoreCase("group")).sorted().collect(Collectors.toList())));
        return CommandResult.SUCCESS;
    }
    String subjectCollection = args.get(0);
    if (subjectCollection.equalsIgnoreCase("user") || subjectCollection.equalsIgnoreCase("group")) {
        MessageUtils.sendPluginMessage(sender, "Please use the main LuckPerms commands to edit users and groups.");
        return CommandResult.STATE_ERROR;
    }
    if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(subjectCollection))) {
        MessageUtils.sendPluginMessage(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::getIdentifier).collect(Collectors.toList());
        if (subjects.size() > 50) {
            List<String> extra = subjects.subList(50, subjects.size());
            int overflow = extra.size();
            extra.clear();
            MessageUtils.sendPluginMessage(sender, "&aCurrent Subjects:\n" + MessageUtils.toCommaSep(subjects) + "&b ... and &a" + overflow + " &bmore.");
        } else {
            MessageUtils.sendPluginMessage(sender, "&aCurrent Subjects:\n" + MessageUtils.toCommaSep(subjects));
        }
        return CommandResult.SUCCESS;
    }
    if (args.size() < 4) {
        sendDetailedUsage(sender, label);
        return CommandResult.SUCCESS;
    }
    boolean persistent = true;
    if (args.get(2).toLowerCase().startsWith("-t")) {
        persistent = false;
        args.remove(2);
    }
    String type = args.get(2).toLowerCase();
    if (!type.equals("permission") && !type.equals("parent") && !type.equals("option")) {
        sendDetailedUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    String cmd = args.get(3);
    Optional<Command<LPSubjectData, ?>> o = this.subCommands.get(type).stream().filter(s -> s.getName().equalsIgnoreCase(cmd)).findAny();
    if (!o.isPresent()) {
        sendDetailedUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    final Command<LPSubjectData, ?> sub = o.get();
    if (!sub.isAuthorized(sender)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    List<String> strippedArgs = new ArrayList<>();
    if (args.size() > 4) {
        strippedArgs.addAll(args.subList(4, args.size()));
    }
    if (sub.getArgumentCheck().test(strippedArgs.size())) {
        sub.sendDetailedUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    String subjectId = args.get(1);
    if (!collection.hasRegistered(subjectId).join()) {
        MessageUtils.sendPluginMessage(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();
    CommandResult result;
    try {
        result = sub.execute(plugin, sender, subjectData, strippedArgs, label);
    } catch (CommandException e) {
        result = CommandManager.handleException(e, sender, label, sub);
    }
    return result;
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) Arrays(java.util.Arrays) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) Command(me.lucko.luckperms.common.command.abstraction.Command) ArrayList(java.util.ArrayList) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Nonnull(javax.annotation.Nonnull) CommandManager(me.lucko.luckperms.common.command.CommandManager) ImmutableMap(com.google.common.collect.ImmutableMap) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) Sender(me.lucko.luckperms.common.sender.Sender) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) ImmutableCollectors(me.lucko.luckperms.common.utils.ImmutableCollectors) List(java.util.List) Optional(java.util.Optional) LPSpongePlugin(me.lucko.luckperms.sponge.LPSpongePlugin) Predicates(me.lucko.luckperms.common.utils.Predicates) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) ArrayList(java.util.ArrayList) CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) CommandResult(me.lucko.luckperms.common.command.CommandResult) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) Command(me.lucko.luckperms.common.command.abstraction.Command) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject)

Example 2 with LuckPermsPlugin

use of me.lucko.luckperms.common.plugin.LuckPermsPlugin in project LuckPerms by lucko.

the class UserDemote method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), user)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    final String trackName = args.get(0).toLowerCase();
    if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
        Message.TRACK_INVALID_ENTRY.send(sender, trackName);
        return CommandResult.INVALID_ARGS;
    }
    Track track = StorageAssistant.loadTrack(trackName, sender, plugin);
    if (track == null) {
        return CommandResult.LOADING_ERROR;
    }
    if (track.getSize() <= 1) {
        Message.TRACK_EMPTY.send(sender, track.getName());
        return CommandResult.STATE_ERROR;
    }
    boolean silent = args.remove("-s");
    MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    // Load applicable groups
    Set<Node> nodes = user.getEnduringNodes().values().stream().filter(Node::isGroupNode).filter(Node::getValuePrimitive).filter(node -> node.getFullContexts().makeImmutable().equals(context.makeImmutable())).collect(Collectors.toSet());
    nodes.removeIf(g -> !track.containsGroup(g.getGroupName()));
    if (nodes.isEmpty()) {
        Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender, user.getFriendlyName(), track.getName());
        return CommandResult.FAILURE;
    }
    if (nodes.size() != 1) {
        Message.TRACK_AMBIGUOUS_CALL.send(sender, user.getFriendlyName());
        return CommandResult.FAILURE;
    }
    final Node oldNode = Iterables.getFirst(nodes, null);
    final String old = oldNode.getGroupName();
    final String previous;
    try {
        previous = track.getPrevious(old);
    } catch (IllegalArgumentException e) {
        Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), old);
        return CommandResult.STATE_ERROR;
    }
    if (ArgumentPermissions.checkArguments(plugin, sender, getPermission().get(), track.getName(), oldNode.getGroupName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (previous == null) {
        user.unsetPermission(oldNode);
        Message.USER_DEMOTE_ENDOFTRACK.send(sender, track.getName(), user.getFriendlyName(), old);
        ExtendedLogEntry.build().actor(sender).acted(user).action("demote", track.getName(), context).build().submit(plugin, sender);
        StorageAssistant.save(user, sender, plugin);
        plugin.getEventFactory().handleUserDemote(user, track, old, null, sender);
        return CommandResult.SUCCESS;
    }
    Group previousGroup = plugin.getStorage().loadGroup(previous).join().orElse(null);
    if (previousGroup == null) {
        Message.USER_DEMOTE_ERROR_MALFORMED.send(sender, previous);
        return CommandResult.LOADING_ERROR;
    }
    user.unsetPermission(oldNode);
    user.setPermission(NodeFactory.buildGroupNode(previousGroup.getName()).withExtraContext(context).build());
    if (context.isEmpty() && user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME).equalsIgnoreCase(old)) {
        user.getPrimaryGroup().setStoredValue(previousGroup.getName());
    }
    Message.USER_DEMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), old, previousGroup.getFriendlyName(), MessageUtils.contextSetToString(context));
    if (!silent) {
        Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), previousGroup.getName(), old, true));
    }
    ExtendedLogEntry.build().actor(sender).acted(user).action("demote", track.getName(), context).build().submit(plugin, sender);
    StorageAssistant.save(user, sender, plugin);
    plugin.getEventFactory().handleUserDemote(user, track, old, previousGroup.getName(), sender);
    return CommandResult.SUCCESS;
}
Also used : Iterables(com.google.common.collect.Iterables) CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ExtendedLogEntry(me.lucko.luckperms.common.actionlog.ExtendedLogEntry) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) Set(java.util.Set) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Track(me.lucko.luckperms.common.model.Track) List(java.util.List) TabCompletions(me.lucko.luckperms.common.command.utils.TabCompletions) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) DataConstraints(me.lucko.luckperms.common.storage.DataConstraints) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) Group(me.lucko.luckperms.common.model.Group) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Node(me.lucko.luckperms.api.Node) Track(me.lucko.luckperms.common.model.Track)

Example 3 with LuckPermsPlugin

use of me.lucko.luckperms.common.plugin.LuckPermsPlugin in project LuckPerms by lucko.

the class UserPromote method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), user)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    final String trackName = args.get(0).toLowerCase();
    if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
        Message.TRACK_INVALID_ENTRY.send(sender, trackName);
        return CommandResult.INVALID_ARGS;
    }
    Track track = StorageAssistant.loadTrack(trackName, sender, plugin);
    if (track == null) {
        return CommandResult.LOADING_ERROR;
    }
    if (track.getSize() <= 1) {
        Message.TRACK_EMPTY.send(sender, track.getName());
        return CommandResult.STATE_ERROR;
    }
    boolean silent = args.remove("-s");
    MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    // Load applicable groups
    Set<Node> nodes = user.getEnduringNodes().values().stream().filter(Node::isGroupNode).filter(Node::getValuePrimitive).filter(node -> node.getFullContexts().makeImmutable().equals(context.makeImmutable())).collect(Collectors.toSet());
    nodes.removeIf(g -> !track.containsGroup(g.getGroupName()));
    if (nodes.isEmpty()) {
        String first = track.getGroups().get(0);
        Group nextGroup = plugin.getGroupManager().getIfLoaded(first);
        if (nextGroup == null) {
            Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, first);
            return CommandResult.LOADING_ERROR;
        }
        if (ArgumentPermissions.checkArguments(plugin, sender, getPermission().get(), track.getName(), nextGroup.getName())) {
            Message.COMMAND_NO_PERMISSION.send(sender);
            return CommandResult.NO_PERMISSION;
        }
        user.setPermission(NodeFactory.buildGroupNode(nextGroup.getId()).withExtraContext(context).build());
        Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getFriendlyName(), nextGroup.getFriendlyName(), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(user).action("promote", track.getName(), context).build().submit(plugin, sender);
        StorageAssistant.save(user, sender, plugin);
        plugin.getEventFactory().handleUserPromote(user, track, null, first, sender);
        return CommandResult.SUCCESS;
    }
    if (nodes.size() != 1) {
        Message.TRACK_AMBIGUOUS_CALL.send(sender, user.getFriendlyName());
        return CommandResult.FAILURE;
    }
    final Node oldNode = nodes.stream().findAny().get();
    final String old = oldNode.getGroupName();
    final String next;
    try {
        next = track.getNext(old);
    } catch (IllegalArgumentException e) {
        Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), old);
        return CommandResult.STATE_ERROR;
    }
    if (next == null) {
        Message.USER_PROMOTE_ERROR_ENDOFTRACK.send(sender, track.getName(), user.getFriendlyName());
        return CommandResult.STATE_ERROR;
    }
    if (!plugin.getStorage().loadGroup(next).join().isPresent()) {
        Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next);
        return CommandResult.STATE_ERROR;
    }
    Group nextGroup = plugin.getGroupManager().getIfLoaded(next);
    if (nextGroup == null) {
        Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, next);
        return CommandResult.LOADING_ERROR;
    }
    if (ArgumentPermissions.checkArguments(plugin, sender, getPermission().get(), track.getName(), nextGroup.getName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    user.unsetPermission(oldNode);
    user.setPermission(NodeFactory.buildGroupNode(nextGroup.getName()).withExtraContext(context).build());
    if (context.isEmpty() && user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME).equalsIgnoreCase(old)) {
        user.getPrimaryGroup().setStoredValue(nextGroup.getName());
    }
    Message.USER_PROMOTE_SUCCESS.send(sender, user.getFriendlyName(), track.getName(), old, nextGroup.getFriendlyName(), MessageUtils.contextSetToString(context));
    if (!silent) {
        Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), old, nextGroup.getName(), false));
    }
    ExtendedLogEntry.build().actor(sender).acted(user).action("promote", track.getName(), context).build().submit(plugin, sender);
    StorageAssistant.save(user, sender, plugin);
    plugin.getEventFactory().handleUserPromote(user, track, old, nextGroup.getName(), sender);
    return CommandResult.SUCCESS;
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ExtendedLogEntry(me.lucko.luckperms.common.actionlog.ExtendedLogEntry) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) Set(java.util.Set) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Track(me.lucko.luckperms.common.model.Track) List(java.util.List) TabCompletions(me.lucko.luckperms.common.command.utils.TabCompletions) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) DataConstraints(me.lucko.luckperms.common.storage.DataConstraints) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) Group(me.lucko.luckperms.common.model.Group) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Node(me.lucko.luckperms.api.Node) Track(me.lucko.luckperms.common.model.Track)

Example 4 with LuckPermsPlugin

use of me.lucko.luckperms.common.plugin.LuckPermsPlugin in project LuckPerms by lucko.

the class DebugCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    Message.DEBUG_START.send(sender);
    StringBuilder sb = new StringBuilder();
    sb.append("LuckPerms Debug Output\n\n\n");
    BiConsumer<String, JObject> builder = (name, content) -> {
        sb.append("-- ").append(name).append(" --\n");
        sb.append(GSON.toJson(content.toJson()));
        sb.append("\n\n");
    };
    builder.accept("platform.json", getPlatformData(plugin));
    builder.accept("storage.json", getStorageData(plugin));
    builder.accept("context.json", getContextData(plugin));
    builder.accept("players.json", getPlayersData(plugin));
    Pastebin.Paste paste = StandardPastebin.HASTEBIN.postPlain(sb.toString());
    Message.DEBUG_URL.send(sender);
    Component message = TextComponent.builder(paste.url()).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(paste.url()))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the debugging data.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : LookupSetting(me.lucko.luckperms.api.LookupSetting) PermissionProcessor(me.lucko.luckperms.common.processors.PermissionProcessor) Contexts(me.lucko.luckperms.api.Contexts) MetaStackElement(me.lucko.luckperms.api.metastacking.MetaStackElement) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) HoverEvent(net.kyori.text.event.HoverEvent) GsonBuilder(com.google.gson.GsonBuilder) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) TextColor(net.kyori.text.format.TextColor) Gson(com.google.gson.Gson) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) BiConsumer(java.util.function.BiConsumer) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) JObject(me.lucko.luckperms.common.utils.gson.JObject) Pastebin(me.lucko.luckperms.common.web.Pastebin) ProxiedContextCalculator(me.lucko.luckperms.common.contexts.ProxiedContextCalculator) Collection(java.util.Collection) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Set(java.util.Set) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) StaticContextCalculator(me.lucko.luckperms.api.context.StaticContextCalculator) ContextSetJsonSerializer(me.lucko.luckperms.common.contexts.ContextSetJsonSerializer) TextComponent(net.kyori.text.TextComponent) JArray(me.lucko.luckperms.common.utils.gson.JArray) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) Component(net.kyori.text.Component) MetaStackDefinition(me.lucko.luckperms.api.metastacking.MetaStackDefinition) ContextCalculator(me.lucko.luckperms.api.context.ContextCalculator) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent) JObject(me.lucko.luckperms.common.utils.gson.JObject) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component) Pastebin(me.lucko.luckperms.common.web.Pastebin) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin)

Example 5 with LuckPermsPlugin

use of me.lucko.luckperms.common.plugin.LuckPermsPlugin in project LuckPerms by lucko.

the class HolderShowTracks method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    try {
        plugin.getStorage().loadAllTracks().get();
    } catch (Exception e) {
        e.printStackTrace();
        Message.TRACKS_LOAD_ERROR.send(sender);
        return CommandResult.LOADING_ERROR;
    }
    List<Map.Entry<Track, String>> lines = new ArrayList<>();
    if (holder.getType().isUser()) {
        // if the holder is a user, we want to query parent groups for tracks
        Set<Node> nodes = holder.getEnduringNodes().values().stream().filter(Node::isGroupNode).filter(Node::getValuePrimitive).filter(Node::isPermanent).collect(Collectors.toSet());
        for (Node node : nodes) {
            String groupName = node.getGroupName();
            List<Track> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(groupName)).collect(Collectors.toList());
            for (Track t : tracks) {
                lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName)));
            }
        }
    } else {
        // otherwise, just lookup for the actual group
        String groupName = ((Group) holder).getName();
        List<Track> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(groupName)).collect(Collectors.toList());
        for (Track t : tracks) {
            lines.add(Maps.immutableEntry(t, MessageUtils.listToArrowSep(t.getGroups(), groupName)));
        }
    }
    if (lines.isEmpty()) {
        Message.LIST_TRACKS_EMPTY.send(sender, holder.getFriendlyName());
        return CommandResult.SUCCESS;
    }
    Message.LIST_TRACKS.send(sender, holder.getFriendlyName());
    for (Map.Entry<Track, String> line : lines) {
        Message.LIST_TRACKS_ENTRY.send(sender, line.getKey().getName(), line.getValue());
    }
    return CommandResult.SUCCESS;
}
Also used : PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) Set(java.util.Set) Sender(me.lucko.luckperms.common.sender.Sender) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) ArrayList(java.util.ArrayList) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) Track(me.lucko.luckperms.common.model.Track) List(java.util.List) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) Group(me.lucko.luckperms.common.model.Group) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Node(me.lucko.luckperms.api.Node) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Predicates(me.lucko.luckperms.common.utils.Predicates) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) ArrayList(java.util.ArrayList) Map(java.util.Map) Track(me.lucko.luckperms.common.model.Track)

Aggregations

List (java.util.List)10 CommandResult (me.lucko.luckperms.common.command.CommandResult)10 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)10 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)10 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)10 Sender (me.lucko.luckperms.common.sender.Sender)10 Predicates (me.lucko.luckperms.common.utils.Predicates)10 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)9 Collectors (java.util.stream.Collectors)8 Message (me.lucko.luckperms.common.locale.message.Message)8 Set (java.util.Set)6 SubCommand (me.lucko.luckperms.common.command.abstraction.SubCommand)6 User (me.lucko.luckperms.common.model.User)6 Map (java.util.Map)5 Node (me.lucko.luckperms.api.Node)5 MessageUtils (me.lucko.luckperms.common.command.utils.MessageUtils)5 Group (me.lucko.luckperms.common.model.Group)5 Track (me.lucko.luckperms.common.model.Track)5 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)5 UUID (java.util.UUID)4