Search in sources :

Example 1 with ChatMetaType

use of net.luckperms.api.node.ChatMetaType in project LuckPerms by lucko.

the class LuckPermsVaultChat method setChatMeta.

private void setChatMeta(PermissionHolder holder, ChatMetaType type, String value, String world) {
    // remove all prefixes/suffixes directly set on the user/group
    holder.removeIf(DataType.NORMAL, null, type.nodeType()::matches, false);
    if (value == null) {
        this.vaultPermission.holderSave(holder);
        return;
    }
    // find the max inherited priority & add 10
    MetaAccumulator metaAccumulator = holder.accumulateMeta(createQueryOptionsForWorldSet(world));
    int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10;
    Node node = type.builder(value, priority).withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()).withContext(DefaultContextKeys.WORLD_KEY, world == null ? "global" : world).build();
    holder.setNode(DataType.NORMAL, node, true);
    this.vaultPermission.holderSave(holder);
}
Also used : ImmutableContextSetImpl(me.lucko.luckperms.common.context.ImmutableContextSetImpl) CheckOrigin(me.lucko.luckperms.common.verbose.event.CheckOrigin) QueryOptions(net.luckperms.api.query.QueryOptions) ChatMetaType(net.luckperms.api.node.ChatMetaType) Meta(me.lucko.luckperms.common.node.types.Meta) DefaultContextKeys(net.luckperms.api.context.DefaultContextKeys) Flag(net.luckperms.api.query.Flag) NodeType(net.luckperms.api.node.NodeType) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) MonitoredMetaCache(me.lucko.luckperms.common.cacheddata.type.MonitoredMetaCache) Strings(com.google.common.base.Strings) Locale(java.util.Locale) Node(net.luckperms.api.node.Node) Suffix(me.lucko.luckperms.common.node.types.Suffix) QueryOptionsImpl(me.lucko.luckperms.common.query.QueryOptionsImpl) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) MetaCache(me.lucko.luckperms.common.cacheddata.type.MetaCache) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) UUID(java.util.UUID) Prefix(me.lucko.luckperms.common.node.types.Prefix) Objects(java.util.Objects) LPBukkitPlugin(me.lucko.luckperms.bukkit.LPBukkitPlugin) Group(me.lucko.luckperms.common.model.Group) Chat(net.milkbowl.vault.chat.Chat) DataType(net.luckperms.api.model.data.DataType) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) Node(net.luckperms.api.node.Node)

Example 2 with ChatMetaType

use of net.luckperms.api.node.ChatMetaType in project LuckPerms by lucko.

the class PermissionHolderSubjectData 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(Prefix.NODE_KEY) || key.equalsIgnoreCase(Suffix.NODE_KEY)) {
        // special handling.
        ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase(Locale.ROOT));
        // remove all prefixes/suffixes from the user
        this.holder.removeIf(this.type, contexts, type.nodeType()::matches, false);
        MetaAccumulator metaAccumulator = this.holder.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build());
        int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
        priority += 10;
        node = type.builder(value, priority).withContext(contexts).build();
    } else {
        // standard remove
        this.holder.removeIf(this.type, contexts, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false);
        node = Meta.builder(key, value).withContext(contexts).build();
    }
    this.holder.setNode(this.type, node, true);
    return save(this.holder).thenApply(v -> true);
}
Also used : PrefixNode(net.luckperms.api.node.types.PrefixNode) ChatMetaType(net.luckperms.api.node.ChatMetaType) Meta(me.lucko.luckperms.common.node.types.Meta) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) NodeType(net.luckperms.api.node.NodeType) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PermissionService(org.spongepowered.api.service.permission.PermissionService) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) Map(java.util.Map) Node(net.luckperms.api.node.Node) Suffix(me.lucko.luckperms.common.node.types.Suffix) HolderType(me.lucko.luckperms.common.model.HolderType) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) SubjectData(org.spongepowered.api.service.permission.SubjectData) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) QueryOptionsImpl(me.lucko.luckperms.common.query.QueryOptionsImpl) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Collection(java.util.Collection) ProxyFactory(me.lucko.luckperms.sponge.service.ProxyFactory) Prefix(me.lucko.luckperms.common.node.types.Prefix) Tristate(net.luckperms.api.util.Tristate) Objects(java.util.Objects) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) NodeBuilders(me.lucko.luckperms.common.node.factory.NodeBuilders) Group(me.lucko.luckperms.common.model.Group) Inheritance(me.lucko.luckperms.common.node.types.Inheritance) User(me.lucko.luckperms.common.model.User) DataType(net.luckperms.api.model.data.DataType) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) PrefixNode(net.luckperms.api.node.types.PrefixNode) Node(net.luckperms.api.node.Node) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MetaNode(net.luckperms.api.node.types.MetaNode) SuffixNode(net.luckperms.api.node.types.SuffixNode) ChatMetaType(net.luckperms.api.node.ChatMetaType)

Aggregations

Locale (java.util.Locale)2 Objects (java.util.Objects)2 MetaAccumulator (me.lucko.luckperms.common.cacheddata.type.MetaAccumulator)2 Group (me.lucko.luckperms.common.model.Group)2 PermissionHolder (me.lucko.luckperms.common.model.PermissionHolder)2 Meta (me.lucko.luckperms.common.node.types.Meta)2 Prefix (me.lucko.luckperms.common.node.types.Prefix)2 Suffix (me.lucko.luckperms.common.node.types.Suffix)2 QueryOptionsImpl (me.lucko.luckperms.common.query.QueryOptionsImpl)2 ImmutableContextSet (net.luckperms.api.context.ImmutableContextSet)2 DataType (net.luckperms.api.model.data.DataType)2 ChatMetaType (net.luckperms.api.node.ChatMetaType)2 Node (net.luckperms.api.node.Node)2 NodeType (net.luckperms.api.node.NodeType)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 Map (java.util.Map)1