Search in sources :

Example 6 with Tristate

use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.

the class DefaultsProcessor method hasPermission.

@Override
public Tristate hasPermission(String permission) {
    Tristate t = this.plugin.getDefaultPermissionMap().lookupDefaultPermission(permission, this.isOp);
    if (t != Tristate.UNDEFINED) {
        return t;
    }
    Permission defPerm = this.plugin.getPermissionMap().get(permission);
    return defPerm == null ? Tristate.UNDEFINED : Tristate.fromBoolean(defPerm.getDefault().getValue(this.isOp));
}
Also used : Tristate(me.lucko.luckperms.api.Tristate) Permission(org.bukkit.permissions.Permission)

Example 7 with Tristate

use of me.lucko.luckperms.api.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();
    String name = "internal/" + e.getSender().getName();
    this.plugin.getVerboseHandler().offerCheckData(CheckOrigin.PLATFORM_LOOKUP_CHECK, name, ContextSet.empty(), permission, result);
    this.plugin.getPermissionVault().offer(permission);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Tristate(me.lucko.luckperms.api.Tristate) EventHandler(net.md_5.bungee.event.EventHandler)

Example 8 with Tristate

use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.

the class CheckCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    String target = args.get(0);
    String permission = args.get(1);
    User user;
    UUID u = Uuids.parseNullable(target);
    if (u != null) {
        user = plugin.getUserManager().getIfLoaded(u);
    } else {
        user = plugin.getUserManager().getByUsername(target);
    }
    if (user == null) {
        Message.USER_NOT_ONLINE.send(sender, target);
        return CommandResult.STATE_ERROR;
    }
    Tristate tristate = user.getCachedData().getPermissionData(plugin.getContextForUser(user).orElse(plugin.getContextManager().getStaticContexts())).getPermissionValue(permission, CheckOrigin.INTERNAL);
    Message.CHECK_RESULT.send(sender, user.getFriendlyName(), permission, MessageUtils.formatTristate(tristate));
    return CommandResult.SUCCESS;
}
Also used : User(me.lucko.luckperms.common.model.User) Tristate(me.lucko.luckperms.api.Tristate) UUID(java.util.UUID)

Example 9 with Tristate

use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.

the class PermissionCheck method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    String node = ArgumentParser.parseString(0, args);
    MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
    Tristate result = holder.hasPermission(NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
    String s = MessageUtils.formatTristate(result);
    Message.CHECK_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context));
    return CommandResult.SUCCESS;
}
Also used : MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Tristate(me.lucko.luckperms.api.Tristate)

Example 10 with Tristate

use of me.lucko.luckperms.api.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.getUuid().equals(sender.getUuid())) {
            // the sender is trying to edit themselves
            Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.self");
            if (ret != Tristate.UNDEFINED) {
                return !ret.asBoolean();
            } else {
                // fallback to the global perm if the one for the specific command is undefined
                Tristate globalRet = sender.getPermissionValue(USER_MODIFY_SELF);
                return !globalRet.asBoolean();
            }
        } else {
            // they're trying to edit another user
            Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.others");
            if (ret != Tristate.UNDEFINED) {
                return !ret.asBoolean();
            } else {
                // fallback to the global perm if the one for the specific command is undefined
                Tristate globalRet = sender.getPermissionValue(USER_MODIFY_OTHERS);
                return !globalRet.asBoolean();
            }
        }
    } else if (target instanceof Group) {
        Group targetGroup = ((Group) target);
        Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify." + targetGroup.getName());
        if (ret != Tristate.UNDEFINED) {
            return !ret.asBoolean();
        } else {
            // fallback to the global perm if the one for the specific command is undefined
            Tristate globalRet = sender.getPermissionValue(GROUP_MODIFY.apply(targetGroup.getName()));
            return !globalRet.asBoolean();
        }
    } else if (target instanceof Track) {
        Track targetTrack = ((Track) target);
        Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify." + targetTrack.getName());
        if (ret != Tristate.UNDEFINED) {
            return !ret.asBoolean();
        } else {
            // fallback to the global perm if the one for the specific command is undefined
            Tristate globalRet = sender.getPermissionValue(TRACK_MODIFY.apply(targetTrack.getName()));
            return !globalRet.asBoolean();
        }
    } else {
        throw new IllegalStateException();
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User) Tristate(me.lucko.luckperms.api.Tristate) Track(me.lucko.luckperms.common.model.Track)

Aggregations

Tristate (me.lucko.luckperms.api.Tristate)20 User (me.lucko.luckperms.common.model.User)6 Contexts (me.lucko.luckperms.api.Contexts)4 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)4 EventHandler (net.md_5.bungee.event.EventHandler)4 Group (me.lucko.luckperms.common.model.Group)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Nonnull (javax.annotation.Nonnull)2 PermissionCache (me.lucko.luckperms.common.caching.type.PermissionCache)2 Track (me.lucko.luckperms.common.model.Track)2 LPPermissionDescription (me.lucko.luckperms.sponge.service.model.LPPermissionDescription)2 LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)2 LPSubjectCollection (me.lucko.luckperms.sponge.service.model.LPSubjectCollection)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 UUID (java.util.UUID)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 ScriptEngine (javax.script.ScriptEngine)1