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