use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class PermissionUnsetTemp 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);
Duration duration = args.getDurationOrDefault(1, null);
int fromIndex = duration == null ? 1 : 2;
MutableContextSet context = args.getContextOrDefault(fromIndex, 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).expiry(10L).withContext(context).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.unsetNode(DataType.NORMAL, builtNode, duration);
if (result.getResult().wasSuccessful()) {
Node mergedNode = result.getMergedNode();
// noinspection ConstantConditions
if (mergedNode != null) {
Message.UNSET_TEMP_PERMISSION_SUBTRACT_SUCCESS.send(sender, mergedNode.getKey(), mergedNode.getValue(), target, mergedNode.getExpiryDuration(), context, duration);
LoggedAction.build().source(sender).target(target).description("permission", "unsettemp", node, duration, context).build().submit(plugin, sender);
} else {
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, target, context);
LoggedAction.build().source(sender).target(target).description("permission", "unsettemp", node, context).build().submit(plugin, sender);
}
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, target, node, context);
}
}
use of net.luckperms.api.context.MutableContextSet 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.context.MutableContextSet 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.context.MutableContextSet in project LuckPerms by lucko.
the class ArgumentList method parseContext.
private MutableContextSet parseContext(int fromIndex) {
MutableContextSet contextSet = new MutableContextSetImpl();
List<String> entries = subList(fromIndex, size());
for (int i = 0; i < entries.size(); i++) {
String entry = entries.get(i);
int sep = entry.indexOf('=');
String key;
String value;
if (sep != -1) {
key = entry.substring(0, sep);
value = entry.substring(sep + 1);
} else {
key = i == 1 ? DefaultContextKeys.WORLD_KEY : DefaultContextKeys.SERVER_KEY;
value = entry;
}
if (!Context.isValidKey(key) || !Context.isValidValue(value)) {
continue;
}
contextSet.add(key, value);
}
return contextSet;
}
use of net.luckperms.api.context.MutableContextSet 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