Java Code Examples for net.luckperms.api.node.Node#hasExpiry()
The following examples show how to use
net.luckperms.api.node.Node#hasExpiry() .
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: AbstractUserManager.java From LuckPerms with MIT License | 6 votes |
/** * Check whether the user's state indicates that they should be persisted to storage. * * @param user the user to check * @return true if the user should be saved */ @Override public boolean shouldSave(User user) { ImmutableCollection<Node> nodes = user.normalData().immutable().values(); if (nodes.size() != 1) { return true; } Node onlyNode = nodes.iterator().next(); if (!(onlyNode instanceof InheritanceNode)) { return true; } if (onlyNode.hasExpiry() || !onlyNode.getContexts().isEmpty()) { return true; } if (!((InheritanceNode) onlyNode).getGroupName().equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) { // The user's only node is not the default group one. return true; } // Not in the default primary group return !user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME); }
Example 2
Source File: GroupListMembers.java From LuckPerms with MIT License | 5 votes |
private static String getNodeExpiryString(Node node) { if (!node.hasExpiry()) { return ""; } return " &8(&7expires in " + DurationFormatter.LONG.format(node.getExpiryDuration()) + "&8)"; }
Example 3
Source File: SearchCommand.java From LuckPerms with MIT License | 5 votes |
private static String getNodeExpiryString(Node node) { if (!node.hasExpiry()) { return ""; } return " &8(&7expires in " + DurationFormatter.LONG.format(node.getExpiryDuration()) + "&8)"; }
Example 4
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 5 votes |
private static void writeAttributesTo(ConfigurationNode attributes, Node node, boolean writeValue) { if (writeValue) { attributes.getNode("value").setValue(node.getValue()); } if (node.hasExpiry()) { attributes.getNode("expiry").setValue(node.getExpiry().getEpochSecond()); } if (!node.getContexts().isEmpty()) { attributes.getNode("context").setValue(ContextSetConfigurateSerializer.serializeContextSet(node.getContexts())); } }
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(); }
Example 9
Source File: NodeComparator.java From LuckPerms with MIT License | 4 votes |
@Override public int compare(Node o1, Node o2) { if (o1.equals(o2)) { return 0; } int result = Boolean.compare(o1.hasExpiry(), o2.hasExpiry()); if (result != 0) { return result; } result = Boolean.compare( o1 instanceof PermissionNode && ((PermissionNode) o1).isWildcard(), o2 instanceof PermissionNode && ((PermissionNode) o2).isWildcard() ); if (result != 0) { return result; } if (o1.hasExpiry()) { result = o1.getExpiry().compareTo(o2.getExpiry()); if (result != 0) { return result; } } if (o1 instanceof PermissionNode && ((PermissionNode) o1).isWildcard()) { result = Integer.compare(((PermissionNode) o1).getWildcardLevel().getAsInt(), ((PermissionNode) o2).getWildcardLevel().getAsInt()); if (result != 0) { return result; } } // note vvv result = -o1.getKey().compareTo(o2.getKey()); if (result != 0) { return result; } // note vvv - we want false to have priority result = -Boolean.compare(o1.getValue(), o2.getValue()); if (result != 0) { return result; } throw new AssertionError("nodes are equal? " + o1 + " - " + o2); }