use of me.lucko.luckperms.common.references.HolderType in project LuckPerms by lucko.
the class SearchCommand method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> " + (perm.asNode().getValuePrimitive() ? "&a" : "&c") + perm.asNode().getPermission(), " ", "&7Click to remove this node from " + holderName), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.common.references.HolderType in project LuckPerms by lucko.
the class GroupListMembers method sendResult.
private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
results = new ArrayList<>(results);
// we need a deterministic sort order
// even though we're comparing uuids here in some cases - it doesn't matter
// the import thing is that the order is the same each time the command is executed
results.sort((o1, o2) -> {
Comparable h1 = (Comparable) o1.getHolder();
Comparable h2 = (Comparable) o2.getHolder();
// noinspection unchecked
return h1.compareTo(h2);
});
int pageIndex = page - 1;
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<HeldPermission<T>> content = pages.get(pageIndex);
List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
// send header
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message);
}
}
use of me.lucko.luckperms.common.references.HolderType in project LuckPerms by lucko.
the class GroupListMembers method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(String holderName, HolderType holderType, String label, HeldPermission<?> perm) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> &b" + perm.asNode().getGroupName(), " ", "&7Click to remove this parent from " + holderName), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.common.references.HolderType in project LuckPerms by lucko.
the class SearchCommand method sendResult.
private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
results = new ArrayList<>(results);
// we need a deterministic sort order
// even though we're comparing uuids here in some cases - it doesn't matter
// the import thing is that the order is the same each time the command is executed
results.sort((o1, o2) -> {
Comparable h1 = (Comparable) o1.getHolder();
Comparable h2 = (Comparable) o2.getHolder();
// noinspection unchecked
return h1.compareTo(h2);
});
int pageIndex = page - 1;
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<HeldPermission<T>> content = pages.get(pageIndex);
List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
// send header
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
String s = "&3> &b" + ent.getKey() + " &7- " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
sender.sendMessage(message);
}
}
Aggregations