Search in sources :

Example 1 with Message

use of me.lucko.luckperms.common.locale.Message in project LuckPerms by lucko.

the class VerboseCommand method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
    if (args.isEmpty()) {
        sendUsage(sender, label);
        return;
    }
    VerboseHandler verboseHandler = plugin.getVerboseHandler();
    String mode = args.get(0).toLowerCase(Locale.ROOT);
    if (mode.equals("command") || mode.equals("cmd")) {
        if (args.size() < 3) {
            sendDetailedUsage(sender, label);
            return;
        }
        String name = args.get(1);
        Sender executor;
        if (name.equals("me") || name.equals("self") || name.equalsIgnoreCase(sender.getName())) {
            executor = sender;
        } else {
            if (!CommandPermission.VERBOSE_COMMAND_OTHERS.isAuthorized(sender)) {
                Message.COMMAND_NO_PERMISSION.send(sender);
                return;
            }
            executor = plugin.getOnlineSenders().filter(s -> !s.isConsole()).filter(s -> s.getName().equalsIgnoreCase(name)).findAny().orElse(null);
            if (executor == null) {
                Message.USER_NOT_ONLINE.send(sender, name);
                return;
            }
        }
        String commandWithSlash = String.join(" ", args.subList(2, args.size()));
        String command = commandWithSlash.charAt(0) == '/' ? commandWithSlash.substring(1) : commandWithSlash;
        plugin.getBootstrap().getScheduler().sync().execute(() -> {
            Message.VERBOSE_ON_COMMAND.send(sender, executor.getName(), command);
            verboseHandler.registerListener(sender, VerboseFilter.acceptAll(), true);
            executor.performCommand(command);
            VerboseListener listener = verboseHandler.unregisterListener(sender);
            if (listener.getMatchedCount() == 0) {
                Message.VERBOSE_OFF_COMMAND_NO_CHECKS.send(sender);
            } else {
                Message.VERBOSE_OFF_COMMAND.send(sender);
            }
        });
        return;
    }
    if (mode.equals("on") || mode.equals("true") || mode.equals("record")) {
        List<String> filters = new ArrayList<>();
        if (args.size() != 1) {
            filters.addAll(args.subList(1, args.size()));
        }
        String filter = filters.isEmpty() ? "" : String.join(" ", filters);
        VerboseFilter compiledFilter;
        try {
            compiledFilter = VerboseFilter.compile(filter);
        } catch (InvalidFilterException e) {
            Message.VERBOSE_INVALID_FILTER.send(sender, filter, e.getCause().getMessage());
            return;
        }
        boolean notify = !mode.equals("record");
        verboseHandler.registerListener(sender, compiledFilter, notify);
        if (notify) {
            if (!filter.isEmpty()) {
                Message.VERBOSE_ON_QUERY.send(sender, filter);
            } else {
                Message.VERBOSE_ON.send(sender);
            }
        } else {
            if (!filter.isEmpty()) {
                Message.VERBOSE_RECORDING_ON_QUERY.send(sender, filter);
            } else {
                Message.VERBOSE_RECORDING_ON.send(sender);
            }
        }
        return;
    }
    if (mode.equals("off") || mode.equals("false") || mode.equals("paste") || mode.equals("upload")) {
        VerboseListener listener = verboseHandler.unregisterListener(sender);
        if (mode.equals("paste") || mode.equals("upload")) {
            if (listener == null) {
                Message.VERBOSE_OFF.send(sender);
            } else {
                Message.VERBOSE_UPLOAD_START.send(sender);
                String id;
                try {
                    id = listener.uploadPasteData(plugin.getBytebin());
                } catch (UnsuccessfulRequestException e) {
                    Message.GENERIC_HTTP_REQUEST_FAILURE.send(sender, e.getResponse().code(), e.getResponse().message());
                    return;
                } catch (IOException e) {
                    plugin.getLogger().warn("Error uploading data to bytebin", e);
                    Message.GENERIC_HTTP_UNKNOWN_FAILURE.send(sender);
                    return;
                }
                String url = plugin.getConfiguration().get(ConfigKeys.VERBOSE_VIEWER_URL_PATTERN) + id;
                Message.VERBOSE_RESULTS_URL.send(sender, url);
                return;
            }
        } else {
            Message.VERBOSE_OFF.send(sender);
        }
        return;
    }
    sendUsage(sender, label);
}
Also used : Sender(me.lucko.luckperms.common.sender.Sender) VerboseListener(me.lucko.luckperms.common.verbose.VerboseListener) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) IOException(java.io.IOException) CompletionSupplier(me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier) Sender(me.lucko.luckperms.common.sender.Sender) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) Message(me.lucko.luckperms.common.locale.Message) ArrayList(java.util.ArrayList) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) InvalidFilterException(me.lucko.luckperms.common.verbose.InvalidFilterException) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) VerboseHandler(me.lucko.luckperms.common.verbose.VerboseHandler) List(java.util.List) VerboseFilter(me.lucko.luckperms.common.verbose.VerboseFilter) Locale(java.util.Locale) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) UnsuccessfulRequestException(me.lucko.luckperms.common.http.UnsuccessfulRequestException) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) InvalidFilterException(me.lucko.luckperms.common.verbose.InvalidFilterException) VerboseHandler(me.lucko.luckperms.common.verbose.VerboseHandler) VerboseListener(me.lucko.luckperms.common.verbose.VerboseListener) ArrayList(java.util.ArrayList) UnsuccessfulRequestException(me.lucko.luckperms.common.http.UnsuccessfulRequestException) IOException(java.io.IOException) VerboseFilter(me.lucko.luckperms.common.verbose.VerboseFilter)

Example 2 with Message

use of me.lucko.luckperms.common.locale.Message in project LuckPerms by lucko.

the class GroupListMembers method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    InheritanceNode node = Inheritance.builder(target.getName()).build();
    ConstraintNodeMatcher<InheritanceNode> matcher = StandardNodeMatchers.key(node);
    int page = args.getIntOrDefault(0, 1);
    Message.SEARCH_SEARCHING_MEMBERS.send(sender, target.getName());
    List<NodeEntry<UUID, InheritanceNode>> matchedUsers = plugin.getStorage().searchUserNodes(matcher).join().stream().filter(n -> n.getNode().getValue()).collect(Collectors.toList());
    // special handling for default group
    if (target.getName().equals(GroupManager.DEFAULT_GROUP_NAME)) {
        // include all non-saved online players in the results
        for (User user : plugin.getUserManager().getAll().values()) {
            if (!plugin.getUserManager().isNonDefaultUser(user)) {
                matchedUsers.add(NodeEntry.of(user.getUniqueId(), node));
            }
        }
        // send a warning message about this behaviour
        Message.SEARCH_RESULT_GROUP_DEFAULT.send(sender);
    }
    List<NodeEntry<String, InheritanceNode>> matchedGroups = plugin.getStorage().searchGroupNodes(matcher).join().stream().filter(n -> n.getNode().getValue()).collect(Collectors.toList());
    int users = matchedUsers.size();
    int groups = matchedGroups.size();
    Message.SEARCH_RESULT.send(sender, users + groups, users, groups);
    if (!matchedUsers.isEmpty()) {
        Map<UUID, String> uuidLookups = LoadingMap.of(u -> plugin.lookupUsername(u).orElseGet(u::toString));
        sendResult(sender, matchedUsers, uuidLookups::get, Message.SEARCH_SHOWING_USERS, HolderType.USER, label, page);
    }
    if (!matchedGroups.isEmpty()) {
        sendResult(sender, matchedGroups, Function.identity(), Message.SEARCH_SHOWING_GROUPS, HolderType.GROUP, label, page);
    }
}
Also used : LoadingMap(me.lucko.luckperms.common.cache.LoadingMap) StandardNodeMatchers(me.lucko.luckperms.common.node.matcher.StandardNodeMatchers) Function(java.util.function.Function) Message(me.lucko.luckperms.common.locale.Message) NodeEntryComparator(me.lucko.luckperms.common.node.comparator.NodeEntryComparator) ArrayList(java.util.ArrayList) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) 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) HolderType(me.lucko.luckperms.common.model.HolderType) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) GroupManager(me.lucko.luckperms.common.model.manager.group.GroupManager) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) ConstraintNodeMatcher(me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher) Iterators(me.lucko.luckperms.common.util.Iterators) List(java.util.List) Group(me.lucko.luckperms.common.model.Group) ChildCommand(me.lucko.luckperms.common.command.abstraction.ChildCommand) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Inheritance(me.lucko.luckperms.common.node.types.Inheritance) User(me.lucko.luckperms.common.model.User) User(me.lucko.luckperms.common.model.User) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) UUID(java.util.UUID)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)2 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)2 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)2 Message (me.lucko.luckperms.common.locale.Message)2 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)2 Sender (me.lucko.luckperms.common.sender.Sender)2 Predicates (me.lucko.luckperms.common.util.Predicates)2 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 Locale (java.util.Locale)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 LoadingMap (me.lucko.luckperms.common.cache.LoadingMap)1 ChildCommand (me.lucko.luckperms.common.command.abstraction.ChildCommand)1 SingleCommand (me.lucko.luckperms.common.command.abstraction.SingleCommand)1 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)1