Async Methods

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

Jan

New member
Apr 15, 2024
5
0
1
I want to create async database requests at the proxy that I can transfer my ban system from my paper server to the velocity proxy. In paper it is realy easy to work with schedulers and make something async like that:

Java:
@Override
public void executeAsyncUpdate(final @NonNull String statement, final @Nullable SqlUpdateCallback callback,
                               final Object... arguments) {
    Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
        try (Connection connection = getConnection()) {
            if (connection == null)
                return;
            try (PreparedStatement preparedStatement = connection.prepareStatement(statement)) {
                if (arguments != null)
                    for (int i = 0; i < arguments.length; i++) {
                        setPreparedData(preparedStatement, i, arguments);
                    }
                int updatedRows = preparedStatement.executeUpdate();
                if (callback != null) {
                    callback.callback(updatedRows, null);
                }
            }
        } catch (final SQLException e) {
            e.printStackTrace();
            if (callback != null) {
                callback.callback(-1, e);
            }
        }
    });
}

But when working with velocity I found the scheduler inside the proxy but the scheduler works differently as in paper. How can I perform my databaserequests async?