Search in sources :

Example 1 with TristateResult

use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.

the class LuckPermsPermissible method hasPermission.

@Override
public boolean hasPermission(Permission permission) {
    if (permission == null) {
        throw new NullPointerException("permission");
    }
    QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
    TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), CheckOrigin.PLATFORM_API_HAS_PERMISSION);
    // override default op handling using the Permission class we have
    if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
        // 'op == true' is implied by the presence of the OpProcessor class
        PermissionDefault def = PermissionDefault.fromPermission(permission);
        if (def != null) {
            return def.getValue(true);
        }
    }
    return result.result().asBoolean();
}
Also used : PermissionDefault(me.lucko.luckperms.nukkit.inject.PermissionDefault) OpProcessor(me.lucko.luckperms.nukkit.calculator.OpProcessor) QueryOptions(net.luckperms.api.query.QueryOptions) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Example 2 with TristateResult

use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.

the class LuckPermsPermissible method hasPermission.

@Override
public boolean hasPermission(@NonNull Permission permission) {
    if (permission == null) {
        throw new NullPointerException("permission");
    }
    QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
    TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), CheckOrigin.PLATFORM_API_HAS_PERMISSION);
    // override default op handling using the Permission class we have
    if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
        // 'op == true' is implied by the presence of the OpProcessor class
        return permission.getDefault().getValue(true);
    }
    return result.result().asBoolean();
}
Also used : OpProcessor(me.lucko.luckperms.bukkit.calculator.OpProcessor) QueryOptions(net.luckperms.api.query.QueryOptions) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Example 3 with TristateResult

use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.

the class LuckPermsPermissible method isPermissionSet.

@Override
public boolean isPermissionSet(@NonNull String permission) {
    if (permission == null) {
        throw new NullPointerException("permission");
    }
    QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
    TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, CheckOrigin.PLATFORM_API_HAS_PERMISSION_SET);
    if (result.result() == Tristate.UNDEFINED) {
        return false;
    }
    // ignore matches made from looking up in the permission map (replicate bukkit behaviour)
    if (result.processorClass() == PermissionMapProcessor.class) {
        return false;
    }
    // ignore the op processor
    return result.processorClass() != OpProcessor.class;
}
Also used : QueryOptions(net.luckperms.api.query.QueryOptions) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Example 4 with TristateResult

use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.

the class LuckPermsVaultPermission method userInGroup.

@Override
public boolean userInGroup(String world, UUID uuid, String group) {
    Objects.requireNonNull(uuid, "uuid");
    Objects.requireNonNull(group, "group");
    PermissionHolder user = lookupUser(uuid);
    QueryOptions queryOptions = getQueryOptions(uuid, world);
    PermissionCache permissionData = user.getCachedData().getPermissionData(queryOptions);
    TristateResult result = permissionData.checkPermission(Inheritance.key(rewriteGroupName(group)), CheckOrigin.THIRD_PARTY_API);
    return result.processorClass() == DirectProcessor.class && result.result().asBoolean();
}
Also used : DirectProcessor(me.lucko.luckperms.common.calculator.processor.DirectProcessor) PermissionCache(me.lucko.luckperms.common.cacheddata.type.PermissionCache) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) QueryOptions(net.luckperms.api.query.QueryOptions) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Example 5 with TristateResult

use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.

the class PermissionCheck method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    String node = args.get(0);
    // accumulate nodes
    List<Node> own = new ArrayList<>();
    List<Node> inherited = new ArrayList<>();
    List<Node> wildcards = new ArrayList<>();
    List<Node> resolved = target.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
    for (Node n : resolved) {
        if (matches(node, n, plugin)) {
            if (isInherited(n, target)) {
                inherited.add(n);
            } else {
                own.add(n);
            }
        }
        if (matchesWildcard(node, n, plugin)) {
            wildcards.add(n);
        }
    }
    // send results
    Message.PERMISSION_CHECK_INFO_HEADER.send(sender, node);
    if (own.isEmpty()) {
        Message.PERMISSION_CHECK_INFO_NOT_DIRECTLY.send(sender, target, node);
    } else {
        for (Node n : own) {
            Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
        }
    }
    if (inherited.isEmpty()) {
        Message.PERMISSION_CHECK_INFO_NOT_INHERITED.send(sender, target, node);
    } else {
        for (Node n : inherited) {
            String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
            Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
        }
    }
    for (Node n : wildcards) {
        if (isInherited(n, target)) {
            String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
            Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
        } else {
            Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
        }
    }
    // blank line
    sender.sendMessage(Message.prefixed(Component.empty()));
    // perform a "real" check
    QueryOptions queryOptions = target.getQueryOptions();
    TristateResult checkResult = target.getCachedData().getPermissionData(queryOptions).checkPermission(node, CheckOrigin.INTERNAL);
    Tristate result = checkResult.result();
    String processor = checkResult.processorClassFriendly();
    Node cause = checkResult.node();
    ImmutableContextSet context = queryOptions.context();
    // send results
    Message.PERMISSION_CHECK_RESULT.send(sender, node, result, processor, cause, context);
}
Also used : Tristate(net.luckperms.api.util.Tristate) AbstractNode(me.lucko.luckperms.common.node.AbstractNode) Node(net.luckperms.api.node.Node) RegexPermissionNode(net.luckperms.api.node.types.RegexPermissionNode) PermissionNode(net.luckperms.api.node.types.PermissionNode) ArrayList(java.util.ArrayList) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) QueryOptions(net.luckperms.api.query.QueryOptions) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult)

Aggregations

TristateResult (me.lucko.luckperms.common.cacheddata.result.TristateResult)14 QueryOptions (net.luckperms.api.query.QueryOptions)6 Node (net.luckperms.api.node.Node)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 PermissionCache (me.lucko.luckperms.common.cacheddata.type.PermissionCache)2 DirectProcessor (me.lucko.luckperms.common.calculator.processor.DirectProcessor)2 AbstractNode (me.lucko.luckperms.common.node.AbstractNode)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 JsonArray (com.google.gson.JsonArray)1 Pattern (java.util.regex.Pattern)1 OpProcessor (me.lucko.luckperms.bukkit.calculator.OpProcessor)1 PermissionProcessor (me.lucko.luckperms.common.calculator.processor.PermissionProcessor)1 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)1 User (me.lucko.luckperms.common.model.User)1 RegexPermission (me.lucko.luckperms.common.node.types.RegexPermission)1 JObject (me.lucko.luckperms.common.util.gson.JObject)1 MetaCheckEvent (me.lucko.luckperms.common.verbose.event.MetaCheckEvent)1 PermissionCheckEvent (me.lucko.luckperms.common.verbose.event.PermissionCheckEvent)1