0

Hello i am generally new to java and working on Minecraft Plugins to get started.

Here is my problem. I am trying to call this method on the main server thread and get the return value.

Here is what i am trying to achieve.

 private String FetchEntry(String TableName, String KeyID, String ColumnName) {

    String value = "NOTHING";

        Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(LGCore.plugin, new Runnable() {
        @Override
        public void run() {

            try {
                ResultSet resultSet;
                resultSet = GetConnection().createStatement().executeQuery("SELECT " + ColumnName + " FROM " + TableName + " WHERE IdKey='" + KeyID + "';");
                resultSet.first();
                String returnvalue = resultSet.getString(1);
                //Here i would like to set value to returnvalue and return it                     

            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    });

    return value;

}

1 Answers1

-1

You seem to be calling a method that schedules an asynchronous task. But an asynchronous task directly returning a value without blocking is sort of like an oxymoron: If it would directly return a value, it would be a synchronous operation. The idea of asynchronous operations is that you run the operation to retrieve the result later when it's ready, but your main thread continues to run. So you need to store the result of your asynchronous task in a place that's accessible by your main thread when it's ready.

I'm not familiar with the Minecraft code base, but I hope this helps anyway.

erikd71
  • 279
  • 2
  • 5