diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..53f6302
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..f44ba7b
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..67e1e61
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..a13f1da
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..d105a01
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+
+ de.slpnetwork
+ spl
+ 1.0-SNAPSHOT
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.20.4-R0.1-SNAPSHOT
+ provided
+
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.33
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/de/slpnetwork/SPL.java b/src/main/java/de/slpnetwork/SPL.java
new file mode 100644
index 0000000..08abd64
--- /dev/null
+++ b/src/main/java/de/slpnetwork/SPL.java
@@ -0,0 +1,17 @@
+package de.slpnetwork;
+
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class SPL {
+ private static JavaPlugin plugin;
+
+ // For other classes in our library
+ public static JavaPlugin getPlugin() {
+ return SPL.plugin;
+ }
+
+ // This method must not be used any where in the library!
+ public static void setPlugin(final JavaPlugin plugin) {
+ SPL.plugin = plugin;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/slpnetwork/database/MySQL.java b/src/main/java/de/slpnetwork/database/MySQL.java
new file mode 100644
index 0000000..072bbee
--- /dev/null
+++ b/src/main/java/de/slpnetwork/database/MySQL.java
@@ -0,0 +1,433 @@
+package de.slpnetwork.database;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import de.slpnetwork.interfaces.IDataHandler;
+import de.slpnetwork.utils.ArrayHelper;
+
+import java.sql.*;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+
+// TODO: refactor all functions to throw end of function exception
+public class MySQL implements IDataHandler {
+
+ private Connection con;
+
+ /**
+ * handles all mysql database operations
+ * @param url the target url for the database
+ * @param username the username for the database
+ * @param password the password for the database
+ * @param database the name of the datbase (not yet required)
+ * @throws Exception if anything failes during connection attempt an exception throws
+ */
+ public MySQL(String url, String username, String password, String database) throws Exception{
+ try {
+ connect(url, username, password);
+ } catch(Exception ex) {
+ throw new Exception("could not connect to database due to error: " + ex.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * connects to the Database
+ * @param url target url to the database
+ * @param username username for the database
+ * @param password password for the database
+ */
+ private Connection connect(String url, String username, String password){
+ try {
+ con = DriverManager.getConnection(url, username, password);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ return null;
+ }
+
+ /**
+ * creates a table in the set database
+ * @param name the tables name
+ * @param fieldMap a map given with fieldnames and datatypes
+ * @throws SQLException
+ */
+ @Override
+ public void createTable(String name, Map fieldMap) {
+ String fields = "";
+
+ fields += "(";
+ for (Map.Entry entry : fieldMap.entrySet()) {
+ System.out.println(entry.getKey() + ":" + entry.getValue());
+ fields += entry.getKey() + " " + entry.getValue();
+ }
+ fields += ")";
+
+ try {
+ this.con.createStatement().executeQuery("CREATE TABLE IF NOT EXISTS " + name + " " + fields);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * this only returns a single given fields value for return of rows use getResults
+ * @param stmt the statement used to query the database
+ * @param target used to specify which field is required
+ * @return if found values from the database of type int
+ */
+ @Override
+ public int getInt(String stmt, String target) {
+ try {
+ int returning = 0;
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ returning = res.getInt(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * this only returns a single given fields value for return of rows use getResults
+ * @param stmt the statement used to query the database
+ * @param target used to specify which field is required
+ * @return if found values from the database of type int
+ */
+ @Override
+ public int[] getInts(String stmt, String target) {
+ try {
+ int[] returning = {};
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ ArrayHelper.push(returning, res.getInt(target));
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * @param stmt the statement used to query the database
+ * @param target not used
+ * @return if found values from the database of type int
+ */
+ @Override
+ public double getDouble(String stmt, @Nullable String target) {
+ try {
+ double returning = 0;
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ returning = res.getDouble(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+ @Override
+ public double[] getDoubles(String stmt, String target) {
+ try {
+ double[] returning = {};
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ ArrayHelper.push(returning, res.getDouble(target));
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * @param stmt the statement used to query the database
+ * @param target states what field is wanted
+ * @return if found values from the database of type string
+ */
+ @Override
+ public String getString(String stmt, String target) {
+ try {
+ String returning = "";
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ returning = res.getString(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return "";
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * @param stmt the statement used to query the database
+ * @param target not used
+ * @return if found values from the database of type string as array
+ */
+ @Override
+ public String[] getStrings(String stmt, String target) {
+ try {
+ String[] returning = {};
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ ArrayHelper.push(returning, res.getString(target));
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * @param stmt the statement used to query the database
+ * @param target not used
+ * @return if found values from the database of type boolean
+ */
+ @Override
+ public boolean getBool(String stmt, String target) {
+ try {
+ boolean returning = false;
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ if(this.countResult(res) <= 0) {
+ throw new Exception("error in MySQL class: received empty resultset");
+ }
+
+ while (res.next()) {
+ returning = res.getBoolean(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return false;
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * @param stmt the statement used to query the database
+ * @param target not used
+ * @return if found values from the database of type boolean as array
+ */
+ @Override
+ public boolean[] getBools(String stmt, String target) {
+ boolean[] result = {};
+
+ try {
+ ResultSet rs = this.con.createStatement().executeQuery(stmt);
+ while (rs.next()) {
+ result = ArrayHelper.push(result,rs.getBoolean(target));
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ /**
+ * executes a query and returns the unproccessed resultset
+ * @param stmt the query given as a string
+ * @return a resultset to continue proccessing with
+ */
+ @Override
+ public ResultSet getResults(String stmt) throws Exception {
+ try {
+ return this.con.createStatement().executeQuery(stmt);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ throw new Exception("reached end of function.. this should never happen");
+ }
+
+
+ @Override
+ public JsonObject getResultAsJSON(String stmt) throws Exception {
+ try {
+ ResultSet rs = this.con.createStatement().executeQuery(stmt);
+ JsonObject jsonObject = new JsonObject();
+
+ while (rs.next()) {
+ int totalColumns = rs.getMetaData().getColumnCount();
+
+ for (int i = 1; i <= totalColumns; i++) {
+ jsonObject.add(rs.getMetaData().getColumnLabel(i), (JsonElement) rs.getObject(i));
+ }
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ throw new Exception("reached end of function.. this should never happen");
+ }
+
+
+ @Override
+ public JsonObject[] getResultsAsJSON(String stmt) throws Exception {
+ try {
+ ResultSet rs = this.con.createStatement().executeQuery(stmt);
+ JsonObject[] jsonArray = new JsonObject[0];
+
+ while (rs.next()) {
+ JsonObject jsonObject = new JsonObject();
+ int totalColumns = rs.getMetaData().getColumnCount();
+
+ for (int i = 1; i <= totalColumns; i++) {
+ jsonObject.add(rs.getMetaData().getColumnLabel(i), (JsonElement) rs.getObject(i));
+ }
+
+ ArrayHelper.push(jsonArray, jsonObject);
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ throw new Exception("reached end of function.. this should never happen");
+ }
+
+
+ @Override
+ public Map getResultsAsMap(String a1) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Unimplemented method 'getResultsAsMap'");
+ }
+
+ @Override
+ public boolean writeData(String tableName, Map values) throws Exception {
+ if (values.isEmpty()) {
+ System.err.println("Data map is empty. No columns to insert values into.");
+ return false;
+ }
+
+ if (tableName == "" ) {
+ throw new Exception("found empty tableName");
+ }
+
+ StringBuilder labels = new StringBuilder();
+ StringBuilder placeholders = new StringBuilder();
+
+ Iterator> iterator = values.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = iterator.next();
+ labels.append(entry.getKey());
+ placeholders.append("?");
+
+ if (iterator.hasNext()) {
+ labels.append(",");
+ placeholders.append(",");
+ }
+ }
+
+ String sql = "INSERT INTO " + tableName + " (" + labels + ") VALUES (" + placeholders + ")";
+
+ try (PreparedStatement statement = this.con.prepareStatement(sql)) {
+ int index = 1;
+ for (Byte[] value : values.values()) {
+ statement.setObject(index++, value);
+ }
+
+ int rowsInserted = statement.executeUpdate();
+ return rowsInserted > 0;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ @Override
+ public boolean writeData(String tableName, String condition, Map values) throws Exception {
+ if (values.isEmpty()) {
+ System.err.println("Data map is empty. No columns to insert values into.");
+ return false;
+ }
+
+ if (tableName == "" ) {
+ throw new Exception("found empty tableName");
+ }
+
+ if (condition == "" ) {
+ throw new Exception("found empty condition");
+ }
+
+ StringBuilder labels = new StringBuilder();
+ StringBuilder placeholders = new StringBuilder();
+
+ Iterator> iterator = values.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = iterator.next();
+ labels.append(entry.getKey());
+ placeholders.append("?");
+
+ if (iterator.hasNext()) {
+ labels.append(",");
+ placeholders.append(",");
+ }
+ }
+
+ String sql = "INSERT INTO " + tableName + " (" + labels + ") VALUES (" + placeholders + ") " + condition;
+
+ try (PreparedStatement statement = this.con.prepareStatement(sql)) {
+ int index = 1;
+ for (Byte[] value : values.values()) {
+ statement.setObject(index++, value);
+ }
+
+ int rowsInserted = statement.executeUpdate();
+ return rowsInserted > 0;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * counts elements of a given resultset
+ * @param resultSet the requested resultset to count
+ * @return the counted size of a resultset
+ * @throws SQLException
+ */
+ private int countResult(ResultSet resultSet) throws SQLException {
+ int size = 0;
+
+ while(resultSet.next()) {
+ size++;
+ }
+
+ return size;
+ }
+}
diff --git a/src/main/java/de/slpnetwork/database/SQLite.java b/src/main/java/de/slpnetwork/database/SQLite.java
new file mode 100644
index 0000000..6cb9401
--- /dev/null
+++ b/src/main/java/de/slpnetwork/database/SQLite.java
@@ -0,0 +1,391 @@
+package de.slpnetwork.database;
+
+import java.sql.*;
+import java.util.Iterator;
+import java.util.Map;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import de.slpnetwork.MCPassiveMode;
+import de.slpnetwork.interfaces.IDataHandler;
+import de.slpnetwork.utils.ArrayHelper;
+
+import javax.annotation.Nullable;
+
+public class SQLite implements IDataHandler {
+
+ private Connection con;
+ private MCPassiveMode plugin;
+
+ public SQLite(MCPassiveMode plugin, String path) throws Exception {
+
+ this.plugin = plugin;
+
+ // setup connection
+ try {
+ this.con = connect(path);
+ } catch (Exception ex) {
+ throw new Exception("SQLite initailzatio failed due to exception" + ex.getLocalizedMessage(), ex.getCause());
+ }
+ }
+
+ private Connection connect(String path) throws Exception {
+ try {
+ return DriverManager.getConnection("jdbc:sqlite:" + path);
+ } catch (Exception ex) {
+ throw new Exception("SQLite connection failed due to exception" + ex.getLocalizedMessage(), ex.getCause());
+ }
+ }
+
+ /**
+ * creates a table in the set database
+ *
+ * @param name the tables name
+ * @throws SQLException
+ */
+ @Override
+ public void createTable(String name, Map fieldMap) {
+ String fields = "";
+
+ fields += "(";
+ for (Map.Entry entry : fieldMap.entrySet()) {
+ System.out.println(entry.getKey() + ":" + entry.getValue());
+ fields += entry.getKey() + " " + entry.getValue();
+ }
+ fields += ")";
+
+ try {
+ this.con.createStatement().executeQuery("CREATE TABLE IF NOT EXISTS " + name + " " + fields);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * executes a given query and returns a result of type int
+ *
+ * @param stmt the query to execute
+ * @param target secondary argument used to define the required field
+ * @return the found result of type int
+ */
+ @Override
+ public int getInt(String stmt, String target) {
+ try {
+ int returning = 0;
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ returning = res.getInt(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+ @Override
+ public int[] getInts(String stmt, String target) {
+ try {
+ int[] returning = {};
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ ArrayHelper.push(returning, res.getInt(target));
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public double getDouble(String stmt, @Nullable String target) {
+ try {
+ double returning = 0;
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ returning = res.getDouble(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+ @Override
+ public double[] getDoubles(String stmt, String target) {
+ try {
+ double[] returning = {};
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ ArrayHelper.push(returning, res.getDouble(target));
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public String getString(String stmt, String target) {
+ try {
+ String returning = "";
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ returning = res.getString(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return "";
+ }
+
+ @Override
+ public String[] getStrings(String stmt, String target) {
+ try {
+ String[] returning = {};
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ ArrayHelper.push(returning, res.getString(target));
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * @param stmt the statement used to query the database
+ * @param target not used
+ * @return if found values from the database of type boolean
+ */
+ @Override
+ public boolean getBool(String stmt, String target) {
+ try {
+ boolean returning = false;
+ ResultSet res = this.con.createStatement().executeQuery(stmt);
+
+ while (res.next()) {
+ returning = res.getBoolean(target);
+ }
+
+ return returning;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * execute a given statement on a mysql database
+ * @param stmt the statement used to query the database
+ * @param target not used
+ * @return if found values from the database of type boolean as array
+ */
+ @Override
+ public boolean[] getBools(String stmt, String target) {
+ boolean[] result = {};
+
+ try {
+ ResultSet rs = this.con.createStatement().executeQuery(stmt);
+ while (rs.next()) {
+ result = ArrayHelper.push(result,rs.getBoolean(target));
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ /**
+ * executes a query and returns the unproccessed resultset
+ * @param stmt the query given as a string
+ * @return a resultset to continue proccessing with
+ */
+ @Override
+ public ResultSet getResults(String stmt) throws Exception {
+ try {
+ return this.con.createStatement().executeQuery(stmt);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ throw new Exception("reached end of function.. this should never happen");
+ }
+
+
+ @Override
+ public JsonObject getResultAsJSON(String stmt) throws Exception {
+ try {
+ ResultSet rs = this.con.createStatement().executeQuery(stmt);
+ JsonObject jsonObject = new JsonObject();
+
+ while (rs.next()) {
+ int totalColumns = rs.getMetaData().getColumnCount();
+
+ for (int i = 1; i <= totalColumns; i++) {
+ jsonObject.add(rs.getMetaData().getColumnLabel(i), (JsonElement) rs.getObject(i));
+ }
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ throw new Exception("reached end of function.. this should never happen");
+ }
+
+
+ @Override
+ public JsonObject[] getResultsAsJSON(String stmt) throws Exception {
+ try {
+ ResultSet rs = this.con.createStatement().executeQuery(stmt);
+ JsonObject[] jsonArray = new JsonObject[0];
+
+ while (rs.next()) {
+ JsonObject jsonObject = new JsonObject();
+ int totalColumns = rs.getMetaData().getColumnCount();
+
+ for (int i = 1; i <= totalColumns; i++) {
+ jsonObject.add(rs.getMetaData().getColumnLabel(i), (JsonElement) rs.getObject(i));
+ }
+
+ ArrayHelper.push(jsonArray, jsonObject);
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ throw new Exception("reached end of function.. this should never happen");
+ }
+
+
+ @Override
+ public Map getResultsAsMap(String a1) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Unimplemented method 'getResultsAsMap'");
+ }
+
+ @Override
+ public boolean writeData(String tableName, Map values) throws Exception {
+ if (values.isEmpty()) {
+ System.err.println("Data map is empty. No columns to insert values into.");
+ return false;
+ }
+
+ if (tableName == "" ) {
+ throw new Exception("found empty tableName");
+ }
+
+ StringBuilder labels = new StringBuilder();
+ StringBuilder placeholders = new StringBuilder();
+
+ Iterator> iterator = values.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = iterator.next();
+ labels.append(entry.getKey());
+ placeholders.append("?");
+
+ if (iterator.hasNext()) {
+ labels.append(",");
+ placeholders.append(",");
+ }
+ }
+
+ String sql = "INSERT INTO " + tableName + " (" + labels + ") VALUES (" + placeholders + ")";
+
+ try (PreparedStatement statement = this.con.prepareStatement(sql)) {
+ int index = 1;
+ for (Byte[] value : values.values()) {
+ statement.setObject(index++, value);
+ }
+
+ int rowsInserted = statement.executeUpdate();
+ return rowsInserted > 0;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ @Override
+ public boolean writeData(String tableName, String condition, Map values) throws Exception {
+ if (values.isEmpty()) {
+ System.err.println("Data map is empty. No columns to insert values into.");
+ return false;
+ }
+
+ if (tableName == "" ) {
+ throw new Exception("found empty tableName");
+ }
+
+ if (condition == "" ) {
+ throw new Exception("found empty condition");
+ }
+
+ StringBuilder labels = new StringBuilder();
+ StringBuilder placeholders = new StringBuilder();
+
+ Iterator> iterator = values.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = iterator.next();
+ labels.append(entry.getKey());
+ placeholders.append("?");
+
+ if (iterator.hasNext()) {
+ labels.append(",");
+ placeholders.append(",");
+ }
+ }
+
+ String sql = "INSERT INTO " + tableName + " (" + labels + ") VALUES (" + placeholders + ") " + condition;
+
+ try (PreparedStatement statement = this.con.prepareStatement(sql)) {
+ int index = 1;
+ for (Byte[] value : values.values()) {
+ statement.setObject(index++, value);
+ }
+
+ int rowsInserted = statement.executeUpdate();
+ return rowsInserted > 0;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * counts elements of a given resultset
+ * @param resultSet the requested resultset to count
+ * @return the counted size of a resultset
+ * @throws SQLException
+ */
+ private int countResult(ResultSet resultSet) throws SQLException {
+ int size = 0;
+
+ while(resultSet.next()) {
+ size++;
+ }
+
+ return size;
+ }
+}
diff --git a/src/main/java/de/slpnetwork/interfaces/IDataHandler.java b/src/main/java/de/slpnetwork/interfaces/IDataHandler.java
new file mode 100644
index 0000000..580b83f
--- /dev/null
+++ b/src/main/java/de/slpnetwork/interfaces/IDataHandler.java
@@ -0,0 +1,86 @@
+package de.slpnetwork.interfaces;
+
+import java.sql.ResultSet;
+import java.util.Map;
+
+import com.google.gson.JsonObject;
+import netscape.javascript.JSObject;
+
+public interface IDataHandler {
+ void createTable(String name, Map fieldMap);
+
+ /**
+ * get integers values from a datasource
+ * @param a1 first argument usually used as target value
+ * @param a2 second argument usually used as value or extra file
+ * @return value of type int
+ */
+ public int getInt(String a1, String a2);
+ public int[] getInts(String a1, String a2);
+
+ /**
+ * get floats values from a datasource
+ * @param a1 first argument usually used as target value
+ * @param a2 second argument usually used as value or extra file
+ * @return value of type float
+ */
+ public double getDouble(String a1, String a2);
+ public double[] getDoubles(String a1, String a2);
+
+ /**
+ * get strings values from a datasource
+ * @param a1 first argument usually used as target value
+ * @param a2 second argument usually used as value or extra file
+ * @return value of type String
+ */
+ public String getString(String a1, String a2);
+ public String[] getStrings(String a1, String a2);
+
+ /**
+ * get boolean values from a datasource
+ * @param a1 first argument usually used as target value
+ * @param a2 second argument usually used as value or extra file
+ * @return value of type int
+ */
+ public boolean getBool(String a1, String a2);
+ public boolean[] getBools(String a1, String a2);
+
+ /**
+ * executes a query and returns the unproccessed resultset
+ * @param a1 the query given as a string
+ * @return a resultset to continue proccessing with
+ */
+ public ResultSet getResults(String a1) throws Exception;
+
+ /**
+ * executes given query and returns result as json object
+ * @param a1 the query to execute
+ * @return the result as JSONObject
+ */
+ public JsonObject getResultAsJSON(String a1) throws Exception;
+ public JsonObject[] getResultsAsJSON(String a1) throws Exception;
+
+ /**
+ * executes a query and returns untyped results as map
+ * @param a1 the query given as a string
+ * @return a resultset to continue proccessing with
+ */
+ public Map getResultsAsMap(String a1);
+
+ /**
+ * write values to a set datasource
+ * @param a1 first argument usually used as location or statement
+ * @param a3 third argument usually used as value or extra file
+ * @return if the write operation was successful
+ */
+ public boolean writeData(String a1, Map a3) throws Exception;
+
+ /**
+ * write values to a set datasource
+ * @param a1 first argument location
+ * @param a2 second argument condition
+ * @param a3 third argument usually used as value or extra file
+ * @return if the write operation was successful
+ */
+ public boolean writeData(String a1, String a2, Map a3) throws Exception;
+}
diff --git a/src/main/java/de/slpnetwork/interfaces/ILogger.java b/src/main/java/de/slpnetwork/interfaces/ILogger.java
new file mode 100644
index 0000000..1e857dd
--- /dev/null
+++ b/src/main/java/de/slpnetwork/interfaces/ILogger.java
@@ -0,0 +1,9 @@
+package de.slpnetwork.interfaces;
+
+public interface ILogger {
+ void Info(String Message, String Prefix);
+ void Debug(String Message, String Prefix);
+ void Warning(String Message, String Prefix);
+ void Error(String Message, String Prefix);
+ void Critical(String Message, String Prefix);
+}
diff --git a/src/main/java/de/slpnetwork/utils/ArrayHelper.java b/src/main/java/de/slpnetwork/utils/ArrayHelper.java
new file mode 100644
index 0000000..9706aab
--- /dev/null
+++ b/src/main/java/de/slpnetwork/utils/ArrayHelper.java
@@ -0,0 +1,62 @@
+package de.slpnetwork.utils;
+
+import java.util.Arrays;
+
+import com.google.gson.JsonObject;
+
+public class ArrayHelper {
+ public static int[] push(int[] arr, int item) {
+ int[] tmp = Arrays.copyOf(arr, arr.length + 1);
+ tmp[tmp.length - 1] = item;
+ return tmp;
+ }
+
+ public static String[] push(String[] arr, String item) {
+ String[] tmp = Arrays.copyOf(arr, arr.length + 1);
+ tmp[tmp.length - 1] = item;
+ return tmp;
+ }
+
+ public static double[] push(double[] arr, double item) {
+ double[] tmp = Arrays.copyOf(arr, arr.length + 1);
+ tmp[tmp.length - 1] = item;
+ return tmp;
+ }
+
+ public static boolean[] push(boolean[] arr, boolean item) {
+ boolean[] tmp = Arrays.copyOf(arr, arr.length + 1);
+ tmp[tmp.length - 1] = item;
+ return tmp;
+ }
+
+ public static JsonObject[] push(JsonObject[] arr, JsonObject item) {
+ JsonObject[] tmp = Arrays.copyOf(arr, arr.length + 1);
+ tmp[tmp.length - 1] = item;
+ return tmp;
+ }
+
+ public static int[] pop(int[] arr) {
+ int[] tmp = Arrays.copyOf(arr, arr.length - 1);
+ return tmp;
+ }
+
+ public static String[] pop(String[] arr) {
+ String[] tmp = Arrays.copyOf(arr, arr.length - 1);
+ return tmp;
+ }
+
+ public static double[] pop(double[] arr) {
+ double[] tmp = Arrays.copyOf(arr, arr.length - 1);
+ return tmp;
+ }
+
+ public static boolean[] pop(boolean[] arr) {
+ boolean[] tmp = Arrays.copyOf(arr, arr.length - 1);
+ return tmp;
+ }
+
+ public static JsonObject[] pop(JsonObject[] arr) {
+ JsonObject[] tmp = Arrays.copyOf(arr, arr.length - 1);
+ return tmp;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/slpnetwork/utils/Log.java b/src/main/java/de/slpnetwork/utils/Log.java
new file mode 100644
index 0000000..9af443d
--- /dev/null
+++ b/src/main/java/de/slpnetwork/utils/Log.java
@@ -0,0 +1,37 @@
+package de.slpnetwork.utils;
+
+import de.slpnetwork.SPL;
+import de.slpnetwork.interfaces.ILogger;
+
+import java.util.logging.Level;
+
+/**
+ * gives a standard logging format
+ */
+public class Log implements ILogger {
+
+ @Override
+ public void Info(String Message, String Prefix) {
+ SPL.getPlugin().getLogger().log(Level.INFO, Prefix + ": " + Message);
+ }
+
+ @Override
+ public void Debug(String Message, String Prefix) {
+ SPL.getPlugin().getLogger().log(Level.INFO, Prefix + " [DEBUG] >> " + Message);
+ }
+
+ @Override
+ public void Warning(String Message, String Prefix) {
+ SPL.getPlugin().getLogger().log(Level.WARNING, Prefix + ": " + Message);
+ }
+
+ @Override
+ public void Error(String Message, String Prefix) {
+ SPL.getPlugin().getLogger().log(Level.SEVERE, Prefix + ": " + Message);
+ }
+
+ @Override
+ public void Critical(String Message, String Prefix) {
+ SPL.getPlugin().getLogger().log(Level.SEVERE, Prefix + " [CRITICAL] >> " + Message);
+ }
+}
diff --git a/steevs-plugin-lib.iml b/steevs-plugin-lib.iml
new file mode 100644
index 0000000..a589521
--- /dev/null
+++ b/steevs-plugin-lib.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ SPIGOT
+
+ 1
+
+
+
+
\ No newline at end of file