|
@@ -2,10 +2,12 @@ package me.km.snuviscript;
|
|
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
import java.io.File;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
import me.km.KajetansMod;
|
|
|
import me.km.utils.NBTUtils;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.GregorianCalendar;
|
|
|
import java.util.List;
|
|
@@ -69,10 +71,7 @@ import me.km.inventory.CustomContainer;
|
|
|
import me.km.items.tools.*;
|
|
|
import me.km.items.weapons.*;
|
|
|
import me.km.networking.ModPacketHandler;
|
|
|
-import me.km.playerbank.PlayerBank;
|
|
|
-import me.km.playerbank.PlayerManager;
|
|
|
import me.km.scoreboard.ScoreboardUtils;
|
|
|
-import me.km.utils.TableUtils;
|
|
|
import net.minecraft.block.BlockCrops;
|
|
|
import net.minecraft.entity.EntityList;
|
|
|
import net.minecraft.entity.effect.EntityLightningBolt;
|
|
@@ -308,6 +307,7 @@ public class MinecraftFunctions
|
|
|
return Void.TYPE;
|
|
|
});
|
|
|
parser.registerFunction("player.hasfly", (sc, in) -> ((EntityPlayer) in[0].get(sc)).capabilities.allowFlying);
|
|
|
+ parser.registerFunction("player.isflying", (sc, in) -> ((EntityPlayer) in[0].get(sc)).capabilities.isFlying);
|
|
|
parser.registerFunction("player.setgamemode", (sc, in) ->
|
|
|
{
|
|
|
EntityPlayer p = (EntityPlayer) in[0].get(sc);
|
|
@@ -1492,7 +1492,195 @@ public class MinecraftFunctions
|
|
|
}
|
|
|
return o;
|
|
|
});
|
|
|
+
|
|
|
+ // ---------------------------------------------------------------------
|
|
|
+ // databank library
|
|
|
+ // ---------------------------------------------------------------------
|
|
|
|
|
|
+ parser.registerFunction("databank.prepare", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ PreparedStatement p = KajetansMod.databank.prepareUnsafeStatement(in[0].getString(sc));
|
|
|
+ sc.addCloseable(p);
|
|
|
+ return p;
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.setint", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ((PreparedStatement) in[0].get(sc)).setInt(in[1].getInt(sc), in[2].getInt(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.setlong", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ((PreparedStatement) in[0].get(sc)).setLong(in[1].getInt(sc), in[2].getLong(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.setdouble", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ((PreparedStatement) in[0].get(sc)).setDouble(in[1].getInt(sc), in[2].getDouble(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.setstring", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ((PreparedStatement) in[0].get(sc)).setString(in[1].getInt(sc), in[2].getString(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.setbool", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ((PreparedStatement) in[0].get(sc)).setBoolean(in[1].getInt(sc), in[2].getBoolean(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.getint", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return (double) ((ResultSet) in[0].get(sc)).getInt(in[1].getInt(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.getlong", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return (double) ((ResultSet) in[0].get(sc)).getLong(in[1].getInt(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.getdouble", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return ((ResultSet) in[0].get(sc)).getDouble(in[1].getInt(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.getstring", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return ((ResultSet) in[0].get(sc)).getString(in[1].getInt(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.getbool", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return ((ResultSet) in[0].get(sc)).getBoolean(in[1].getInt(sc));
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.execute", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return ((PreparedStatement) in[0].get(sc)).executeQuery();
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.workerexecute", (sc, in) ->
|
|
|
+ {
|
|
|
+ final PreparedStatement p = (PreparedStatement) in[0].get(sc);
|
|
|
+ final String name = sc.getName();
|
|
|
+ KajetansMod.scheduler.getWorker().add(() ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ p.executeQuery();
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ KajetansMod.scheduler.scheduleTask(() ->
|
|
|
+ {
|
|
|
+ ChatChannel.getDevChannel().sendWarning("Worker error in script '" + name + "'");
|
|
|
+ ChatChannel.getDevChannel().sendWarning(ex.getLocalizedMessage());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.next", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return ((ResultSet) in[0].get(sc)).next();
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ parser.registerFunction("databank.close", (sc, in) ->
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ((ResultSet) in[0].get(sc)).close();
|
|
|
+ return Void.TYPE;
|
|
|
+ }
|
|
|
+ catch(SQLException ex)
|
|
|
+ {
|
|
|
+ throw new IllegalArgumentException(ex.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
// ---------------------------------------------------------------------
|
|
|
// Plot-library
|
|
|
// ---------------------------------------------------------------------
|