Search in sources :

Example 1 with VerboseListener

use of me.lucko.luckperms.common.verbose.VerboseListener in project LuckPerms by lucko.

the class VerboseCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    if (args.isEmpty()) {
        sendUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    String mode = args.get(0).toLowerCase();
    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() ? "" : filters.stream().collect(Collectors.joining(" "));
        VerboseFilter parsedFilter;
        try {
            parsedFilter = VerboseFilter.parse(filter);
        } catch (InvalidFilterException e) {
            e.printStackTrace();
            Message.VERBOSE_INVALID_FILTER.send(sender, filter);
            return CommandResult.FAILURE;
        }
        boolean notify = !mode.equals("record");
        plugin.getVerboseHandler().registerListener(sender, parsedFilter, notify);
        if (notify) {
            if (!filter.equals("")) {
                Message.VERBOSE_ON_QUERY.send(sender, filter);
            } else {
                Message.VERBOSE_ON.send(sender);
            }
        } else {
            if (!filter.equals("")) {
                Message.VERBOSE_RECORDING_ON_QUERY.send(sender, filter);
            } else {
                Message.VERBOSE_RECORDING_ON.send(sender);
            }
        }
        return CommandResult.SUCCESS;
    }
    if (mode.equals("off") || mode.equals("false") || mode.equals("paste") || mode.equals("upload")) {
        VerboseListener listener = plugin.getVerboseHandler().unregisterListener(sender.getUuid());
        if (mode.equals("paste") || mode.equals("upload")) {
            if (listener == null) {
                Message.VERBOSE_OFF.send(sender);
            } else {
                Message.VERBOSE_UPLOAD_START.send(sender);
                String id = listener.uploadPasteData();
                String url = plugin.getConfiguration().get(ConfigKeys.VERBOSE_VIEWER_URL_PATTERN) + "?" + id;
                Message.VERBOSE_RESULTS_URL.send(sender);
                Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(url))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the results page.").color(TextColor.GRAY))).build();
                sender.sendMessage(message);
                return CommandResult.SUCCESS;
            }
        } else {
            Message.VERBOSE_OFF.send(sender);
        }
        return CommandResult.SUCCESS;
    }
    sendUsage(sender, label);
    return CommandResult.INVALID_ARGS;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) InvalidFilterException(me.lucko.luckperms.common.verbose.InvalidFilterException) ClickEvent(net.kyori.text.event.ClickEvent) ArrayList(java.util.ArrayList) VerboseListener(me.lucko.luckperms.common.verbose.VerboseListener) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component) VerboseFilter(me.lucko.luckperms.common.verbose.VerboseFilter)

Aggregations

ArrayList (java.util.ArrayList)1 InvalidFilterException (me.lucko.luckperms.common.verbose.InvalidFilterException)1 VerboseFilter (me.lucko.luckperms.common.verbose.VerboseFilter)1 VerboseListener (me.lucko.luckperms.common.verbose.VerboseListener)1 Component (net.kyori.text.Component)1 TextComponent (net.kyori.text.TextComponent)1 ClickEvent (net.kyori.text.event.ClickEvent)1 HoverEvent (net.kyori.text.event.HoverEvent)1