From c85d579645743a54be383be858d4719f2771e0bd Mon Sep 17 00:00:00 2001 From: Govindas Date: Sat, 26 Jun 2021 13:10:19 +0300 Subject: [PATCH] fix expressions in queries, thanks to TPGamesNL --- .../skriptdb/skript/EffExecuteStatement.java | 58 ++++++++++--------- src/main/resources/plugin.yml | 2 +- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java b/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java index a09f98a..53db2bc 100644 --- a/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java +++ b/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java @@ -105,21 +105,31 @@ public class EffExecuteStatement extends Effect { if (getNext() != null) { //if local variables are present - //bring back local variables + //bring back local variables - //populate SQL data into variables - if (!(res instanceof String)) { + //populate SQL data into variables + if (!(res instanceof String)) { - //also set variables in the sql query complete event + //also set variables in the sql query complete event - //TEMPORARILY DISABLED, AS THIS WOULD WORSEN PERFORMANCE OF THE QUERIES AND NOT BE USED BY MOST PEOPLE. - //I may add config option to enable this later? + //TEMPORARILY DISABLED, AS THIS WOULD WORSEN PERFORMANCE OF THE QUERIES AND NOT BE USED BY MOST PEOPLE. + //I may add config option to enable this later? - //SQLQueryCompleteEvent event = new SQLQueryCompleteEvent(this.query.getSingle(e)); - //((Map) res).forEach((name, value) -> setVariable(event, name, value)); - //SkriptDB.getPlugin(SkriptDB.class).getServer().getPluginManager().callEvent(event); + //SQLQueryCompleteEvent event = new SQLQueryCompleteEvent(this.query.getSingle(e)); + //((Map) res).forEach((name, value) -> setVariable(event, name, value)); + //SkriptDB.getPlugin(SkriptDB.class).getServer().getPluginManager().callEvent(event); + } + if (isSync || finalSync) { + if (locals != null) { + Variables.setLocalVariables(e, locals); } - if (isSync || finalSync) { + if (!(res instanceof String)) { + ((Map) res).forEach((name, value) -> setVariable(e, name, value)); + } + TriggerItem.walk(getNext(), e); + Variables.removeLocals(e); + } else { + Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> { if (locals != null) { Variables.setLocalVariables(e, locals); } @@ -127,22 +137,12 @@ public class EffExecuteStatement extends Effect { ((Map) res).forEach((name, value) -> setVariable(e, name, value)); } TriggerItem.walk(getNext(), e); + //the line below is required to prevent memory leaks + //no functionality difference notice with it being removed from my test, but the memory gets filled with leaks + //so it must be kept Variables.removeLocals(e); - } else { - Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> { - if (locals != null) { - Variables.setLocalVariables(e, locals); - } - if (!(res instanceof String)) { - ((Map) res).forEach((name, value) -> setVariable(e, name, value)); - } - TriggerItem.walk(getNext(), e); - //the line below is required to prevent memory leaks - //no functionality difference notice with it being removed from my test, but the memory gets filled with leaks - //so it must be kept - Variables.removeLocals(e); - }); - } + }); + } } }); } @@ -176,7 +176,11 @@ public class EffExecuteStatement extends Effect { if (o instanceof String) { sb.append(o); } else { - Expression expr = SkriptUtil.getExpressionFromInfo(o); + Expression expr; + if (o instanceof Expression) + expr = (Expression) o; + else + expr = SkriptUtil.getExpressionFromInfo(o); String before = getString(objects, i - 1); String after = getString(objects, i + 1); @@ -330,4 +334,4 @@ public class EffExecuteStatement extends Effect { } return true; } -} +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0891bfa..6b502e1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,5 +2,5 @@ name: skript-db version: 1.3.2 main: com.btk5h.skriptdb.SkriptDB depend: [Skript] -authors: [btk5h, FranKusmiruk, Govindas] +authors: [btk5h, FranKusmiruk, Govindas, TPGamesNL] api-version: 1.13