use of me.lucko.luckperms.common.bulkupdate.query.Query in project LuckPerms by lucko.
the class BulkUpdate method appendConstraintsAsSql.
/**
* Appends the constraints of this {@link BulkUpdate} to the provided statement builder in SQL syntax
*
* @param builder the statement builder to append the constraints to
* @return the same statement builder provided as input
*/
public PreparedStatementBuilder appendConstraintsAsSql(PreparedStatementBuilder builder) {
// if there are no constraints, just return without a WHERE clause
if (this.queries.isEmpty()) {
return builder;
}
// append constraints
builder.append(" WHERE");
for (int i = 0; i < this.queries.size(); i++) {
Query query = this.queries.get(i);
builder.append(" ");
if (i != 0) {
builder.append("AND ");
}
query.appendSql(builder);
}
return builder;
}
use of me.lucko.luckperms.common.bulkupdate.query.Query in project LuckPerms by lucko.
the class GroupRename method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, Group target, ArgumentList args, String label) {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
String newGroupName = args.get(0).toLowerCase(Locale.ROOT);
if (!DataConstraints.GROUP_NAME_TEST.test(newGroupName)) {
Message.GROUP_INVALID_ENTRY.send(sender, newGroupName);
return;
}
if (plugin.getStorage().loadGroup(newGroupName).join().isPresent()) {
Message.ALREADY_EXISTS.send(sender, newGroupName);
return;
}
Group newGroup;
try {
newGroup = plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).get();
} catch (Exception e) {
plugin.getLogger().warn("Error whilst creating group", e);
Message.CREATE_ERROR.send(sender, Component.text(newGroupName));
return;
}
try {
plugin.getStorage().deleteGroup(target, DeletionCause.COMMAND).get();
} catch (Exception e) {
plugin.getLogger().warn("Error whilst deleting group", e);
Message.DELETE_ERROR.send(sender, target.getFormattedDisplayName());
return;
}
newGroup.setNodes(DataType.NORMAL, target.normalData().asList(), false);
Message.RENAME_SUCCESS.send(sender, target.getFormattedDisplayName(), newGroup.getFormattedDisplayName());
LoggedAction.build().source(sender).target(target).description("rename", newGroup.getName()).build().submit(plugin, sender);
StorageAssistant.save(newGroup, sender, plugin).thenCompose((v) -> {
if (args.remove("--update-parent-lists")) {
// the group is now renamed, proceed to update its representing inheritance nodes
BulkUpdate operation = BulkUpdateBuilder.create().trackStatistics(false).dataType(me.lucko.luckperms.common.bulkupdate.DataType.ALL).action(UpdateAction.of(QueryField.PERMISSION, Inheritance.key(newGroupName))).query(Query.of(QueryField.PERMISSION, Constraint.of(StandardComparison.EQUAL, Inheritance.key(target.getName())))).build();
return plugin.getStorage().applyBulkUpdate(operation);
} else {
return CompletableFuture.completedFuture(v);
}
}).whenCompleteAsync((v, ex) -> {
if (ex != null) {
ex.printStackTrace();
}
plugin.getSyncTaskBuffer().requestDirectly();
}, plugin.getBootstrap().getScheduler().async());
}
Aggregations