use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentAdd 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);
MutableContextSet context = args.getContextOrDefault(1, 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;
}
DataMutateResult result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
if (result.wasSuccessful()) {
Message.SET_INHERIT_SUCCESS.send(sender, target, group, context);
LoggedAction.build().source(sender).target(target).description("parent", "add", group.getName(), context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_INHERITS.send(sender, target, group, context);
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class PermissionSet 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);
MutableContextSet context = args.getContextOrDefault(2, 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).build();
if (builtNode instanceof InheritanceNode) {
if (ArgumentPermissions.checkGroup(plugin, sender, ((InheritanceNode) builtNode).getGroupName(), context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
}
DataMutateResult result = target.setNode(DataType.NORMAL, builtNode, true);
if (result.wasSuccessful()) {
Message.SETPERMISSION_SUCCESS.send(sender, node, value, target, context);
LoggedAction.build().source(sender).target(target).description("permission", "set", node, value, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_HASPERMISSION.send(sender, target, node, context);
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ContextSetConfigurateSerializer method deserializeContextSet.
public static ContextSet deserializeContextSet(ConfigurationNode data) {
Preconditions.checkArgument(data.isMap());
Map<Object, ? extends ConfigurationNode> dataMap = data.getChildrenMap();
if (dataMap.isEmpty()) {
return ImmutableContextSetImpl.EMPTY;
}
MutableContextSet map = new MutableContextSetImpl();
for (Map.Entry<Object, ? extends ConfigurationNode> e : dataMap.entrySet()) {
String k = e.getKey().toString();
ConfigurationNode v = e.getValue();
if (v.isList()) {
for (ConfigurationNode value : v.getChildrenList()) {
map.add(k, value.getString());
}
} else {
map.add(k, v.getString());
}
}
return map;
}
Aggregations