forked from Limework/skript-db
		
	Preparations for quicker queries (no 50ms delay) feature
This commit is contained in:
		
							parent
							
								
									8b3d26cf78
								
							
						
					
					
						commit
						9e7c5fcbee
					
				
							
								
								
									
										4
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								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.0</version>
 | 
				
			||||||
    <packaging>jar</packaging>
 | 
					    <packaging>jar</packaging>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <repositories>
 | 
					    <repositories>
 | 
				
			||||||
@ -65,7 +65,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.2</version>
 | 
				
			||||||
            <scope>compile</scope>
 | 
					            <scope>compile</scope>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
 | 
				
			|||||||
@ -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;
 | 
				
			||||||
@ -83,10 +84,7 @@ public class EffExecuteStatement extends Effect {
 | 
				
			|||||||
      return;
 | 
					      return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isSync) {
 | 
					
 | 
				
			||||||
      Object populatedVariables = executeStatement(ds, baseVariable, query);
 | 
					 | 
				
			||||||
      continueScriptExecution(e, populatedVariables);
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      Object locals = Variables.removeLocals(e);
 | 
					      Object locals = Variables.removeLocals(e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      //execute SQL statement
 | 
					      //execute SQL statement
 | 
				
			||||||
@ -95,11 +93,9 @@ public class EffExecuteStatement extends Effect {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      //when SQL statement is completed
 | 
					      //when SQL statement is completed
 | 
				
			||||||
      sql.whenComplete((res, err) -> {
 | 
					      sql.whenComplete((res, err) -> {
 | 
				
			||||||
        if (err != null) {
 | 
					        if (err != null) { err.printStackTrace(); }
 | 
				
			||||||
          err.printStackTrace();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> {
 | 
					       // 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) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              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);
 | 
					                      TriggerItem.walk(getNext(), e);
 | 
				
			||||||
                      //the line below is required to prevent memory leaks
 | 
					                      //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
 | 
					                      //no functionality difference notice with it being removed from my test, but the memory gets filled with leaks
 | 
				
			||||||
                      //so it must be kept
 | 
					                      //so it must be kept
 | 
				
			||||||
                      Variables.removeLocals(e);
 | 
					                      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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										29
									
								
								src/java/com/btk5h/skriptdb/skript/EvtSQLQueryComplete.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/java/com/btk5h/skriptdb/skript/EvtSQLQueryComplete.java
									
									
									
									
									
										Normal file
									
								
							@ -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";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
name: skript-db
 | 
					name: skript-db
 | 
				
			||||||
version: 1.2.0
 | 
					version: 1.3.0
 | 
				
			||||||
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