Search in sources :

Example 1 with Query

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;
}
Also used : Query(me.lucko.luckperms.common.bulkupdate.query.Query)

Example 2 with Query

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());
}
Also used : DeletionCause(net.luckperms.api.event.cause.DeletionCause) DataConstraints(me.lucko.luckperms.common.storage.misc.DataConstraints) CompletableFuture(java.util.concurrent.CompletableFuture) Constraint(me.lucko.luckperms.common.bulkupdate.comparison.Constraint) BulkUpdate(me.lucko.luckperms.common.bulkupdate.BulkUpdate) StorageAssistant(me.lucko.luckperms.common.command.utils.StorageAssistant) CreationCause(net.luckperms.api.event.cause.CreationCause) Query(me.lucko.luckperms.common.bulkupdate.query.Query) Message(me.lucko.luckperms.common.locale.Message) QueryField(me.lucko.luckperms.common.bulkupdate.query.QueryField) Component(net.kyori.adventure.text.Component) Locale(java.util.Locale) Predicates(me.lucko.luckperms.common.util.Predicates) CommandSpec(me.lucko.luckperms.common.command.spec.CommandSpec) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) StandardComparison(me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison) LoggedAction(me.lucko.luckperms.common.actionlog.LoggedAction) CompletionSupplier(me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier) Sender(me.lucko.luckperms.common.sender.Sender) UpdateAction(me.lucko.luckperms.common.bulkupdate.action.UpdateAction) TabCompleter(me.lucko.luckperms.common.command.tabcomplete.TabCompleter) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) Group(me.lucko.luckperms.common.model.Group) ChildCommand(me.lucko.luckperms.common.command.abstraction.ChildCommand) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Inheritance(me.lucko.luckperms.common.node.types.Inheritance) BulkUpdateBuilder(me.lucko.luckperms.common.bulkupdate.BulkUpdateBuilder) DataType(net.luckperms.api.model.data.DataType) Group(me.lucko.luckperms.common.model.Group) BulkUpdate(me.lucko.luckperms.common.bulkupdate.BulkUpdate)

Aggregations

Query (me.lucko.luckperms.common.bulkupdate.query.Query)2 List (java.util.List)1 Locale (java.util.Locale)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 LoggedAction (me.lucko.luckperms.common.actionlog.LoggedAction)1 BulkUpdate (me.lucko.luckperms.common.bulkupdate.BulkUpdate)1 BulkUpdateBuilder (me.lucko.luckperms.common.bulkupdate.BulkUpdateBuilder)1 UpdateAction (me.lucko.luckperms.common.bulkupdate.action.UpdateAction)1 Constraint (me.lucko.luckperms.common.bulkupdate.comparison.Constraint)1 StandardComparison (me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison)1 QueryField (me.lucko.luckperms.common.bulkupdate.query.QueryField)1 ChildCommand (me.lucko.luckperms.common.command.abstraction.ChildCommand)1 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)1 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)1 CommandSpec (me.lucko.luckperms.common.command.spec.CommandSpec)1 CompletionSupplier (me.lucko.luckperms.common.command.tabcomplete.CompletionSupplier)1 TabCompleter (me.lucko.luckperms.common.command.tabcomplete.TabCompleter)1 ArgumentList (me.lucko.luckperms.common.command.utils.ArgumentList)1 StorageAssistant (me.lucko.luckperms.common.command.utils.StorageAssistant)1 Message (me.lucko.luckperms.common.locale.Message)1