Java Code Examples for net.luckperms.api.node.Node#getValue()
The following examples show how to use
net.luckperms.api.node.Node#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeMap.java From LuckPerms with MIT License | 6 votes |
void add(Node node) { ImmutableContextSet context = node.getContexts(); Node n = localise(node); SortedSet<Node> nodesInContext = this.map.computeIfAbsent(context, VALUE_SET_SUPPLIER); nodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE)); nodesInContext.add(n); if (n instanceof InheritanceNode) { SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.computeIfAbsent(context, INHERITANCE_VALUE_SET_SUPPLIER); inheritanceNodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE)); if (n.getValue()) { inheritanceNodesInContext.add((InheritanceNode) n); } } }
Example 2
Source File: PermissionHolderSubjectData.java From LuckPerms with MIT License | 5 votes |
private static ImmutableMap<String, String> nodesToOptions(Iterable<? extends Node> nodes) { Map<String, String> builder = new HashMap<>(); int maxPrefixPriority = Integer.MIN_VALUE; int maxSuffixPriority = Integer.MIN_VALUE; for (Node n : nodes) { if (!n.getValue()) continue; if (!NodeType.META_OR_CHAT_META.matches(n)) continue; if (n instanceof PrefixNode) { PrefixNode pn = (PrefixNode) n; if (pn.getPriority() > maxPrefixPriority) { builder.put(Prefix.NODE_KEY, pn.getMetaValue()); maxPrefixPriority = pn.getPriority(); } continue; } if (n instanceof SuffixNode) { SuffixNode sn = (SuffixNode) n; if (sn.getPriority() > maxSuffixPriority) { builder.put(Suffix.NODE_KEY, sn.getMetaValue()); maxSuffixPriority = sn.getPriority(); } continue; } if (n instanceof MetaNode) { MetaNode mn = (MetaNode) n; builder.put(mn.getMetaKey(), mn.getMetaValue()); } } return ImmutableMap.copyOf(builder); }
Example 3
Source File: NodeMap.java From LuckPerms with MIT License | 5 votes |
private void removeExact(Node node) { ImmutableContextSet context = node.getContexts(); SortedSet<Node> nodesInContext = this.map.get(context); if (nodesInContext != null) { nodesInContext.remove(node); } if (node instanceof InheritanceNode && node.getValue()) { SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(context); if (inheritanceNodesInContext != null) { inheritanceNodesInContext.remove(node); } } }
Example 4
Source File: NodeMap.java From LuckPerms with MIT License | 5 votes |
boolean auditTemporaryNodes(@Nullable Set<? super Node> removed) { boolean work = false; for (SortedSet<Node> valueSet : this.map.values()) { Iterator<Node> it = valueSet.iterator(); while (it.hasNext()) { Node entry = it.next(); if (!entry.hasExpired()) { continue; } // remove if (removed != null) { removed.add(entry); } if (entry instanceof InheritanceNode && entry.getValue()) { SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(entry.getContexts()); if (inheritanceNodesInContext != null) { inheritanceNodesInContext.remove(entry); } } it.remove(); work = true; } } return work; }
Example 5
Source File: PermissionInfo.java From LuckPerms with MIT License | 4 votes |
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) { if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } int page = args.getIntOrDefault(0, 1); SortMode sortMode = SortMode.determine(args); // get the holders nodes List<Node> nodes = new ArrayList<>(target.normalData().asSortedSet()); // remove irrelevant types (these are displayed in the other info commands) nodes.removeIf(NodeType.INHERITANCE.predicate(n -> n.getValue() && plugin.getGroupManager().isLoaded(n.getGroupName())) .or(NodeType.META_OR_CHAT_META.predicate())); // handle empty if (nodes.isEmpty()) { Message.PERMISSION_INFO_NO_DATA.send(sender, target.getFormattedDisplayName()); 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<Node>> pages = Iterators.divideIterable(nodes, 19); if (pageIndex < 0 || pageIndex >= pages.size()) { page = 1; pageIndex = 0; } List<Node> content = pages.get(pageIndex); // send header Message.PERMISSION_INFO.send(sender, target.getFormattedDisplayName(), page, pages.size(), nodes.size()); // send content for (Node node : content) { String s = "&3> " + (node.getValue() ? "&a" : "&c") + node.getKey() + (sender.isConsole() ? " &7(" + node.getValue() + "&7)" : "") + MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node); if (node.hasExpiry()) { s += "\n&2- expires in " + DurationFormatter.LONG.format(node.getExpiryDuration()); } TextComponent message = TextUtils.fromLegacy(s, TextUtils.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(target, label, node)).build(); sender.sendMessage(message); } return CommandResult.SUCCESS; }
Example 6
Source File: ApplyEditsCommand.java From LuckPerms with MIT License | 4 votes |
private static String formatNode(LocaleManager localeManager, Node n) { return n.getKey() + " &7(" + (n.getValue() ? "&a" : "&c") + n.getValue() + "&7)" + MessageUtils.getAppendableNodeContextString(localeManager, n) + (n.hasExpiry() ? " &7(" + DurationFormatter.CONCISE.format(n.getExpiryDuration()) + ")" : ""); }
Example 7
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 4 votes |
private static boolean isPlain(Node node) { return node.getValue() && !node.hasExpiry() && node.getContexts().isEmpty(); }
Example 8
Source File: NodeCommandFactory.java From LuckPerms with MIT License | 4 votes |
public static String undoCommand(Node node, String holder, HolderType holderType, boolean explicitGlobalContext) { StringBuilder sb = new StringBuilder(32); sb.append(holderType.toString()).append(' ').append(holder).append(' '); if (node instanceof InheritanceNode) { // command sb.append("parent remove"); if (node.hasExpiry()) { sb.append("temp"); } sb.append(' '); // value sb.append(((InheritanceNode) node).getGroupName()); } else if (node.getValue() && (node instanceof ChatMetaNode<?, ?>)) { ChatMetaNode<?, ?> chatNode = (ChatMetaNode<?, ?>) node; // command sb.append("meta remove"); if (node.hasExpiry()) { sb.append("temp"); } sb.append(chatNode.getMetaType().toString()); // values sb.append(' ').append(chatNode.getPriority()).append(' '); appendEscaped(sb, chatNode.getMetaValue()); } else if (node.getValue() && node instanceof MetaNode) { MetaNode metaNode = (MetaNode) node; // command sb.append("meta unset"); if (node.hasExpiry()) { sb.append("temp"); } sb.append(' '); // value appendEscaped(sb, metaNode.getMetaKey()); } else { // command sb.append("permission unset"); if (node.hasExpiry()) { sb.append("temp"); } sb.append(' '); // value appendEscaped(sb, node.getKey()); } if (!node.getContexts().isEmpty()) { for (Context context : node.getContexts()) { sb.append(' ').append(context.getKey()).append("=").append(context.getValue()); } } else if (explicitGlobalContext) { sb.append(" global"); } return sb.toString(); }