Java Code Examples for net.luckperms.api.node.NodeType#SUFFIX

The following examples show how to use net.luckperms.api.node.NodeType#SUFFIX . 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: PermissionHolderSubjectData.java    From LuckPerms with MIT License 6 votes vote down vote up
@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 2
Source File: StandardNodeMatchers.java    From LuckPerms with MIT License 6 votes vote down vote up
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 3
Source File: SuffixNode.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
default @NonNull NodeType<SuffixNode> getType() {
    return NodeType.SUFFIX;
}
 
Example 4
Source File: MetaClear.java    From LuckPerms with MIT License 4 votes vote down vote up
@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;
    }

    NodeType<?> type = null;
    if (!args.isEmpty()) {
        String typeId = args.get(0).toLowerCase();
        if (typeId.equals("any") || typeId.equals("all") || typeId.equals("*")) {
            type = NodeType.META_OR_CHAT_META;
        }
        if (typeId.equals("chat") || typeId.equals("chatmeta")) {
            type = NodeType.CHAT_META;
        }
        if (typeId.equals("meta")) {
            type = NodeType.META;
        }
        if (typeId.equals("prefix") || typeId.equals("prefixes")) {
            type = NodeType.PREFIX;
        }
        if (typeId.equals("suffix") || typeId.equals("suffixes")) {
            type = NodeType.SUFFIX;
        }

        if (type != null) {
            args.remove(0);
        }
    }

    if (type == null) {
        type = NodeType.META_OR_CHAT_META;
    }

    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, type::matches, false);
    } else {
        target.removeIf(DataType.NORMAL, context, type::matches, false);
    }

    int changed = before - target.normalData().immutable().size();
    if (changed == 1) {
        Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, target.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
    } else {
        Message.META_CLEAR_SUCCESS.send(sender, target.getFormattedDisplayName(), type.name().toLowerCase(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context), changed);
    }

    LoggedAction.build().source(sender).target(target)
            .description("meta", "clear", context)
            .build().submit(plugin, sender);

    StorageAssistant.save(target, sender, plugin);
    return CommandResult.SUCCESS;
}