diff --git a/pom.xml b/pom.xml
index 7c70711..3ba4158 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,7 +90,6 @@
1.18.10
provided
-
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java
index d2e3541..d03aca8 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java
@@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter;
import lombok.Setter;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
@@ -31,4 +32,33 @@ public class Floor {
}
return getY() == other.getY();
}
+
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ String newLine = System.getProperty("line.separator");
+
+ result.append(this.getClass().getName());
+ result.append(" Object {");
+ result.append(newLine);
+
+ //determine fields declared in this class only (no fields of superclass)
+ Field[] fields = this.getClass().getDeclaredFields();
+
+ //print field names paired with their values
+ for (Field field: fields) {
+ result.append(" ");
+ try {
+ result.append(field.getName());
+ result.append(": ");
+ //requires access to private field:
+ result.append(field.get(this));
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ result.append(newLine);
+ }
+ result.append("}");
+
+ return result.toString();
+ }
}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java
index 48680ff..4b1b02f 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java
@@ -4,13 +4,14 @@ import lombok.Getter;
import lombok.Setter;
import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser;
+import java.lang.reflect.Field;
import java.util.*;
public class Lift {
@Getter @Setter private String worldName;
@Getter @Setter private int y;
@Getter private final HashSet owners;
- @Getter @Setter private ArrayList whitelist;
+ //@Getter @Setter private ArrayList whitelist;
@Getter private final TreeSet blocks = new TreeSet<>();
@Getter private final LinkedHashMap floors = new LinkedHashMap<>();
@Getter private final HashSet signs = new HashSet<>();
@@ -42,4 +43,33 @@ public class Lift {
this.speed = speed;
this.realistic = realistic;
}
+
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ String newLine = System.getProperty("line.separator");
+
+ result.append(this.getClass().getName());
+ result.append(" Object {");
+ result.append(newLine);
+
+ //determine fields declared in this class only (no fields of superclass)
+ Field[] fields = this.getClass().getDeclaredFields();
+
+ //print field names paired with their values
+ for (Field field: fields) {
+ result.append(" ");
+ try {
+ result.append(field.getName());
+ result.append(": ");
+ //requires access to private field:
+ result.append(field.get(this));
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ result.append(newLine);
+ }
+ result.append("}");
+
+ return result.toString();
+ }
}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java
index 423e661..957af9e 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java
@@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import javax.annotation.Nonnull;
+import java.lang.reflect.Field;
import java.util.Map;
public class LiftBlock implements Comparable {
@@ -107,4 +108,33 @@ public class LiftBlock implements Comparable {
LiftBlock other = (LiftBlock) obj;
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
}
+
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ String newLine = System.getProperty("line.separator");
+
+ result.append(this.getClass().getName());
+ result.append(" Object {");
+ result.append(newLine);
+
+ //determine fields declared in this class only (no fields of superclass)
+ Field[] fields = this.getClass().getDeclaredFields();
+
+ //print field names paired with their values
+ for (Field field: fields) {
+ result.append(" ");
+ try {
+ result.append(field.getName());
+ result.append(": ");
+ //requires access to private field:
+ result.append(field.get(this));
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ result.append(newLine);
+ }
+ result.append("}");
+
+ return result.toString();
+ }
}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java
index 007f5a9..0b334bd 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java
@@ -4,6 +4,8 @@ import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
+import java.lang.reflect.Field;
+
@Getter @Setter
public class LiftRope {
private final Material type;
@@ -35,4 +37,33 @@ public class LiftRope {
&& getMaxY() == other.getMaxY()
&& getZ() == other.getZ();
}
+
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ String newLine = System.getProperty("line.separator");
+
+ result.append(this.getClass().getName());
+ result.append(" Object {");
+ result.append(newLine);
+
+ //determine fields declared in this class only (no fields of superclass)
+ Field[] fields = this.getClass().getDeclaredFields();
+
+ //print field names paired with their values
+ for (Field field: fields) {
+ result.append(" ");
+ try {
+ result.append(field.getName());
+ result.append(": ");
+ //requires access to private field:
+ result.append(field.get(this));
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ result.append(newLine);
+ }
+ result.append("}");
+
+ return result.toString();
+ }
}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java
index 78feeb4..d684271 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java
@@ -2,8 +2,8 @@ package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter;
import lombok.Setter;
-import org.bukkit.Rotation;
-import org.bukkit.block.BlockFace;
+
+import java.lang.reflect.Field;
@Getter @Setter
public class LiftSign {
@@ -34,4 +34,33 @@ public class LiftSign {
LiftSign other = (LiftSign) obj;
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
}
+
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ String newLine = System.getProperty("line.separator");
+
+ result.append(this.getClass().getName());
+ result.append(" Object {");
+ result.append(newLine);
+
+ //determine fields declared in this class only (no fields of superclass)
+ Field[] fields = this.getClass().getDeclaredFields();
+
+ //print field names paired with their values
+ for (Field field: fields) {
+ result.append(" ");
+ try {
+ result.append(field.getName());
+ result.append(": ");
+ //requires access to private field:
+ result.append(field.get(this));
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ result.append(newLine);
+ }
+ result.append("}");
+
+ return result.toString();
+ }
}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java
index 31ee625..969300c 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java
@@ -5,6 +5,7 @@ import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
+import java.lang.reflect.Field;
import java.util.UUID;
@Getter
@@ -56,4 +57,33 @@ public class V10Entity {
if (getEntity() == null || getEntity().isDead()) return false;
return uuid == getEntity().getUniqueId();
}
+
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ String newLine = System.getProperty("line.separator");
+
+ result.append(this.getClass().getName());
+ result.append(" Object {");
+ result.append(newLine);
+
+ //determine fields declared in this class only (no fields of superclass)
+ Field[] fields = this.getClass().getDeclaredFields();
+
+ //print field names paired with their values
+ for (Field field: fields) {
+ result.append(" ");
+ try {
+ result.append(field.getName());
+ result.append(": ");
+ //requires access to private field:
+ result.append(field.get(this));
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ result.append(newLine);
+ }
+ result.append("}");
+
+ return result.toString();
+ }
}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DBManager.java b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DBManager.java
new file mode 100644
index 0000000..aff505b
--- /dev/null
+++ b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DBManager.java
@@ -0,0 +1,48 @@
+package nl.SBDeveloper.V10Lift.Managers;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import nl.SBDeveloper.V10Lift.API.Objects.Lift;
+import nl.SBDeveloper.V10Lift.Utils.SBSQLiteDB;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.*;
+
+public class DBManager {
+
+ private static SBSQLiteDB data;
+
+ public DBManager(JavaPlugin plugin, String name) {
+ data = new SBSQLiteDB(plugin, name);
+
+ data.execute("CREATE TABLE IF NOT EXISTS lifts (liftName varchar(255) NOT NULL, liftData blob NOT NULL, UNIQUE (liftName))");
+ }
+
+ public void load() throws SQLException {
+ ResultSet liftSet = data.execute("SELECT * FROM lifts", new HashMap<>());
+ while (liftSet.next()) {
+ //Loading a lift...
+ byte[] blob = liftSet.getBytes("liftData");
+ String json = new String(blob);
+ Gson gson = new Gson();
+ Lift lift = gson.fromJson(json, new TypeToken(){}.getType());
+ DataManager.addLift(liftSet.getString("liftName"), lift);
+ }
+ }
+
+ public void save() {
+ HashMap inserts = new HashMap<>();
+ Gson gson = new Gson();
+ for (Map.Entry entry : DataManager.getLifts().entrySet()) {
+ inserts.put(entry.getKey(), gson.toJson(entry.getValue()).getBytes());
+ }
+ //TODO Insert
+ }
+
+ public void closeConnection() {
+ data.closeSource();
+ }
+
+}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java b/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java
index 1aa26cb..5eb4ce9 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java
@@ -96,7 +96,7 @@ public class SBSQLiteDB {
try {
con = this.source.getConnection();
statement = con.prepareStatement(query);
- if (objects != null) {
+ if (objects != null && !objects.isEmpty()) {
for (Map.Entry entry : objects.entrySet()) {
statement.setObject(entry.getKey(), entry.getValue());
}
@@ -122,11 +122,10 @@ public class SBSQLiteDB {
*
* @param query The query you want to execute
* @param objects The objects you want to insert, in the right order
- * @param requests The objects you want to select from the database
*
* @return HashMap