make sql auto sync if not main thread

This commit is contained in:
Govindas 2021-03-16 15:05:26 +02:00
parent 9e7c5fcbee
commit 0c16b98553
3 changed files with 10 additions and 10 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.btk5h</groupId>
<artifactId>skript-db</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
<packaging>jar</packaging>
<repositories>

View File

@ -80,11 +80,12 @@ public class EffExecuteStatement extends Effect {
String baseVariable = var != null ? var.toString(e).toLowerCase(Locale.ENGLISH) : null;
//if data source isn't set
if (ds == null)
return;
if (ds == null) return;
boolean sync = false;
if (!Bukkit.isPrimaryThread()) {
sync = true;
}
Object locals = Variables.removeLocals(e);
//execute SQL statement
@ -92,11 +93,10 @@ public class EffExecuteStatement extends Effect {
CompletableFuture.supplyAsync(() -> executeStatement(ds, baseVariable, query), threadPool);
//when SQL statement is completed
sql.whenComplete((res, err) -> {
boolean finalSync = sync;
sql.whenComplete((res, err) -> {
if (err != null) { err.printStackTrace(); }
// Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> {
//handle last error syntax data
lastError = null;
if (res instanceof String) {
@ -117,7 +117,7 @@ public class EffExecuteStatement extends Effect {
((Map<String, Object>) res).forEach((name, value) -> setVariable(event, name, value));
SkriptDB.getPlugin(SkriptDB.class).getServer().getPluginManager().callEvent(event);
}
if (isSync) {
if (isSync || finalSync) {
Variables.setLocalVariables(e, locals);
if (!(res instanceof String)) { ((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value)); }

View File

@ -1,5 +1,5 @@
name: skript-db
version: 1.3.0
version: 1.3.1
main: com.btk5h.skriptdb.SkriptDB
depend: [Skript]
authors: [btk5h, FranKusmiruk, Govindas]