Search in sources :

Example 6 with Contexts

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

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

the class AbstractCachedData method reloadPermissions.

@Nonnull
@Override
public CompletableFuture<PermissionCache> reloadPermissions(@Nonnull Contexts contexts) {
    Objects.requireNonNull(contexts, "contexts");
    // get the previous value - to use when recalculating
    PermissionCache previous = this.permission.getIfPresent(contexts);
    // invalidate the entry
    this.permission.invalidate(contexts);
    // repopulate the cache
    return CompletableFuture.supplyAsync(() -> this.permission.get(contexts, c -> calculatePermissions(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) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Nonnull(javax.annotation.Nonnull)

Example 8 with Contexts

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

the class ParentsByWeightHolder 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();
    }
    Set<Group> groups = new LinkedHashSet<>();
    for (Node node : this.user.getOwnNodes(contexts.getContexts())) {
        if (!node.getValuePrimitive() || !node.isGroupNode()) {
            continue;
        }
        Group group = this.user.getPlugin().getGroupManager().getIfLoaded(node.getGroupName());
        if (group != null) {
            groups.add(group);
        }
    }
    Group bestGroup = null;
    if (!groups.isEmpty()) {
        int best = 0;
        for (Group g : groups) {
            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 : LinkedHashSet(java.util.LinkedHashSet) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) Contexts(me.lucko.luckperms.api.Contexts)

Example 9 with Contexts

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

the class DebugCommand method getPlayersData.

private static JObject getPlayersData(LuckPermsPlugin plugin) {
    JObject ret = new JObject();
    Set<UUID> onlinePlayers = plugin.getBootstrap().getOnlinePlayers().collect(Collectors.toSet());
    ret.add("count", onlinePlayers.size());
    JArray playerArray = new JArray();
    for (UUID uuid : onlinePlayers) {
        User user = plugin.getUserManager().getIfLoaded(uuid);
        if (user == null) {
            playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", false));
            continue;
        }
        playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", true).add("username", user.getName().orElse("null")).add("primaryGroup", new JObject().add("type", user.getPrimaryGroup().getClass().getName()).add("value", user.getPrimaryGroup().getValue()).add("storedValue", user.getPrimaryGroup().getStoredValue().orElse("null"))).add("activeContext", () -> {
            JObject obj = new JObject();
            Contexts contexts = plugin.getContextForUser(user).orElse(null);
            if (contexts != null) {
                MetaContexts metaContexts = plugin.getContextManager().formMetaContexts(contexts);
                obj.add("data", new JObject().add("permissions", serializePermissionsData(user.getCachedData().getPermissionData(contexts))).add("meta", serializeMetaData(user.getCachedData().getMetaData(metaContexts)))).add("contextSet", ContextSetJsonSerializer.serializeContextSet(contexts.getContexts())).add("settings", serializeContextsSettings(contexts)).add("metaSettings", serializeMetaContextsSettings(metaContexts));
            }
            return obj;
        }));
    }
    ret.add("players", playerArray);
    return ret;
}
Also used : MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) User(me.lucko.luckperms.common.model.User) JObject(me.lucko.luckperms.common.utils.gson.JObject) UUID(java.util.UUID) Contexts(me.lucko.luckperms.api.Contexts) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) JArray(me.lucko.luckperms.common.utils.gson.JArray)

Example 10 with Contexts

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

the class UserInfo method execute.

@SuppressWarnings("unchecked")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Message status = plugin.getBootstrap().isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
    Message.USER_INFO_GENERAL.send(sender, user.getName().orElse("Unknown"), user.getUuid(), user.getUuid().version() == 4 ? "&2mojang" : "&8offline", status.asString(plugin.getLocaleManager()), user.getPrimaryGroup().getValue());
    Set<Node> parents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isPermanent).collect(Collectors.toSet());
    Set<Node> tempParents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isTemporary).collect(Collectors.toSet());
    if (!parents.isEmpty()) {
        Message.INFO_PARENT_HEADER.send(sender);
        for (Node node : parents) {
            Message.EMPTY.send(sender, "&f-    &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
        }
    }
    if (!tempParents.isEmpty()) {
        Message.INFO_TEMP_PARENT_HEADER.send(sender);
        for (Node node : tempParents) {
            Message.EMPTY.send(sender, "&f-    &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
            Message.EMPTY.send(sender, "&f-    &2-    expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()));
        }
    }
    String context = "&bNone";
    String prefix = "&bNone";
    String suffix = "&bNone";
    String meta = "&bNone";
    Contexts contexts = plugin.getContextForUser(user).orElse(null);
    if (contexts != null) {
        ContextSet contextSet = contexts.getContexts();
        if (!contextSet.isEmpty()) {
            context = contextSet.toSet().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
        }
        MetaData data = user.getCachedData().getMetaData(contexts);
        if (data.getPrefix() != null) {
            prefix = "&f\"" + data.getPrefix() + "&f\"";
        }
        if (data.getSuffix() != null) {
            suffix = "&f\"" + data.getSuffix() + "&f\"";
        }
        ListMultimap<String, String> metaMap = data.getMetaMultimap();
        if (!metaMap.isEmpty()) {
            meta = metaMap.entries().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
        }
    }
    Message.USER_INFO_DATA.send(sender, MessageUtils.formatBoolean(contexts != null), context, prefix, suffix, meta);
    return CommandResult.SUCCESS;
}
Also used : ContextSet(me.lucko.luckperms.api.context.ContextSet) Message(me.lucko.luckperms.common.locale.message.Message) MetaData(me.lucko.luckperms.api.caching.MetaData) Node(me.lucko.luckperms.api.Node) 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