use of me.lucko.luckperms.common.verbose.InvalidFilterException 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;
}
Aggregations