Search in sources :

Example 1 with MetaAccumulator

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

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

the class MetaSetTempChatMeta method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    int priority = args.getIntOrDefault(0, Integer.MIN_VALUE);
    String meta;
    Duration duration;
    TemporaryNodeMergeStrategy modifier;
    MutableContextSet context;
    if (priority == Integer.MIN_VALUE) {
        // priority wasn't defined, meta is at index 0, duration at index 1
        meta = args.get(0);
        duration = args.getDuration(1);
        modifier = args.getTemporaryModifierAndRemove(2).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
        context = args.getContextOrDefault(2, plugin);
    } else {
        // priority was defined, meta should be at index 1, duration at index 2
        if (args.size() <= 2) {
            sendDetailedUsage(sender);
            return;
        }
        meta = args.get(1);
        duration = args.getDuration(2);
        modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
        context = args.getContextOrDefault(3, plugin);
    }
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    // remove all other prefixes/suffixes set in these contexts
    target.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
    // determine the priority to set at
    if (priority == Integer.MIN_VALUE) {
        MetaAccumulator metaAccumulator = target.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
        priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;
        if (target instanceof Group) {
            OptionalInt weight = target.getWeight();
            if (weight.isPresent() && weight.getAsInt() > priority) {
                priority = weight.getAsInt();
            }
        }
    }
    DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).expiry(duration).withContext(context).build(), modifier);
    if (result.getResult().wasSuccessful()) {
        duration = result.getMergedNode().getExpiryDuration();
        Message.ADD_TEMP_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, duration, context);
        LoggedAction.build().source(sender).target(target).description("meta", "settemp" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, duration, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, target, this.type, meta, priority, context);
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) TemporaryNodeMergeStrategy(net.luckperms.api.model.data.TemporaryNodeMergeStrategy) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) MutableContextSet(net.luckperms.api.context.MutableContextSet) Duration(java.time.Duration) OptionalInt(java.util.OptionalInt) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 3 with MetaAccumulator

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

the class AbstractCachedDataManager method calculateMeta.

private MonitoredMetaCache calculateMeta(QueryOptions queryOptions) {
    Objects.requireNonNull(queryOptions, "queryOptions");
    CacheMetadata metadata = getMetadataForQueryOptions(queryOptions);
    MetaAccumulator accumulator = newAccumulator(queryOptions);
    resolveMeta(accumulator, queryOptions);
    return new MonitoredMetaCache(this.plugin, queryOptions, metadata, accumulator);
}
Also used : MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) MonitoredMetaCache(me.lucko.luckperms.common.cacheddata.type.MonitoredMetaCache)

Example 4 with MetaAccumulator

use of me.lucko.luckperms.common.cacheddata.type.MetaAccumulator 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)

Example 5 with MetaAccumulator

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

the class MetaSetChatMeta method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    int priority = args.getIntOrDefault(0, Integer.MIN_VALUE);
    String meta;
    MutableContextSet context;
    if (priority == Integer.MIN_VALUE) {
        // priority wasn't defined, meta is at index 0, contexts at index 1
        meta = args.get(0);
        context = args.getContextOrDefault(1, plugin);
    } else {
        // priority was defined, meta should be at index 1, contexts at index 2
        if (args.size() <= 1) {
            sendDetailedUsage(sender);
            return;
        }
        meta = args.get(1);
        context = args.getContextOrDefault(2, plugin);
    }
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    // remove all other prefixes/suffixes set in these contexts
    target.removeIf(DataType.NORMAL, context, this.type.nodeType()::matches, false);
    // determine the priority to set at
    if (priority == Integer.MIN_VALUE) {
        MetaAccumulator metaAccumulator = target.accumulateMeta(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
        priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;
        if (target instanceof Group) {
            OptionalInt weight = target.getWeight();
            if (weight.isPresent() && weight.getAsInt() > priority) {
                priority = weight.getAsInt();
            }
        }
    }
    DataMutateResult result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
    if (result.wasSuccessful()) {
        Message.ADD_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, context);
        LoggedAction.build().source(sender).target(target).description("meta", "set" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, context).build().submit(plugin, sender);
        StorageAssistant.save(target, sender, plugin);
    } else {
        Message.ALREADY_HAS_CHAT_META.send(sender, target, this.type, meta, priority, context);
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) MetaAccumulator(me.lucko.luckperms.common.cacheddata.type.MetaAccumulator) MutableContextSet(net.luckperms.api.context.MutableContextSet) OptionalInt(java.util.OptionalInt) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Aggregations

MetaAccumulator (me.lucko.luckperms.common.cacheddata.type.MetaAccumulator)5 Group (me.lucko.luckperms.common.model.Group)4 Locale (java.util.Locale)2 Objects (java.util.Objects)2 OptionalInt (java.util.OptionalInt)2 MonitoredMetaCache (me.lucko.luckperms.common.cacheddata.type.MonitoredMetaCache)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 Duration (java.time.Duration)1