Search in sources :

Example 1 with Tristate

use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.

the class DescriptionBuilder method register.

@Override
@NonNull
public PermissionDescription register() throws IllegalStateException {
    if (this.id == null) {
        throw new IllegalStateException("id cannot be null");
    }
    LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
    // Set role-templates
    LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
    for (Map.Entry<String, Tristate> assignment : this.roles.entrySet()) {
        LPSubject roleSubject = subjects.loadSubject(assignment.getKey()).join();
        roleSubject.getTransientSubjectData().setPermission(ImmutableContextSetImpl.EMPTY, this.id, assignment.getValue());
    }
    // null stuff so this instance can be reused
    this.roles.clear();
    this.id = null;
    this.description = null;
    return description.sponge();
}
Also used : Tristate(net.luckperms.api.util.Tristate) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) HashMap(java.util.HashMap) Map(java.util.Map) LPPermissionDescription(me.lucko.luckperms.sponge.service.model.LPPermissionDescription) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 2 with Tristate

use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.

the class BungeePermissionCheckListener method onOtherTristateCheck.

@EventHandler(priority = EventPriority.HIGHEST)
public void onOtherTristateCheck(TristateCheckEvent e) {
    if (e.getSender() instanceof ProxiedPlayer) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    String permission = e.getPermission();
    Tristate result = e.getResult();
    VerboseCheckTarget target = VerboseCheckTarget.internal(e.getSender().getName());
    this.plugin.getVerboseHandler().offerPermissionCheckEvent(CheckOrigin.PLATFORM_API_HAS_PERMISSION_SET, target, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.forMonitoredResult(result));
    this.plugin.getPermissionRegistry().offer(permission);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Tristate(net.luckperms.api.util.Tristate) VerboseCheckTarget(me.lucko.luckperms.common.verbose.VerboseCheckTarget) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with Tristate

use of net.luckperms.api.util.Tristate 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)

Example 4 with Tristate

use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.

the class ArgumentPermissions method checkModifyPerms.

/**
 * Checks if the sender has permission to modify the given target
 *
 * @param plugin the plugin instance
 * @param sender the sender to check
 * @param base the base permission for the command
 * @param target the object the sender is truing to modify
 * @return true if the sender should NOT be allowed to modify the target, true if they should
 */
public static boolean checkModifyPerms(LuckPermsPlugin plugin, Sender sender, CommandPermission base, Object target) {
    if (!plugin.getConfiguration().get(ConfigKeys.USE_ARGUMENT_BASED_COMMAND_PERMISSIONS)) {
        return false;
    }
    if (target instanceof User) {
        User targetUser = (User) target;
        if (targetUser.getUniqueId().equals(sender.getUniqueId())) {
            // the sender is trying to edit themselves
            Tristate state = sender.getPermissionValue(base.getPermission() + ".modify.self");
            if (state != Tristate.UNDEFINED) {
                return !state.asBoolean();
            } else {
                // fallback to the global perm if the one for the specific command is undefined
                Tristate globalState = sender.getPermissionValue(USER_MODIFY_SELF);
                return !globalState.asBoolean();
            }
        } else {
            // they're trying to edit another user
            Tristate state = sender.getPermissionValue(base.getPermission() + ".modify.others");
            if (state != Tristate.UNDEFINED) {
                return !state.asBoolean();
            } else {
                // fallback to the global perm if the one for the specific command is undefined
                Tristate globalState = sender.getPermissionValue(USER_MODIFY_OTHERS);
                return !globalState.asBoolean();
            }
        }
    } else if (target instanceof Group) {
        Group targetGroup = (Group) target;
        Tristate state = sender.getPermissionValue(base.getPermission() + ".modify." + targetGroup.getName());
        if (state != Tristate.UNDEFINED) {
            return !state.asBoolean();
        } else {
            // fallback to the global perm if the one for the specific command is undefined
            Tristate globalState = sender.getPermissionValue(GROUP_MODIFY.apply(targetGroup.getName()));
            return !globalState.asBoolean();
        }
    } else if (target instanceof Track) {
        Track targetTrack = (Track) target;
        Tristate state = sender.getPermissionValue(base.getPermission() + ".modify." + targetTrack.getName());
        if (state != Tristate.UNDEFINED) {
            return !state.asBoolean();
        } else {
            // fallback to the global perm if the one for the specific command is undefined
            Tristate globalState = sender.getPermissionValue(TRACK_MODIFY.apply(targetTrack.getName()));
            return !globalState.asBoolean();
        }
    } else {
        throw new IllegalStateException();
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User) Tristate(net.luckperms.api.util.Tristate) Track(me.lucko.luckperms.common.model.Track)

Example 5 with Tristate

use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.

the class PermissionSet method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) throws CommandException {
    String node = args.get(0);
    Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
    ImmutableContextSet contextSet = args.getContextOrEmpty(2);
    if (subjectData.setPermission(contextSet, node, tristate).join()) {
        SpongeCommandUtils.sendPrefixed(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase(Locale.ROOT) + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        SpongeCommandUtils.sendPrefixed(sender, "Unable to set permission. Does the Subject already have it set?");
    }
}
Also used : Tristate(net.luckperms.api.util.Tristate) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Aggregations

Tristate (net.luckperms.api.util.Tristate)10 User (me.lucko.luckperms.common.model.User)4 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)4 EventHandler (net.md_5.bungee.event.EventHandler)4 QueryOptions (net.luckperms.api.query.QueryOptions)3 Group (me.lucko.luckperms.common.model.Group)2 Track (me.lucko.luckperms.common.model.Track)2 VerboseCheckTarget (me.lucko.luckperms.common.verbose.VerboseCheckTarget)2 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TristateResult (me.lucko.luckperms.common.cacheddata.result.TristateResult)1 AbstractNode (me.lucko.luckperms.common.node.AbstractNode)1 LPPermissionDescription (me.lucko.luckperms.sponge.service.model.LPPermissionDescription)1 LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)1 LPSubjectCollection (me.lucko.luckperms.sponge.service.model.LPSubjectCollection)1 Node (net.luckperms.api.node.Node)1 PermissionNode (net.luckperms.api.node.types.PermissionNode)1 RegexPermissionNode (net.luckperms.api.node.types.RegexPermissionNode)1