use of net.kyori.text.event.HoverEvent in project LuckPerms by lucko.
the class ParentInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> &f" + node.getGroupName(), " ", "&7Click to remove this parent from " + holder.getFriendlyName()), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of net.kyori.text.event.HoverEvent in project LuckPerms by lucko.
the class CommandManager method sendCommandUsage.
private void sendCommandUsage(Sender sender, String label) {
MessageUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + this.plugin.getBootstrap().getVersion() + "&2.");
this.mainCommands.stream().filter(Command::shouldDisplay).filter(c -> c.isAuthorized(sender)).forEach(c -> {
@SuppressWarnings("unchecked") String permission = (String) c.getPermission().map(p -> ((CommandPermission) p).getPermission()).orElse("None");
TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR).toBuilder().applyDeep(comp -> {
comp.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&bCommand: &2" + c.getName(), "&bDescription: &2" + c.getDescription(), "&bUsage: &2" + String.format(c.getUsage(), label), "&bPermission: &2" + permission, " ", "&7Click to auto-complete."), AMPERSAND_CHAR)));
comp.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format(c.getUsage(), label)));
}).build();
sender.sendMessage(component);
});
}
use of net.kyori.text.event.HoverEvent in project LuckPerms by lucko.
the class EditorCommand method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
Type type = Type.ALL;
// parse type
String typeString = ArgumentParser.parseStringOrElse(0, args, null);
if (typeString != null) {
try {
type = Type.valueOf(typeString.toUpperCase());
} catch (IllegalArgumentException e) {
// ignored
}
}
// collect holders
List<PermissionHolder> holders = new ArrayList<>();
if (type.includingGroups) {
plugin.getGroupManager().getAll().values().stream().sorted((o1, o2) -> {
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
}).forEach(holders::add);
}
if (type.includingUsers) {
plugin.getUserManager().getAll().values().stream().sorted((o1, o2) -> o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName())).forEach(holders::add);
}
// remove holders which the sender doesn't have perms to view
holders.removeIf(holder -> ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder));
// they don't have perms to view any of them
if (holders.isEmpty()) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Message.EDITOR_START.send(sender);
// form the payload data
JsonObject payload = WebEditor.formPayload(holders, sender, label, plugin);
// upload the payload data to gist
String pasteId = StandardPastebin.BYTEBIN.postJson(payload, true).id();
if (pasteId == null) {
Message.EDITOR_UPLOAD_FAILURE.send(sender);
return CommandResult.STATE_ERROR;
}
// form a url for the editor
String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "?" + pasteId;
Message.EDITOR_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY))).build();
sender.sendMessage(message);
return CommandResult.SUCCESS;
}
use of net.kyori.text.event.HoverEvent in project LuckPerms by lucko.
the class ListGroups method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
try {
plugin.getStorage().loadAllGroups().get();
} catch (Exception e) {
e.printStackTrace();
Message.GROUPS_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR;
}
Message.GROUPS_LIST.send(sender);
plugin.getGroupManager().getAll().values().stream().sorted((o1, o2) -> {
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
}).forEach(group -> {
List<String> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(group)).map(Track::getName).collect(Collectors.toList());
TextComponent component;
if (tracks.isEmpty()) {
component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY.asString(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0)), CommandManager.SECTION_CHAR);
} else {
component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asString(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0), MessageUtils.toCommaSep(tracks)), CommandManager.SECTION_CHAR);
}
component = component.toBuilder().applyDeep(c -> {
c.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + label + " group " + group.getName() + " info"));
c.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to view more info about " + group.getName() + ".").color(TextColor.GRAY)));
}).build();
sender.sendMessage(component);
});
return CommandResult.SUCCESS;
}
use of net.kyori.text.event.HoverEvent in project LuckPerms by lucko.
the class VerboseListener method sendNotification.
private void sendNotification(CheckData data) {
String msg = "&a" + data.getCheckTarget() + "&7 - &a" + data.getPermission() + "&7 - " + getTristateColor(data.getResult()) + data.getResult().name().toLowerCase();
if (this.notifiedSender.isConsole()) {
// just send as a raw message
Message.VERBOSE_LOG.send(this.notifiedSender, msg);
return;
}
// form a hoverevent from the check trace
TextComponent textComponent = TextUtils.fromLegacy(Message.VERBOSE_LOG.asString(this.notifiedSender.getPlatform().getLocaleManager(), msg));
// build the text
List<String> hover = new ArrayList<>();
hover.add("&bOrigin: &2" + data.getCheckOrigin().name());
hover.add("&bContext: &r" + MessageUtils.contextSetToString(data.getCheckContext()));
hover.add("&bTrace: &r");
Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str));
int overflow;
if (data.getCheckOrigin() == CheckOrigin.API || data.getCheckOrigin() == CheckOrigin.INTERNAL) {
overflow = CHAT_UNFILTERED_PRINTER.process(data.getCheckTrace(), printer);
} else {
overflow = CHAT_FILTERED_PRINTER.process(data.getCheckTrace(), printer);
}
if (overflow != 0) {
hover.add("&f... and " + overflow + " more");
}
// send the message
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(hover.stream()), CommandManager.AMPERSAND_CHAR));
TextComponent text = textComponent.toBuilder().applyDeep(comp -> comp.hoverEvent(hoverEvent)).build();
this.notifiedSender.sendMessage(text);
}
Aggregations