use of me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class MetaInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(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> ¥r" + node.getMeta().getKey() + " ¥7- ¥r" + node.getMeta().getValue(), " ", "¥7Click to remove this meta pair 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 ParentInfo 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());
// handle empty
if (nodes.isEmpty()) {
Message.PARENT_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.PARENT_INFO.send(sender, holder.getFriendlyName(), page, pages.size(), nodes.size());
// send content
for (LocalizedNode node : content) {
String s = "&3> &a" + node.getGroupName() + 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 NodeWithContextComparator method compare.
@Override
public int compare(LocalizedNode one, LocalizedNode two) {
Node o1 = one.getNode();
Node o2 = two.getNode();
if (o1.equals(o2)) {
return 0;
}
if (o1.isOverride() != o2.isOverride()) {
return o1.isOverride() ? 1 : -1;
}
if (o1.isServerSpecific() != o2.isServerSpecific()) {
return o1.isServerSpecific() ? 1 : -1;
}
if (o1.isWorldSpecific() != o2.isWorldSpecific()) {
return o1.isWorldSpecific() ? 1 : -1;
}
if (o1.getContexts().size() != o2.getContexts().size()) {
return o1.getContexts().size() > o2.getContexts().size() ? 1 : -1;
}
if (o1.isTemporary() != o2.isTemporary()) {
return o1.isTemporary() ? 1 : -1;
}
if (o1.isWildcard() != o2.isWildcard()) {
return o1.isWildcard() ? 1 : -1;
}
if (o1.isTemporary()) {
return o1.getSecondsTilExpiry() < o2.getSecondsTilExpiry() ? 1 : -1;
}
if (o1.isWildcard()) {
return o1.getWildcardLevel() > o2.getWildcardLevel() ? 1 : -1;
}
return CollationKeyCache.compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1;
}
use of me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class PermissionHolder method exportNodesAndShorthand.
public Map<String, Boolean> exportNodesAndShorthand(Contexts context, boolean lowerCase) {
List<LocalizedNode> entries = getAllEntries(context);
Map<String, Boolean> perms = new HashMap<>();
boolean applyShorthand = this.plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND);
for (Node node : entries) {
String perm = lowerCase ? node.getPermission().toLowerCase() : node.getPermission();
if (perms.putIfAbsent(perm, node.getValuePrimitive()) == null) {
if (applyShorthand) {
List<String> shorthand = node.resolveShorthand();
if (!shorthand.isEmpty()) {
for (String s : shorthand) {
perms.putIfAbsent(lowerCase ? s.toLowerCase() : s, node.getValuePrimitive());
}
}
}
}
}
return ImmutableMap.copyOf(perms);
}
use of me.lucko.luckperms.api.LocalizedNode in project LuckPerms by lucko.
the class PermissionHolder method accumulateInheritancesTo.
private void accumulateInheritancesTo(List<LocalizedNode> accumulator) {
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph();
Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
for (PermissionHolder holder : traversal) {
List<Node> nodes = holder.getOwnNodes();
for (Node node : nodes) {
ImmutableLocalizedNode localizedNode = ImmutableLocalizedNode.of(node, holder.getObjectName());
accumulator.add(localizedNode);
}
}
}
Aggregations