use of net.luckperms.api.model.data.TemporaryNodeMergeStrategy in project LuckPerms by lucko.
the class MetaAddTempChatMeta 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.getPriority(0);
String meta = args.get(1);
Duration duration = args.getDuration(2);
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet 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;
}
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", "addtemp" + 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 net.luckperms.api.model.data.TemporaryNodeMergeStrategy 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 net.luckperms.api.model.data.TemporaryNodeMergeStrategy in project LuckPerms by lucko.
the class ArgumentList method getTemporaryModifierAndRemove.
public Optional<TemporaryNodeMergeStrategy> getTemporaryModifierAndRemove(int index) {
if (indexOutOfBounds(index)) {
return Optional.empty();
}
TemporaryNodeMergeStrategy strategy = parseTemporaryModifier(get(index));
if (strategy == null) {
return Optional.empty();
}
remove(index);
return Optional.of(strategy);
}
use of net.luckperms.api.model.data.TemporaryNodeMergeStrategy in project LuckPerms by lucko.
the class ParentAddTemp 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;
}
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
Duration duration = args.getDuration(1);
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(2).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = args.getContextOrDefault(2, plugin);
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return;
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, group, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (group.getName().equalsIgnoreCase(target.getIdentifier().getName())) {
Message.ALREADY_TEMP_INHERITS.send(sender, target, group, context);
return;
}
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).expiry(duration).withContext(context).build(), modifier);
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, target, group, duration, context);
LoggedAction.build().source(sender).target(target).description("parent", "addtemp", group.getName(), duration, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_TEMP_INHERITS.send(sender, target, group, context);
}
}
use of net.luckperms.api.model.data.TemporaryNodeMergeStrategy in project LuckPerms by lucko.
the class PermissionSetTemp 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;
}
String node = args.get(0);
boolean value = args.getBooleanOrInsert(1, true);
Duration duration = args.getDuration(2);
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = args.getContextOrDefault(3, plugin);
if (node.isEmpty()) {
Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
Node builtNode = NodeBuilders.determineMostApplicable(node).value(value).withContext(context).expiry(duration).build();
if (builtNode instanceof InheritanceNode) {
if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
}
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, builtNode, modifier);
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, target, duration, context);
LoggedAction.build().source(sender).target(target).description("permission", "settemp", node, value, duration, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, target, node, context);
}
}
Aggregations