use of me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class PermissionHolder method accumulateInheritancesTo.
private void accumulateInheritancesTo(List<LocalizedNode> accumulator, Contexts context) {
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(context);
Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
for (PermissionHolder holder : traversal) {
List<Node> nodes = holder.getOwnNodes(context.getContexts());
for (Node node : nodes) {
ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(node, holder.getObjectName());
accumulator.add(localizedNode);
}
}
}
use of me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class MetaInfo method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
SortedSet<Map.Entry<Integer, LocalizedNode>> prefixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
SortedSet<Map.Entry<Integer, LocalizedNode>> suffixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
Set<LocalizedNode> meta = new HashSet<>();
// Collect data
for (LocalizedNode node : holder.resolveInheritances()) {
if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) {
continue;
}
if (node.isPrefix()) {
prefixes.add(Maps.immutableEntry(node.getPrefix().getKey(), node));
} else if (node.isSuffix()) {
suffixes.add(Maps.immutableEntry(node.getSuffix().getKey(), node));
} else if (node.isMeta()) {
meta.add(node);
}
}
if (prefixes.isEmpty()) {
Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
} else {
Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
sendChatMetaMessage(ChatMetaType.PREFIX, prefixes, sender, holder, label);
}
if (suffixes.isEmpty()) {
Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
} else {
Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
sendChatMetaMessage(ChatMetaType.SUFFIX, suffixes, sender, holder, label);
}
if (meta.isEmpty()) {
Message.META_NONE.send(sender, holder.getFriendlyName());
} else {
Message.META_HEADER.send(sender, holder.getFriendlyName());
sendMetaMessage(meta, sender, holder, label);
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class MetaInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥a" + type.getEntry(node).getKey() + " ¥7- ¥r" + type.getEntry(node).getValue(), " ", "¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFriendlyName()), '¥'));
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 me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class PermissionInfo method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
int page = ArgumentParser.parseIntOrElse(0, args, 1);
SortMode sortMode = SortMode.determine(args);
// get the holders nodes
List<LocalizedNode> nodes = new ArrayList<>(holder.getEnduringData().asSortedSet());
// remove irrelevant types (these are displayed in the other info commands)
nodes.removeIf(node -> (node.isGroupNode() && node.getValuePrimitive() && plugin.getGroupManager().isLoaded(node.getGroupName())) || // remove if the node is a meta node
node.isPrefix() || node.isSuffix() || node.isMeta());
// handle empty
if (nodes.isEmpty()) {
Message.PERMISSION_INFO_NO_DATA.send(sender, holder.getFriendlyName());
return CommandResult.SUCCESS;
}
// sort the list alphabetically instead
if (sortMode.getType() == SortType.ALPHABETICALLY) {
nodes.sort(ALPHABETICAL_NODE_COMPARATOR);
}
// reverse the order if necessary
if (!sortMode.isAscending()) {
Collections.reverse(nodes);
}
int pageIndex = page - 1;
List<List<LocalizedNode>> pages = Iterators.divideIterable(nodes, 19);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<LocalizedNode> content = pages.get(pageIndex);
// send header
Message.PERMISSION_INFO.send(sender, holder.getFriendlyName(), page, pages.size(), nodes.size());
// send content
for (LocalizedNode node : content) {
String s = "&3> " + (node.getValuePrimitive() ? "&a" : "&c") + node.getPermission() + (sender.isConsole() ? " &7(" + node.getValuePrimitive() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(node);
if (node.isTemporary()) {
s += "\n&2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime());
}
TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build();
sender.sendMessage(message);
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class MetaInfo method sendMetaMessage.
private static void sendMetaMessage(Set<LocalizedNode> meta, Sender sender, PermissionHolder holder, String label) {
for (LocalizedNode m : meta) {
String location = processLocation(m, holder);
if (m.hasSpecificContext()) {
String context = MessageUtils.getAppendableNodeContextString(m);
TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context), CommandManager.SECTION_CHAR).toBuilder();
builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build());
} else {
TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location), CommandManager.SECTION_CHAR).toBuilder();
builder.applyDeep(makeFancy(holder, label, m));
sender.sendMessage(builder.build());
}
}
}
Aggregations