use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class MetaSetTemp method execute.
@Override
public void 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;
}
String key = args.get(0);
String value = args.get(1);
Duration duration = args.getDuration(2);
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = args.getContextOrDefault(3, 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;
}
Node node = Meta.builder(key, value).withContext(context).expiry(duration).build();
// remove temp meta nodes that have the same key and /different/ value (don't want to remove it if we are accumulating/replacing)
target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key) && !n.getMetaValue().equals(value)), false);
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, node, modifier);
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SET_META_TEMP_SUCCESS.send(sender, key, value, target, duration, context);
LoggedAction.build().source(sender).target(target).description("meta", "settemp", key, value, duration, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_HAS_TEMP_META.send(sender, target, key, value, context);
}
}
use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class PermissionSet method execute.
@Override
public void 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;
}
String node = args.get(0);
boolean value = args.getBooleanOrInsert(1, true);
MutableContextSet context = args.getContextOrDefault(2, plugin);
if (node.isEmpty()) {
Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
Node builtNode = NodeBuilders.determineMostApplicable(node).value(value).withContext(context).build();
if (builtNode instanceof InheritanceNode) {
if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
}
DataMutateResult result = target.setNode(DataType.NORMAL, builtNode, true);
if (result.wasSuccessful()) {
Message.SETPERMISSION_SUCCESS.send(sender, node, value, target, context);
LoggedAction.build().source(sender).target(target).description("permission", "set", node, value, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_HASPERMISSION.send(sender, target, node, context);
}
}
use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class LogNotify method isIgnoring.
public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {
User user = plugin.getUserManager().getIfLoaded(uuid);
if (user == null) {
return false;
}
Optional<? extends Node> node = user.normalData().nodesInContext(ImmutableContextSetImpl.EMPTY).stream().filter(n -> n.getKey().equalsIgnoreCase(IGNORE_NODE)).findFirst();
// if set to false, ignore it, return false
return node.map(Node::getValue).orElse(false);
}
use of net.luckperms.api.node.Node in project LuckPerms by lucko.
the class SearchCommand method sendResult.
private static <T extends Comparable<T>> void sendResult(Sender sender, List<NodeEntry<T, Node>> results, Function<T, String> lookupFunction, Message.Args3<Integer, Integer, Integer> headerMessage, HolderType holderType, String label, int page, Comparison comparison) {
results = new ArrayList<>(results);
results.sort(NodeEntryComparator.normal());
int pageIndex = page - 1;
List<List<NodeEntry<T, Node>>> pages = Iterators.divideIterable(results, 15);
if (pageIndex < 0 || pageIndex >= pages.size()) {
page = 1;
pageIndex = 0;
}
List<NodeEntry<T, Node>> content = pages.get(pageIndex);
List<Map.Entry<String, NodeEntry<T, Node>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
// send header
headerMessage.send(sender, page, pages.size(), results.size());
for (Map.Entry<String, NodeEntry<T, Node>> ent : mappedContent) {
Message.SEARCH_NODE_ENTRY.send(sender, comparison != StandardComparison.EQUAL, ent.getValue().getNode(), ent.getKey(), holderType, label, sender.getPlugin());
}
}
Aggregations