net.luckperms.api.node.NodeType Java Examples
The following examples show how to use
net.luckperms.api.node.NodeType.
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: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<Set<Context>, Map<String, Boolean>> getTransientPermissions(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.transientData().toCollection(); Map<Set<Context>, Map<String, Boolean>> transientPermissionMap = new TreeMap<Set<Context>, Map<String, Boolean>>(CONTEXT_COMPARATOR); for (Node node : nodes) { if (node.getType() != NodeType.PERMISSION) { continue; } final PermissionNode permissionNode = (PermissionNode) node; final Set<Context> contexts = getGPContexts(node.getContexts()); Map<String, Boolean> permissionEntry = transientPermissionMap.get(contexts); if (permissionEntry == null) { permissionEntry = new HashMap<>(); permissionEntry.put(permissionNode.getPermission(), node.getValue()); transientPermissionMap.put(contexts, permissionEntry); } else { permissionEntry.put(permissionNode.getPermission(), node.getValue()); } } return transientPermissionMap; }
Example #2
Source File: PermissionHolderSubjectData.java From LuckPerms with MIT License | 6 votes |
@Override public CompletableFuture<Boolean> unsetOption(ImmutableContextSet contexts, String key) { Objects.requireNonNull(contexts, "contexts"); Objects.requireNonNull(key, "key"); Predicate<? super Node> test; if (key.equalsIgnoreCase(Prefix.NODE_KEY)) { test = NodeType.PREFIX::matches; } else if (key.equalsIgnoreCase(Suffix.NODE_KEY)) { test = NodeType.SUFFIX::matches; } else { test = NodeType.META.predicate(mn -> mn.getMetaKey().equals(key)); } if (!this.holder.removeIf(this.type, contexts, test, false)) { return CompletableFuture.completedFuture(false); } return save(this.holder).thenApply(v -> true); }
Example #3
Source File: GroupSetWeight.java From LuckPerms with MIT License | 6 votes |
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) throws CommandException { if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } int weight = args.getPriority(0); target.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches, false); target.setNode(DataType.NORMAL, Weight.builder(weight).build(), true); Message.GROUP_SET_WEIGHT.send(sender, weight, target.getFormattedDisplayName()); LoggedAction.build().source(sender).target(target) .description("setweight", weight) .build().submit(plugin, sender); StorageAssistant.save(target, sender, plugin); return CommandResult.SUCCESS; }
Example #4
Source File: LuckPermsVaultChat.java From LuckPerms with MIT License | 6 votes |
private void setMeta(PermissionHolder holder, String key, Object value, String world) { if (key.equalsIgnoreCase(Prefix.NODE_KEY) || key.equalsIgnoreCase(Suffix.NODE_KEY)) { setChatMeta(holder, ChatMetaType.valueOf(key.toUpperCase()), value == null ? null : value.toString(), world); return; } holder.removeIf(DataType.NORMAL, null, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false); if (value == null) { this.vaultPermission.holderSave(holder); return; } Node node = Meta.builder(key, value.toString()) .withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()) .withContext(DefaultContextKeys.WORLD_KEY, world == null ? "global" : world) .build(); holder.setNode(DataType.NORMAL, node, true); this.vaultPermission.holderSave(holder); }
Example #5
Source File: LuckPermsVaultPermission.java From LuckPerms with MIT License | 6 votes |
@Override public String[] userGetGroups(String world, UUID uuid) { Objects.requireNonNull(uuid, "uuid"); PermissionHolder user = lookupUser(uuid); QueryOptions queryOptions = getQueryOptions(uuid, world); return user.getOwnNodes(NodeType.INHERITANCE, queryOptions).stream() .map(n -> { Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName()); if (group != null) { return group.getPlainDisplayName(); } return n.getGroupName(); }) .toArray(String[]::new); }
Example #6
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<String, String> getTransientOptions(GDPermissionHolder holder, Set<Context> contexts) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.transientData().toCollection(); final Map<String, String> options = new HashMap<>(); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; if (contexts == null) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } else if (getGPContexts(node.getContexts()).containsAll(contexts)) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return options; }
Example #7
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<String, String> getPermanentOptions(GDPermissionHolder holder, Set<Context> contexts) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.data().toCollection(); final Map<String, String> options = new HashMap<>(); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; if (contexts == null) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } else if (getGPContexts(node.getContexts()).containsAll(contexts)) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return options; }
Example #8
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<Set<Context>, Map<String, String>> getTransientOptions(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.transientData().toCollection(); Map<Set<Context>, Map<String, String>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, String>>(CONTEXT_COMPARATOR); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; final Set<Context> contexts = getGPContexts(node.getContexts()); Map<String, String> metaEntry = permanentPermissionMap.get(contexts); if (metaEntry == null) { metaEntry = new HashMap<>(); metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); permanentPermissionMap.put(contexts, metaEntry); } else { metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return permanentPermissionMap; }
Example #9
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<Set<Context>, Map<String, String>> getPermanentOptions(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.data().toCollection(); Map<Set<Context>, Map<String, String>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, String>>(CONTEXT_COMPARATOR); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; final Set<Context> contexts = getGPContexts(node.getContexts()); Map<String, String> metaEntry = permanentPermissionMap.get(contexts); if (metaEntry == null) { metaEntry = new HashMap<>(); metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); permanentPermissionMap.put(contexts, metaEntry); } else { metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return permanentPermissionMap; }
Example #10
Source File: StandardNodeMatchers.java From LuckPerms with MIT License | 6 votes |
private static Constraint getConstraintForType(NodeType<?> type) { if (type == NodeType.REGEX_PERMISSION) { return Constraint.of(StandardComparison.SIMILAR, RegexPermission.key(StandardComparison.WILDCARD)); } else if (type == NodeType.INHERITANCE) { return Constraint.of(StandardComparison.SIMILAR, Inheritance.key(StandardComparison.WILDCARD)); } else if (type == NodeType.PREFIX) { return Constraint.of(StandardComparison.SIMILAR, Prefix.NODE_MARKER + StandardComparison.WILDCARD + AbstractNode.NODE_SEPARATOR + StandardComparison.WILDCARD); } else if (type == NodeType.SUFFIX) { return Constraint.of(StandardComparison.SIMILAR, Suffix.NODE_MARKER + StandardComparison.WILDCARD + AbstractNode.NODE_SEPARATOR + StandardComparison.WILDCARD); } else if (type == NodeType.META) { return Constraint.of(StandardComparison.SIMILAR, Meta.key(StandardComparison.WILDCARD, StandardComparison.WILDCARD)); } else if (type == NodeType.WEIGHT) { return Constraint.of(StandardComparison.SIMILAR, Weight.NODE_MARKER + StandardComparison.WILDCARD); } else if (type == NodeType.DISPLAY_NAME) { return Constraint.of(StandardComparison.SIMILAR, DisplayName.key(StandardComparison.WILDCARD)); } throw new IllegalArgumentException("Unable to create a NodeMatcher for NodeType " + type.name()); }
Example #11
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<Set<Context>, Map<String, Boolean>> getTransientPermissions(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.transientData().toCollection(); Map<Set<Context>, Map<String, Boolean>> transientPermissionMap = new TreeMap<Set<Context>, Map<String, Boolean>>(CONTEXT_COMPARATOR); for (Node node : nodes) { if (node.getType() != NodeType.PERMISSION) { continue; } final PermissionNode permissionNode = (PermissionNode) node; final Set<Context> contexts = getGPContexts(node.getContexts()); Map<String, Boolean> permissionEntry = transientPermissionMap.get(contexts); if (permissionEntry == null) { permissionEntry = new HashMap<>(); permissionEntry.put(permissionNode.getPermission(), node.getValue()); transientPermissionMap.put(contexts, permissionEntry); } else { permissionEntry.put(permissionNode.getPermission(), node.getValue()); } } return transientPermissionMap; }
Example #12
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<String, String> getTransientOptions(GDPermissionHolder holder, Set<Context> contexts) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.transientData().toCollection(); final Map<String, String> options = new HashMap<>(); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; if (contexts == null) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } else if (getGPContexts(node.getContexts()).containsAll(contexts)) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return options; }
Example #13
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<String, String> getPermanentOptions(GDPermissionHolder holder, Set<Context> contexts) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.data().toCollection(); final Map<String, String> options = new HashMap<>(); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; if (contexts == null) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } else if (getGPContexts(node.getContexts()).containsAll(contexts)) { options.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return options; }
Example #14
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<Set<Context>, Map<String, String>> getTransientOptions(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.transientData().toCollection(); Map<Set<Context>, Map<String, String>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, String>>(CONTEXT_COMPARATOR); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; final Set<Context> contexts = getGPContexts(node.getContexts()); Map<String, String> metaEntry = permanentPermissionMap.get(contexts); if (metaEntry == null) { metaEntry = new HashMap<>(); metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); permanentPermissionMap.put(contexts, metaEntry); } else { metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return permanentPermissionMap; }
Example #15
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<Set<Context>, Map<String, String>> getPermanentOptions(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.data().toCollection(); Map<Set<Context>, Map<String, String>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, String>>(CONTEXT_COMPARATOR); for (Node node : nodes) { if (node.getType() != NodeType.META) { continue; } final MetaNode metaNode = (MetaNode) node; final Set<Context> contexts = getGPContexts(node.getContexts()); Map<String, String> metaEntry = permanentPermissionMap.get(contexts); if (metaEntry == null) { metaEntry = new HashMap<>(); metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); permanentPermissionMap.put(contexts, metaEntry); } else { metaEntry.put(metaNode.getMetaKey(), metaNode.getMetaValue()); } } return permanentPermissionMap; }
Example #16
Source File: PermissionHolderSubjectData.java From LuckPerms with MIT License | 5 votes |
@Override public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) { Objects.requireNonNull(contexts, "contexts"); Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); Node node; if (key.equalsIgnoreCase(Prefix.NODE_KEY) || key.equalsIgnoreCase(Suffix.NODE_KEY)) { // special handling. ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase()); // remove all prefixes/suffixes from the user this.holder.removeIf(this.type, contexts, type.nodeType()::matches, false); MetaAccumulator metaAccumulator = this.holder.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build()); int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0); priority += 10; node = type.builder(value, priority).withContext(contexts).build(); } else { // standard remove this.holder.removeIf(this.type, contexts, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false); node = Meta.builder(key, value).withContext(contexts).build(); } this.holder.setNode(this.type, node, true); return save(this.holder).thenApply(v -> true); }
Example #17
Source File: LuckPermsHook.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
private void handle(NodeMutateEvent event, Node node, boolean add) { if (event.isUser() && node.getType() == NodeType.INHERITANCE) { String groupName = NodeType.INHERITANCE.cast(node).getGroupName(); UUID uuid = ((User) event.getTarget()).getUniqueId(); Map<String, List<String>> justModified = DiscordSRV.getPlugin() .getGroupSynchronizationManager().getJustModifiedGroups().getOrDefault(uuid, null); if (justModified != null && justModified.getOrDefault(add ? "add" : "remove", Collections.emptyList()).remove(groupName)) { return; } handle(((User) event.getTarget()).getUniqueId()); } }
Example #18
Source File: PermissionHolderSubjectData.java From LuckPerms with MIT License | 5 votes |
@Override public CompletableFuture<Boolean> clearOptions(ImmutableContextSet contexts) { Objects.requireNonNull(contexts, "contexts"); if (!this.holder.removeIf(this.type, contexts, NodeType.META_OR_CHAT_META::matches, false)) { return CompletableFuture.completedFuture(false); } return save(this.holder).thenApply(v -> true); }
Example #19
Source File: PermissionHolderSubjectData.java From LuckPerms with MIT License | 5 votes |
@Override public CompletableFuture<Boolean> clearOptions() { if (!this.holder.removeIf(this.type, null, NodeType.META_OR_CHAT_META::matches, false)) { return CompletableFuture.completedFuture(false); } return save(this.holder).thenApply(v -> true); }
Example #20
Source File: PermissionClear.java From LuckPerms with MIT License | 5 votes |
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException { if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } int before = target.normalData().immutable().size(); MutableContextSet context = args.getContextOrDefault(0, plugin); if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } target.removeIf(DataType.NORMAL, context.isEmpty() ? null : context, NodeType.PERMISSION::matches, false); int changed = before - target.normalData().immutable().size(); if (changed == 1) { Message.PERMISSION_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { Message.PERMISSION_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } LoggedAction.build().source(sender).target(target) .description("permission", "clear", context) .build().submit(plugin, sender); StorageAssistant.save(target, sender, plugin); return CommandResult.SUCCESS; }
Example #21
Source File: MetaUnsetTemp.java From LuckPerms with MIT License | 5 votes |
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException { if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } String key = args.get(0); MutableContextSet context = args.getContextOrDefault(1, plugin); if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) { Message.UNSET_META_TEMP_SUCCESS.send(sender, key, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); LoggedAction.build().source(sender).target(target) .description("meta", "unsettemp", key, context) .build().submit(plugin, sender); StorageAssistant.save(target, sender, plugin); return CommandResult.SUCCESS; } else { Message.DOESNT_HAVE_TEMP_META.send(sender, target.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } }
Example #22
Source File: MetaUnset.java From LuckPerms with MIT License | 5 votes |
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException { if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } String key = args.get(0); MutableContextSet context = args.getContextOrDefault(1, plugin); if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> !n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) { Message.UNSET_META_SUCCESS.send(sender, key, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); LoggedAction.build().source(sender).target(target) .description("meta", "unset", key, context) .build().submit(plugin, sender); StorageAssistant.save(target, sender, plugin); return CommandResult.SUCCESS; } else { Message.DOESNT_HAVE_META.send(sender, target.getFormattedDisplayName(), key, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); return CommandResult.STATE_ERROR; } }
Example #23
Source File: ParentClear.java From LuckPerms with MIT License | 5 votes |
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException { if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } int before = target.normalData().immutable().size(); MutableContextSet context = args.getContextOrDefault(0, plugin); if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } if (context.isEmpty()) { target.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE::matches, true); } else { target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, true); } int changed = before - target.normalData().immutable().size(); if (changed == 1) { Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } else { Message.PARENT_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed); } LoggedAction.build().source(sender).target(target) .description("parent", "clear", context) .build().submit(plugin, sender); StorageAssistant.save(target, sender, plugin); return CommandResult.SUCCESS; }
Example #24
Source File: ParentSet.java From LuckPerms with MIT License | 5 votes |
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException { if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST); MutableContextSet context = args.getContextOrDefault(1, plugin); Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false); if (group == null) { return CommandResult.LOADING_ERROR; } if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, group, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; } target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE::matches, false); target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true); if (target.getType() == HolderType.USER) { ((User) target).getPrimaryGroup().setStoredValue(group.getName()); } Message.SET_PARENT_SUCCESS.send(sender, target.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)); LoggedAction.build().source(sender).target(target) .description("parent", "set", group.getName(), context) .build().submit(plugin, sender); StorageAssistant.save(target, sender, plugin); return CommandResult.SUCCESS; }
Example #25
Source File: PermissionHolder.java From LuckPerms with MIT License | 5 votes |
public <T extends Node> List<T> getOwnNodes(NodeType<T> type, QueryOptions queryOptions) { List<T> nodes = new ArrayList<>(); for (DataType dataType : queryOrder(queryOptions)) { getData(dataType).copyTo(nodes, type, queryOptions); } return nodes; }
Example #26
Source File: PermissionHolder.java From LuckPerms with MIT License | 5 votes |
public <T extends Node> List<T> resolveInheritedNodes(NodeType<T> type, QueryOptions queryOptions) { if (!queryOptions.flag(Flag.RESOLVE_INHERITANCE)) { return getOwnNodes(type, queryOptions); } List<T> nodes = new ArrayList<>(); InheritanceGraph graph = this.plugin.getInheritanceGraphFactory().getGraph(queryOptions); for (PermissionHolder holder : graph.traverse(this)) { for (DataType dataType : holder.queryOrder(queryOptions)) { holder.getData(dataType).copyTo(nodes, type, queryOptions); } } return nodes; }
Example #27
Source File: PermissionHolder.java From LuckPerms with MIT License | 5 votes |
public MetaAccumulator accumulateMeta(MetaAccumulator accumulator, QueryOptions queryOptions) { InheritanceGraph graph = this.plugin.getInheritanceGraphFactory().getGraph(queryOptions); for (PermissionHolder holder : graph.traverse(this)) { // accumulate nodes for (DataType dataType : holder.queryOrder(queryOptions)) { holder.getData(dataType).forEach(queryOptions, node -> { if (node.getValue() && NodeType.META_OR_CHAT_META.matches(node)) { accumulator.accumulateNode(node); } }); } // accumulate weight OptionalInt w = holder.getWeight(); if (w.isPresent()) { accumulator.accumulateWeight(w.getAsInt()); } } // accumulate primary group if (this instanceof User) { String primaryGroup = ((User) this).getPrimaryGroup().calculateValue(queryOptions); accumulator.setPrimaryGroup(primaryGroup); } accumulator.complete(); return accumulator; }
Example #28
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public Map<Set<Context>, Map<String, Boolean>> getPermanentPermissions(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final Collection<Node> nodes = permissionHolder.data().toCollection(); Map<Set<Context>, Map<String, Boolean>> permanentPermissionMap = new TreeMap<Set<Context>, Map<String, Boolean>>(CONTEXT_COMPARATOR); for (Node node : nodes) { if (node.getType() != NodeType.PERMISSION) { continue; } final PermissionNode permissionNode = (PermissionNode) node; final Set<Context> contexts = getGPContexts(node.getContexts()); Map<String, Boolean> permissionEntry = permanentPermissionMap.get(contexts); if (permissionEntry == null) { permissionEntry = new HashMap<>(); permissionEntry.put(permissionNode.getPermission(), node.getValue()); permanentPermissionMap.put(contexts, permissionEntry); } else { permissionEntry.put(permissionNode.getPermission(), node.getValue()); } } return permanentPermissionMap; }
Example #29
Source File: PermissionHolderSubjectData.java From LuckPerms with MIT License | 5 votes |
@Override public CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts) { Objects.requireNonNull(contexts, "contexts"); if (!this.holder.removeIf(this.type, contexts, NodeType.INHERITANCE::matches, true)) { return CompletableFuture.completedFuture(false); } return save(this.holder).thenApply(v -> true); }
Example #30
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
private void clearMeta(PermissionHolder holder, String metaKey, ContextSet set) { if (set.size() == 1 && set.containsKey("server")) { if (set.getAnyValue("server").get().equalsIgnoreCase("global")) { // LP does not remove meta if passing only global context so we need to make sure to pass none holder.data().clear(NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey))); return; } } holder.data().clear(set, NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey))); }