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