forked from Limework/skript-db
		
	make sql auto sync if not main thread
This commit is contained in:
		
							parent
							
								
									9e7c5fcbee
								
							
						
					
					
						commit
						0c16b98553
					
				
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@ -6,7 +6,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <groupId>com.btk5h</groupId>
 | 
					    <groupId>com.btk5h</groupId>
 | 
				
			||||||
    <artifactId>skript-db</artifactId>
 | 
					    <artifactId>skript-db</artifactId>
 | 
				
			||||||
    <version>1.3.0</version>
 | 
					    <version>1.3.1</version>
 | 
				
			||||||
    <packaging>jar</packaging>
 | 
					    <packaging>jar</packaging>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <repositories>
 | 
					    <repositories>
 | 
				
			||||||
 | 
				
			|||||||
@ -80,11 +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 (!Bukkit.isPrimaryThread()) {
 | 
				
			||||||
 | 
					        sync = true;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      Object locals = Variables.removeLocals(e);
 | 
					      Object locals = Variables.removeLocals(e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      //execute SQL statement
 | 
					      //execute SQL statement
 | 
				
			||||||
@ -92,11 +93,10 @@ 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;
 | 
				
			||||||
 | 
					    sql.whenComplete((res, err) -> {
 | 
				
			||||||
        if (err != null) { 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;
 | 
				
			||||||
          if (res instanceof String) {
 | 
					          if (res instanceof String) {
 | 
				
			||||||
@ -117,7 +117,7 @@ public class EffExecuteStatement extends Effect {
 | 
				
			|||||||
              ((Map<String, Object>) res).forEach((name, value) -> setVariable(event, name, value));
 | 
					              ((Map<String, Object>) res).forEach((name, value) -> setVariable(event, name, value));
 | 
				
			||||||
              SkriptDB.getPlugin(SkriptDB.class).getServer().getPluginManager().callEvent(event);
 | 
					              SkriptDB.getPlugin(SkriptDB.class).getServer().getPluginManager().callEvent(event);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (isSync) {
 | 
					            if (isSync || finalSync) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              Variables.setLocalVariables(e, locals);
 | 
					              Variables.setLocalVariables(e, locals);
 | 
				
			||||||
              if (!(res instanceof String)) { ((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value)); }
 | 
					              if (!(res instanceof String)) { ((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value)); }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
name: skript-db
 | 
					name: skript-db
 | 
				
			||||||
version: 1.3.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]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user