Search in sources :

Example 1 with Contexts

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

the class AllParentsByWeightHolder method calculateValue.

@Override
protected String calculateValue() {
    Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
    if (contexts == null) {
        contexts = this.user.getPlugin().getContextManager().getStaticContexts();
    }
    InheritanceGraph graph = this.user.getPlugin().getInheritanceHandler().getGraph(contexts);
    // fully traverse the graph, obtain a list of permission holders the user inherits from
    List<PermissionHolder> traversal = ImmutableList.copyOf(graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this.user));
    Group bestGroup = null;
    if (!traversal.isEmpty()) {
        int best = 0;
        for (PermissionHolder holder : traversal) {
            if (!(holder instanceof Group)) {
                continue;
            }
            Group g = ((Group) holder);
            int weight = g.getWeight().orElse(0);
            if (bestGroup == null || g.getWeight().orElse(0) > best) {
                bestGroup = g;
                best = weight;
            }
        }
    }
    return bestGroup == null ? null : bestGroup.getName();
}
Also used : Group(me.lucko.luckperms.common.model.Group) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Contexts(me.lucko.luckperms.api.Contexts) InheritanceGraph(me.lucko.luckperms.common.inheritance.InheritanceGraph)

Example 2 with Contexts

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

the class VaultChatHook method getGroupMeta.

@Override
public String getGroupMeta(String world, String name, String key) {
    Objects.requireNonNull(name, "name");
    Objects.requireNonNull(key, "key");
    Group group = getGroup(name);
    if (group == null) {
        return null;
    }
    Contexts contexts = this.permissionHook.contextForLookup(null, world);
    MetaCache metaData = group.getCachedData().getMetaData(contexts);
    String ret = metaData.getMeta().get(key);
    if (log()) {
        logMsg("#getGroupMeta: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), key, ret);
    }
    return ret;
}
Also used : Group(me.lucko.luckperms.common.model.Group) Contexts(me.lucko.luckperms.api.Contexts) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache)

Example 3 with Contexts

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

the class VaultChatHook method getGroupChatPrefix.

@Override
public String getGroupChatPrefix(String world, String name) {
    Objects.requireNonNull(name, "name");
    Group group = getGroup(name);
    if (group == null) {
        return null;
    }
    Contexts contexts = this.permissionHook.contextForLookup(null, world);
    MetaCache metaData = group.getCachedData().getMetaData(contexts);
    String ret = metaData.getPrefix();
    if (log()) {
        logMsg("#getGroupPrefix: %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), ret);
    }
    return Strings.nullToEmpty(ret);
}
Also used : Group(me.lucko.luckperms.common.model.Group) Contexts(me.lucko.luckperms.api.Contexts) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache)

Example 4 with Contexts

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

the class VaultPermissionHook method userGetGroups.

@Override
public String[] userGetGroups(String world, UUID uuid) {
    if (uuid == null) {
        return new String[0];
    }
    User user = getUser(uuid);
    if (user == null) {
        return new String[0];
    }
    ContextSet contexts = contextForLookup(user, world).getContexts();
    String[] ret = user.getEnduringNodes().values().stream().filter(Node::isGroupNode).filter(n -> n.shouldApplyWithContext(contexts)).map(n -> {
        Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
        if (group != null) {
            return group.getDisplayName().orElse(group.getName());
        }
        return n.getGroupName();
    }).toArray(String[]::new);
    if (log()) {
        logMsg("#userGetGroups: %s - %s - %s", user.getFriendlyName(), contexts, Arrays.toString(ret));
    }
    return ret;
}
Also used : ContextSet(me.lucko.luckperms.api.context.ContextSet) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Arrays(java.util.Arrays) CommandManager(me.lucko.luckperms.common.command.CommandManager) CheckOrigin(me.lucko.luckperms.common.verbose.CheckOrigin) Contexts(me.lucko.luckperms.api.Contexts) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Tristate(me.lucko.luckperms.api.Tristate) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Player(org.bukkit.entity.Player) UUID(java.util.UUID) ContextSet(me.lucko.luckperms.api.context.ContextSet) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) LPBukkitPlugin(me.lucko.luckperms.bukkit.LPBukkitPlugin) Group(me.lucko.luckperms.common.model.Group) Preconditions(com.google.common.base.Preconditions) Node(me.lucko.luckperms.api.Node) User(me.lucko.luckperms.common.model.User) ExecutorService(java.util.concurrent.ExecutorService) Permission(net.milkbowl.vault.permission.Permission) Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User)

Example 5 with Contexts

use of me.lucko.luckperms.api.Contexts 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

Contexts (me.lucko.luckperms.api.Contexts)18 MetaCache (me.lucko.luckperms.common.caching.type.MetaCache)8 User (me.lucko.luckperms.common.model.User)8 Group (me.lucko.luckperms.common.model.Group)7 Tristate (me.lucko.luckperms.api.Tristate)5 PermissionCache (me.lucko.luckperms.common.caching.type.PermissionCache)5 Objects (java.util.Objects)3 Node (me.lucko.luckperms.api.Node)3 MetaContexts (me.lucko.luckperms.api.caching.MetaContexts)3 CacheLoader (com.github.benmanes.caffeine.cache.CacheLoader)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)2 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TimeUnit (java.util.concurrent.TimeUnit)2 Nonnull (javax.annotation.Nonnull)2 ChatMetaType (me.lucko.luckperms.api.ChatMetaType)2