Search in sources :

Example 6 with Tristate

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

the class ArgumentPermissions method checkViewPerms.

/**
 * Checks if the sender has permission to view 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 view
 * @return true if the sender should NOT be allowed to view the target, true if they should
 */
public static boolean checkViewPerms(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 view themselves
            Tristate state = sender.getPermissionValue(base.getPermission() + ".view.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_VIEW_SELF);
                return !globalState.asBoolean();
            }
        } else {
            // they're trying to view another user
            Tristate state = sender.getPermissionValue(base.getPermission() + ".view.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_VIEW_OTHERS);
                return !globalState.asBoolean();
            }
        }
    } else if (target instanceof Group) {
        Group targetGroup = (Group) target;
        Tristate state = sender.getPermissionValue(base.getPermission() + ".view." + 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_VIEW.apply(targetGroup.getName()));
            return !globalState.asBoolean();
        }
    } else if (target instanceof Track) {
        Track targetTrack = (Track) target;
        Tristate state = sender.getPermissionValue(base.getPermission() + ".view." + 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_VIEW.apply(targetTrack.getName()));
            return !globalState.asBoolean();
        }
    }
    return false;
}
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 7 with Tristate

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

the class BungeePermissionCheckListener method onPlayerPermissionCheck.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
    if (!(e.getSender() instanceof ProxiedPlayer)) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    ProxiedPlayer player = (ProxiedPlayer) e.getSender();
    User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
    if (user == null) {
        this.plugin.getLogger().warn("A permission check was made for player " + player.getName() + " - " + player.getUniqueId() + ", " + "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?", new Exception());
        e.setHasPermission(false);
        return;
    }
    QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player);
    Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), CheckOrigin.PLATFORM_API_HAS_PERMISSION).result();
    if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
        // just use the result provided by the proxy when the event was created
        return;
    }
    e.setHasPermission(result.asBoolean());
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) User(me.lucko.luckperms.common.model.User) Tristate(net.luckperms.api.util.Tristate) QueryOptions(net.luckperms.api.query.QueryOptions) EventHandler(net.md_5.bungee.event.EventHandler)

Example 8 with Tristate

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

the class BungeePermissionCheckListener method onPlayerTristateCheck.

@EventHandler
public void onPlayerTristateCheck(TristateCheckEvent e) {
    if (!(e.getSender() instanceof ProxiedPlayer)) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    ProxiedPlayer player = (ProxiedPlayer) e.getSender();
    User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
    if (user == null) {
        this.plugin.getLogger().warn("A permission check was made for player " + player.getName() + " - " + player.getUniqueId() + ", " + "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?", new Exception());
        e.setResult(Tristate.UNDEFINED);
        return;
    }
    QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player);
    Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), CheckOrigin.PLATFORM_API_HAS_PERMISSION_SET).result();
    if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
        // just use the result provided by the proxy when the event was created
        return;
    }
    e.setResult(result);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) User(me.lucko.luckperms.common.model.User) Tristate(net.luckperms.api.util.Tristate) QueryOptions(net.luckperms.api.query.QueryOptions) EventHandler(net.md_5.bungee.event.EventHandler)

Example 9 with Tristate

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

the class BungeePermissionCheckListener method onOtherPermissionCheck.

@EventHandler(priority = EventPriority.HIGHEST)
public void onOtherPermissionCheck(PermissionCheckEvent e) {
    if (e.getSender() instanceof ProxiedPlayer) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    String permission = e.getPermission();
    Tristate result = Tristate.of(e.hasPermission());
    VerboseCheckTarget target = VerboseCheckTarget.internal(e.getSender().getName());
    this.plugin.getVerboseHandler().offerPermissionCheckEvent(CheckOrigin.PLATFORM_API_HAS_PERMISSION, 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 10 with Tristate

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

the class SpongeSenderFactory method getPermissionValue.

@Override
protected Tristate getPermissionValue(Audience source, String node) {
    if (!(source instanceof Subject)) {
        throw new IllegalStateException("Source is not a subject");
    }
    final Subject subject = (Subject) source;
    Tristate result = CompatibilityUtil.convertTristate(subject.permissionValue(node));
    // check the permdefault
    if (result == Tristate.UNDEFINED && subject.hasPermission(node)) {
        result = Tristate.TRUE;
    }
    return result;
}
Also used : Tristate(net.luckperms.api.util.Tristate) SystemSubject(org.spongepowered.api.SystemSubject) Subject(org.spongepowered.api.service.permission.Subject)

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