Search in sources :

Example 1 with MetaCache

use of me.lucko.luckperms.common.caching.type.MetaCache 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 2 with MetaCache

use of me.lucko.luckperms.common.caching.type.MetaCache 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 3 with MetaCache

use of me.lucko.luckperms.common.caching.type.MetaCache in project LuckPerms by lucko.

the class AbstractCachedData method calculateMeta.

/**
 * Calculates a {@link MetaCache} instance.
 *
 * @param contexts the contexts to calculate in
 * @param data an old data instance to try to reuse - ignored if null
 * @return the calculated instance
 */
private MetaCache calculateMeta(MetaContexts contexts, MetaCache data) {
    Objects.requireNonNull(contexts, "contexts");
    if (data == null) {
        data = new MetaCache(contexts);
    }
    MetaAccumulator accumulator = newAccumulator(contexts);
    if (contexts.getContexts() == Contexts.allowAll()) {
        resolveMeta(accumulator);
    } else {
        resolveMeta(accumulator, contexts);
    }
    data.loadMeta(accumulator);
    return data;
}
Also used : MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache)

Example 4 with MetaCache

use of me.lucko.luckperms.common.caching.type.MetaCache in project LuckPerms by lucko.

the class AbstractCachedData method reloadMeta.

@Nonnull
@Override
public CompletableFuture<MetaCache> reloadMeta(@Nonnull MetaContexts contexts) {
    Objects.requireNonNull(contexts, "contexts");
    // get the previous value - to use when recalculating
    MetaCache previous = this.meta.getIfPresent(contexts);
    // invalidate the entry
    this.meta.invalidate(contexts);
    // repopulate the cache
    return CompletableFuture.supplyAsync(() -> this.meta.get(contexts, c -> calculateMeta(c, previous)));
}
Also used : PermissionCalculatorMetadata(me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) FullySatisfiedContexts(me.lucko.luckperms.api.FullySatisfiedContexts) CacheLoader(com.github.benmanes.caffeine.cache.CacheLoader) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Contexts(me.lucko.luckperms.api.Contexts) PermissionCalculator(me.lucko.luckperms.common.calculators.PermissionCalculator) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Set(java.util.Set) CachedData(me.lucko.luckperms.api.caching.CachedData) CompletableFuture(java.util.concurrent.CompletableFuture) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) CalculatorFactory(me.lucko.luckperms.common.calculators.CalculatorFactory) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) HashSet(java.util.HashSet) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) SimpleMetaStack(me.lucko.luckperms.common.metastacking.SimpleMetaStack) Map(java.util.Map) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Nonnull(javax.annotation.Nonnull) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) Nonnull(javax.annotation.Nonnull)

Example 5 with MetaCache

use of me.lucko.luckperms.common.caching.type.MetaCache in project LuckPerms by lucko.

the class VaultChatHook method getUserMeta.

@Override
public String getUserMeta(String world, UUID uuid, String key) {
    if (uuid == null) {
        return null;
    }
    Objects.requireNonNull(key, "key");
    User user = getUser(uuid);
    if (user == null) {
        return null;
    }
    Contexts contexts = this.permissionHook.contextForLookup(user, world);
    MetaCache metaData = user.getCachedData().getMetaData(contexts);
    String ret = metaData.getMeta().get(key);
    if (log()) {
        logMsg("#getUserMeta: %s - %s - %s - %s", user.getFriendlyName(), contexts.getContexts().toMultimap(), key, ret);
    }
    return ret;
}
Also used : User(me.lucko.luckperms.common.model.User) Contexts(me.lucko.luckperms.api.Contexts) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache)

Aggregations

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