forked from Limework/skript-db
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e1e3ce14b | ||
|
|
aa65a4e7e8 | ||
|
|
d00fc2b6a0 | ||
|
|
a72da39839 | ||
|
|
d98bc34b38 | ||
|
|
ce64eda9e2 | ||
|
|
d9f95ac101 | ||
|
|
fbb35937e6 | ||
|
|
852e5e0477 | ||
|
|
7620da85f1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@
|
|||||||
*.iml
|
*.iml
|
||||||
out/
|
out/
|
||||||
target
|
target
|
||||||
|
compile/
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
### Difference from original skript-db
|
### Difference from original skript-db
|
||||||
- Fixed local variables disappearance in newer Skript versions (very hacky fix, but it works, so that's good!)
|
- Fixed local variables disappearance in newer Skript versions (very hacky fix, but it works, so that's good!)
|
||||||
- Thread-pool size is now configurable
|
- Thread-pool size is now automatically increasing on demand to use of CachedThreadPool, instead of a fixed hard-coded number
|
||||||
- Uses a newer version of HikariCP
|
- Uses a newer version of HikariCP
|
||||||
- Only meant to be used by newer Minecraft versions (1.8 is not supported)
|
- Only meant to be used by newer Minecraft versions (1.8 is not supported)
|
||||||
|
|
||||||
|
|||||||
26
pom.xml
26
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.btk5h</groupId>
|
<groupId>com.btk5h</groupId>
|
||||||
<artifactId>skript-db</artifactId>
|
<artifactId>skript-db</artifactId>
|
||||||
<version>1.2.1</version>
|
<version>1.3.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
@@ -45,11 +45,27 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.6.1</version>
|
<version>3.6.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>10</source>
|
<source>8</source>
|
||||||
<target>10</target>
|
<target>8</target>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.3</version>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
@@ -65,7 +81,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
<artifactId>HikariCP</artifactId>
|
<artifactId>HikariCP</artifactId>
|
||||||
<version>4.0.1</version>
|
<version>4.0.3</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -89,4 +105,4 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: com.btk5h.skriptdb.SkriptDB
|
Main-Class: com.btk5h.skriptdb.SkriptDB
|
||||||
|
|
||||||
@@ -73,13 +73,9 @@ public final class SkriptDB extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (out == null) return;
|
if (out == null) return;
|
||||||
|
|
||||||
out.write("# How many connections can be awaited for simultaneously, may be useful to increase if mysql database is hosted on a separate machine to account for ping.\n");
|
|
||||||
out.write("# If it is hosted within the same machine, set it to the count of cores your processor has or the count of threads your processor can process at once.\n");
|
|
||||||
out.write("thread-pool-size: " + (Runtime.getRuntime().availableProcessors() + 1) + "\n");
|
|
||||||
out.write("# Only change this if you wish to use a different driver than Java's default, like MariaDB driver.\n");
|
out.write("# Only change this if you wish to use a different driver than Java's default, like MariaDB driver.\n");
|
||||||
out.write("# If you use MariaDB, its driver is shaded together with skript-db, so you can just specify:" + "\"org.mariadb.jdbc.Driver\"" + ".\n");
|
out.write("# If you use MariaDB, its driver is shaded together with skript-db, so you can just specify:" + "\"org.mariadb.jdbc.Driver\"" + ".\n");
|
||||||
out.write("sql-driver-class-name:" + "\"default\"" + "\n");
|
out.write("sql-driver-class-name: " + "\"default\"" + "\n");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.btk5h.skriptdb.events;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class SQLQueryCompleteEvent extends Event {
|
||||||
|
private final static HandlerList HANDLERS = new HandlerList();
|
||||||
|
private String argument;
|
||||||
|
private Object variables;
|
||||||
|
|
||||||
|
public SQLQueryCompleteEvent(String argument) {
|
||||||
|
super(true);
|
||||||
|
this.argument = argument;
|
||||||
|
// this.variables = variables;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getEventName() {
|
||||||
|
return super.getEventName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArgument() {
|
||||||
|
return argument;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public String getVariables() {return;}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import ch.njol.util.Kleenean;
|
|||||||
import ch.njol.util.Pair;
|
import ch.njol.util.Pair;
|
||||||
import com.btk5h.skriptdb.SkriptDB;
|
import com.btk5h.skriptdb.SkriptDB;
|
||||||
import com.btk5h.skriptdb.SkriptUtil;
|
import com.btk5h.skriptdb.SkriptUtil;
|
||||||
|
import com.btk5h.skriptdb.events.SQLQueryCompleteEvent;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@@ -51,7 +52,7 @@ public class EffExecuteStatement extends Effect {
|
|||||||
static String lastError;
|
static String lastError;
|
||||||
|
|
||||||
private static final ExecutorService threadPool =
|
private static final ExecutorService threadPool =
|
||||||
Executors.newFixedThreadPool(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 2));
|
Executors.newCachedThreadPool();
|
||||||
|
|
||||||
private Expression<String> query;
|
private Expression<String> query;
|
||||||
private Expression<HikariDataSource> dataSource;
|
private Expression<HikariDataSource> dataSource;
|
||||||
@@ -79,14 +80,12 @@ public class EffExecuteStatement extends Effect {
|
|||||||
String baseVariable = var != null ? var.toString(e).toLowerCase(Locale.ENGLISH) : null;
|
String baseVariable = var != null ? var.toString(e).toLowerCase(Locale.ENGLISH) : null;
|
||||||
|
|
||||||
//if data source isn't set
|
//if data source isn't set
|
||||||
if (ds == null)
|
if (ds == null) return;
|
||||||
return;
|
|
||||||
|
|
||||||
|
boolean sync = false;
|
||||||
if (isSync) {
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
Object populatedVariables = executeStatement(ds, baseVariable, query);
|
sync = true;
|
||||||
continueScriptExecution(e, populatedVariables);
|
}
|
||||||
} else {
|
|
||||||
Object locals = Variables.removeLocals(e);
|
Object locals = Variables.removeLocals(e);
|
||||||
|
|
||||||
//execute SQL statement
|
//execute SQL statement
|
||||||
@@ -94,12 +93,9 @@ public class EffExecuteStatement extends Effect {
|
|||||||
CompletableFuture.supplyAsync(() -> executeStatement(ds, baseVariable, query), threadPool);
|
CompletableFuture.supplyAsync(() -> executeStatement(ds, baseVariable, query), threadPool);
|
||||||
|
|
||||||
//when SQL statement is completed
|
//when SQL statement is completed
|
||||||
sql.whenComplete((res, err) -> {
|
boolean finalSync = sync;
|
||||||
if (err != null) {
|
sql.whenComplete((res, err) -> {
|
||||||
err.printStackTrace();
|
if (err != null) { err.printStackTrace(); }
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> {
|
|
||||||
|
|
||||||
//handle last error syntax data
|
//handle last error syntax data
|
||||||
lastError = null;
|
lastError = null;
|
||||||
@@ -110,28 +106,42 @@ public class EffExecuteStatement extends Effect {
|
|||||||
if (getNext() != null) {
|
if (getNext() != null) {
|
||||||
//if local variables are present
|
//if local variables are present
|
||||||
if (locals != null)
|
if (locals != null)
|
||||||
|
|
||||||
//bring back local variables
|
//bring back local variables
|
||||||
Variables.setLocalVariables(e, locals);
|
|
||||||
|
|
||||||
//populate SQL data into variables
|
//populate SQL data into variables
|
||||||
if (!(res instanceof String)) {
|
if (!(res instanceof String)) {
|
||||||
((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value));
|
|
||||||
|
//also set variables in the sql query complete event
|
||||||
|
|
||||||
|
SQLQueryCompleteEvent event = new SQLQueryCompleteEvent("something");
|
||||||
|
((Map<String, Object>) res).forEach((name, value) -> setVariable(event, name, value));
|
||||||
|
SkriptDB.getPlugin(SkriptDB.class).getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
if (isSync || finalSync) {
|
||||||
|
|
||||||
|
Variables.setLocalVariables(e, locals);
|
||||||
|
if (!(res instanceof String)) { ((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value)); }
|
||||||
|
TriggerItem.walk(getNext(), e);
|
||||||
|
Variables.removeLocals(e);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> {
|
||||||
|
Variables.setLocalVariables(e, locals);
|
||||||
|
if (!(res instanceof String)) { ((Map<String, Object>) 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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TriggerItem walk(Event e) {
|
protected TriggerItem walk(Event e) {
|
||||||
debug(e, true);
|
debug(e, true);
|
||||||
|
//I think no longer needed as of 1.3.0, uncomment if something breaks
|
||||||
if (!isSync) {
|
if (!isSync) {
|
||||||
Delay.addDelayedEvent(e);
|
Delay.addDelayedEvent(e);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.btk5h.skriptdb.skript;
|
||||||
|
|
||||||
|
import ch.njol.skript.Skript;
|
||||||
|
import ch.njol.skript.lang.Literal;
|
||||||
|
import ch.njol.skript.lang.SkriptEvent;
|
||||||
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
|
import com.btk5h.skriptdb.events.SQLQueryCompleteEvent;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
|
public class EvtSQLQueryComplete extends SkriptEvent {
|
||||||
|
static {
|
||||||
|
Skript.registerEvent("complete of sql query", EvtSQLQueryComplete.class, SQLQueryCompleteEvent.class, "complete of [(sql|database)] query");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean init(final Literal<?>[] literals, final int i, final SkriptParser.ParseResult parseResult) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check(Event event) {
|
||||||
|
return (event instanceof SQLQueryCompleteEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(@Nullable Event event, boolean debug) {
|
||||||
|
return "complete of sql query";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ public class Types {
|
|||||||
static {
|
static {
|
||||||
Classes.registerClass(new ClassInfo<>(HikariDataSource.class, "datasource")
|
Classes.registerClass(new ClassInfo<>(HikariDataSource.class, "datasource")
|
||||||
.user("datasources?")
|
.user("datasources?")
|
||||||
.parser(new Parser<>() {
|
.parser(new Parser<HikariDataSource>() {
|
||||||
@Override
|
@Override
|
||||||
public HikariDataSource parse(String s, ParseContext context) {
|
public HikariDataSource parse(String s, ParseContext context) {
|
||||||
return null;
|
return null;
|
||||||
@@ -35,7 +35,7 @@ public class Types {
|
|||||||
return "jdbc:.+";
|
return "jdbc:.+";
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.serializer(new Serializer<>() {
|
.serializer(new Serializer<HikariDataSource>() {
|
||||||
@Override
|
@Override
|
||||||
public Fields serialize(HikariDataSource o) {
|
public Fields serialize(HikariDataSource o) {
|
||||||
Fields fields = new Fields();
|
Fields fields = new Fields();
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
name: skript-db
|
name: skript-db
|
||||||
version: 1.2.0
|
version: 1.3.1
|
||||||
main: com.btk5h.skriptdb.SkriptDB
|
main: com.btk5h.skriptdb.SkriptDB
|
||||||
depend: [Skript]
|
depend: [Skript]
|
||||||
authors: [btk5h, FranKusmiruk, Govindas]
|
authors: [btk5h, FranKusmiruk, Govindas]
|
||||||
|
api-version: 1.13
|
||||||
Reference in New Issue
Block a user