Search in sources :

Example 1 with Tristate

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

the class PermissionSet method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
    String node = args.get(0);
    Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
    ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
    if (subjectData.setPermission(contextSet, node, tristate).join()) {
        MessageUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        MessageUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?");
    }
    return CommandResult.SUCCESS;
}
Also used : Tristate(me.lucko.luckperms.api.Tristate) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet)

Example 2 with Tristate

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

the class DescriptionBuilder method register.

@Nonnull
@Override
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(ContextSet.empty(), this.id, assignment.getValue());
    }
    this.service.getPlugin().getPermissionVault().offer(this.id);
    // null stuff so this instance can be reused
    this.roles.clear();
    this.id = null;
    this.description = null;
    return description.sponge();
}
Also used : Tristate(me.lucko.luckperms.api.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(javax.annotation.Nonnull)

Example 3 with Tristate

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

the class DescriptionBuilder method register.

@Nonnull
@Override
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(ContextSet.empty(), this.id, assignment.getValue());
    }
    this.service.getPlugin().getPermissionVault().offer(this.id);
    // null stuff so this instance can be reused
    this.roles.clear();
    this.id = null;
    this.description = null;
    return description.sponge();
}
Also used : Tristate(me.lucko.luckperms.api.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(javax.annotation.Nonnull)

Example 4 with Tristate

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

the class SpongeWildcardProcessor method hasPermission.

@Override
public Tristate hasPermission(String permission) {
    String node = permission;
    while (true) {
        int endIndex = node.lastIndexOf(ImmutableNode.NODE_SEPARATOR);
        if (endIndex == -1) {
            break;
        }
        node = node.substring(0, endIndex);
        if (!node.isEmpty()) {
            Tristate t = Tristate.fromNullableBoolean(this.sourceMap.get(node));
            if (t != Tristate.UNDEFINED) {
                return t;
            }
        }
    }
    return Tristate.UNDEFINED;
}
Also used : Tristate(me.lucko.luckperms.api.Tristate)

Example 5 with Tristate

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

the class VaultPermissionHook method groupHasPermission.

@Override
public boolean groupHasPermission(String world, String name, String permission) {
    Objects.requireNonNull(name, "name");
    Objects.requireNonNull(permission, "permission");
    Group group = getGroup(name);
    if (group == null) {
        return false;
    }
    Contexts contexts = contextForLookup(null, world);
    PermissionCache permissionData = group.getCachedData().getPermissionData(contexts);
    Tristate result = permissionData.getPermissionValue(permission, CheckOrigin.INTERNAL);
    if (log()) {
        logMsg("#groupHasPermission: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), permission, result);
    }
    return result.asBoolean();
}
Also used : Group(me.lucko.luckperms.common.model.Group) Tristate(me.lucko.luckperms.api.Tristate) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Contexts(me.lucko.luckperms.api.Contexts)

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