Search in sources :

Example 1 with MetaAccumulator

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

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

the class VaultChatHook method setChatMeta.

private void setChatMeta(PermissionHolder holder, ChatMetaType type, String value, String world) {
    if (log()) {
        logMsg("#setChatMeta: %s - %s - %s - %s", holder.getFriendlyName(), type, value, world);
    }
    this.permissionHook.getExecutor().execute(() -> {
        // remove all prefixes/suffixes directly set on the user/group
        holder.removeIf(type::matches);
        if (value == null) {
            this.permissionHook.holderSave(holder);
            return;
        }
        // find the max inherited priority & add 10
        MetaAccumulator metaAccumulator = holder.accumulateMeta(null, createContextForWorldSet(world));
        int priority = (type == ChatMetaType.PREFIX ? metaAccumulator.getPrefixes() : metaAccumulator.getSuffixes()).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10;
        Node.Builder chatMetaNode = NodeFactory.buildChatMetaNode(type, priority, value);
        chatMetaNode.setServer(this.permissionHook.getVaultServer());
        chatMetaNode.setWorld(world);
        holder.setPermission(chatMetaNode.build());
        this.permissionHook.holderSave(holder);
    });
}
Also used : CommandManager(me.lucko.luckperms.common.command.CommandManager) Contexts(me.lucko.luckperms.api.Contexts) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) UUID(java.util.UUID) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) Objects(java.util.Objects) Strings(com.google.common.base.Strings) LPBukkitPlugin(me.lucko.luckperms.bukkit.LPBukkitPlugin) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) Chat(net.milkbowl.vault.chat.Chat) User(me.lucko.luckperms.common.model.User) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) Node(me.lucko.luckperms.api.Node)

Example 3 with MetaAccumulator

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

the class HolderSubjectData method setOption.

@Override
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
    Objects.requireNonNull(contexts, "contexts");
    Objects.requireNonNull(key, "key");
    Objects.requireNonNull(value, "value");
    Node node;
    if (key.equalsIgnoreCase(NodeFactory.PREFIX_KEY) || key.equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
        // special handling.
        ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
        // remove all prefixes/suffixes from the user
        List<Node> toRemove = streamNodes().filter(type::matches).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
        toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
        MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, this.service.getPlugin().getContextManager().formContexts(contexts));
        int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
        priority += 10;
        node = NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(contexts).build();
    } else {
        // standard remove
        List<Node> toRemove = streamNodes().filter(n -> n.isMeta() && n.getMeta().getKey().equals(key)).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
        toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
        node = NodeFactory.buildMetaNode(key, value).withExtraContext(contexts).build();
    }
    this.type.run(() -> this.holder.setPermission(node), () -> this.holder.setTransientPermission(node));
    return objectSave(this.holder).thenApply(v -> true);
}
Also used : DataMutateResult(me.lucko.luckperms.api.DataMutateResult) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) Tristate(me.lucko.luckperms.api.Tristate) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PermissionService(org.spongepowered.api.service.permission.PermissionService) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SubjectData(org.spongepowered.api.service.permission.SubjectData) ProxyFactory(me.lucko.luckperms.sponge.service.proxy.ProxyFactory) ImmutableMap(com.google.common.collect.ImmutableMap) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Collection(java.util.Collection) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) List(java.util.List) Stream(java.util.stream.Stream) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) NodeMapType(me.lucko.luckperms.common.model.NodeMapType) User(me.lucko.luckperms.common.model.User) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) Node(me.lucko.luckperms.api.Node) ChatMetaType(me.lucko.luckperms.api.ChatMetaType)

Aggregations

MetaAccumulator (me.lucko.luckperms.common.caching.type.MetaAccumulator)3 Objects (java.util.Objects)2 ChatMetaType (me.lucko.luckperms.api.ChatMetaType)2 Node (me.lucko.luckperms.api.Node)2 ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)2 MetaCache (me.lucko.luckperms.common.caching.type.MetaCache)2 Group (me.lucko.luckperms.common.model.Group)2 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)2 User (me.lucko.luckperms.common.model.User)2 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1