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);
}
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);
}
Aggregations