diff --git a/pom.xml b/pom.xml
index d00f140..480c833 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,6 +60,10 @@
spigot-repo
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+ iobyte-repo
+ https://nexus.iobyte.nl/repository/maven-public/
+
@@ -90,6 +94,12 @@
1.18.10
provided
+
+ nl.SBDevelopment
+ SBUtilities
+ 1.0
+ SBUtilities
+
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java
index 9c63b2a..5a51c4b 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java
@@ -3,10 +3,10 @@ package nl.SBDeveloper.V10Lift.API.Runnables;
import nl.SBDeveloper.V10Lift.API.Objects.*;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
-import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.Utils.XSound;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
+import nl.SBDevelopment.SBUtilities.Utils.LocationSerializer;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java
index c42b4cd..3d161fc 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java
@@ -8,9 +8,9 @@ import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
-import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
+import nl.SBDevelopment.SBUtilities.Utils.LocationSerializer;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java
index a154bb2..7334b2b 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java
@@ -6,9 +6,9 @@ import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
-import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
+import nl.SBDevelopment.SBUtilities.Utils.LocationSerializer;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DBManager.java b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DBManager.java
index 5fc531b..2f38240 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DBManager.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DBManager.java
@@ -3,23 +3,22 @@ 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 nl.SBDevelopment.SBUtilities.Data.SQLiteDB;
import org.bukkit.Bukkit;
-import org.bukkit.plugin.java.JavaPlugin;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.*;
+import java.util.Map;
public class DBManager {
- private static SBSQLiteDB data;
+ private static SQLiteDB data;
private static Connection con;
- public DBManager(JavaPlugin plugin, String name) {
- data = new SBSQLiteDB(plugin, name);
+ public DBManager(String name) {
+ data = new SQLiteDB(name);
try {
con = data.getConnection();
@@ -95,7 +94,33 @@ public class DBManager {
Gson gson = new Gson();
for (Map.Entry entry : DataManager.getLifts().entrySet()) {
- byte[] blob = gson.toJson(entry.getValue()).getBytes();
+
+
+ //Building JSON for debug purposes.
+ String json = "{" +
+ "blocks: " + gson.toJson(entry.getValue().getBlocks()) +
+ "counter: " + gson.toJson(entry.getValue().getCounter()) +
+ "doorcloser: " + gson.toJson(entry.getValue().getDoorCloser()) +
+ "dooropen:" + gson.toJson(entry.getValue().getDoorOpen()) +
+ "floors: " + gson.toJson(entry.getValue().getFloors()) +
+ "inputs: " + gson.toJson(entry.getValue().getInputs()) +
+ "offlineinputs: " + gson.toJson(entry.getValue().getOfflineInputs()) +
+ "owners: " + gson.toJson(entry.getValue().getOwners()) +
+ "queue: " + gson.toJson(entry.getValue().getQueue()) +
+ "ropes: " + gson.toJson(entry.getValue().getRopes()) +
+ "signs: " + gson.toJson(entry.getValue().getSigns()) +
+ "signtext: " + gson.toJson(entry.getValue().getSignText()) +
+ "speed: " + gson.toJson(entry.getValue().getSpeed()) +
+ "tomove: " + gson.toJson(entry.getValue().getToMove()) +
+ "worldname: " + gson.toJson(entry.getValue().getWorldName()) +
+ "y: " + gson.toJson(entry.getValue().getY()) +
+ "}";
+
+ Bukkit.getLogger().info(entry.getKey() + " : " + json);
+
+ Bukkit.getLogger().info(gson.toJson(entry.getValue()));
+
+ /*byte[] blob = gson.toJson(entry.getValue()).getBytes();
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
@@ -115,7 +140,7 @@ public class DBManager {
statement2.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
- }
+ }*/
}
}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Utils/LocationSerializer.java b/src/main/java/nl/SBDeveloper/V10Lift/Utils/LocationSerializer.java
deleted file mode 100644
index 82d8057..0000000
--- a/src/main/java/nl/SBDeveloper/V10Lift/Utils/LocationSerializer.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package nl.SBDeveloper.V10Lift.Utils;
-
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-public class LocationSerializer {
-
- //Hieronder de methodes zonder yaw & pitch!
- @Nonnull
- public static Location deserialize(@Nonnull String string) {
- String[] split = string.split("_");
-
- //world_x_y_z
- return new Location(
- Bukkit.getWorld(split[0]),
- Double.parseDouble(split[1]),
- Double.parseDouble(split[2]),
- Double.parseDouble(split[3])
- );
- }
-
- @Nullable
- public static String serialize(@Nonnull Location loc) {
- if (loc.getWorld() == null) return null;
- return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ();
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java b/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java
deleted file mode 100644
index 08de615..0000000
--- a/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBSQLiteDB.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package nl.SBDeveloper.V10Lift.Utils;
-
-import com.zaxxer.hikari.HikariConfig;
-import com.zaxxer.hikari.HikariDataSource;
-import com.zaxxer.hikari.util.DriverDataSource;
-import org.bukkit.Bukkit;
-import org.bukkit.plugin.Plugin;
-
-import javax.annotation.Nonnull;
-import javax.sql.DataSource;
-import java.io.File;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.*;
-
-public class SBSQLiteDB {
-
- private HikariDataSource source;
-
- /**
- * Initialize a new connection
- *
- * @param plugin The plugin (Main class)
- * @param name The database name
- */
- public SBSQLiteDB(@Nonnull Plugin plugin, String name) {
- Bukkit.getLogger().info("[V10Lift] Loading databases...");
-
- File dbFile = new File(plugin.getDataFolder(), name + ".db");
-
- if (!dbFile.exists()) {
- try {
- Bukkit.getLogger().info("[V10Lift] Generating the " + name + ".db!");
- dbFile.createNewFile();
- } catch (IOException e) {
- Bukkit.getLogger().severe("[V10Lift] Couldn't generate the " + name + ".db!");
- e.printStackTrace();
- return;
- }
- }
-
- DataSource dataSource = new DriverDataSource("jdbc:sqlite:" + dbFile.getAbsolutePath(), "org.sqlite.JDBC", new Properties(), null, null);
- HikariConfig config = new HikariConfig();
- config.setPoolName("SQLiteConnectionPool");
- config.setDataSource(dataSource);
-
- this.source = new HikariDataSource(config);
- }
-
- //CREATE TABLE -> execute()
- //SELECT -> executeQuery()
- //UPDATE -> executeUpdate()
-
- public Connection getConnection() throws SQLException {
- return this.source.getConnection();
- }
-
- public void closeSource() {
- Bukkit.getLogger().info("[V10Lift] Closing the database connection!");
- this.source.close();
- }
-}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBYamlFile.java b/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBYamlFile.java
deleted file mode 100644
index 3603bb7..0000000
--- a/src/main/java/nl/SBDeveloper/V10Lift/Utils/SBYamlFile.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package nl.SBDeveloper.V10Lift.Utils;
-
-import org.bukkit.Bukkit;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.Plugin;
-
-import javax.annotation.Nonnull;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.StandardCharsets;
-
-public class SBYamlFile {
- //SBYamlFile file = new SBYamlFile(this, "data");
-
- private FileConfiguration fileConfiguration;
- private File file;
- private String name;
- private Plugin pl;
-
- public SBYamlFile(@Nonnull Plugin pl, String name) {
- this.pl = pl;
- this.name = name;
-
- if (!pl.getDataFolder().exists()) {
- pl.getDataFolder().mkdir();
- }
-
- this.file = new File(pl.getDataFolder(), name + ".yml");
- if (!this.file.exists()) {
- try {
- this.file.createNewFile();
- Bukkit.getLogger().info("[V10Lift] Generating the " + name + ".yml!");
- } catch (IOException e) {
- Bukkit.getLogger().severe("[V10Lift] Couldn't generate the " + name + ".yml!");
- }
- }
- this.fileConfiguration = YamlConfiguration.loadConfiguration(this.file);
- }
-
- public void loadDefaults() {
- Bukkit.getLogger().info("[V10Lift] Copying default " + name + ".yml to the folder, if needed!");
- Reader defConfigStream1 = new InputStreamReader(this.pl.getResource(name + ".yml"), StandardCharsets.UTF_8);
- YamlConfiguration defConfig1 = YamlConfiguration.loadConfiguration(defConfigStream1);
- getFile().setDefaults(defConfig1);
- getFile().options().copyDefaults(true);
- saveFile();
- }
-
- public FileConfiguration getFile() {
- return this.fileConfiguration;
- }
-
- public void saveFile() {
- try {
- this.fileConfiguration.save(this.file);
- } catch (IOException e) {
- Bukkit.getLogger().severe("[V10Lift] Couldn't save the " + name + ".yml!");
- }
- }
-
- public void reloadConfig() {
- this.fileConfiguration = YamlConfiguration.loadConfiguration(this.file);
- }
-}
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Utils/UpdateManager.java b/src/main/java/nl/SBDeveloper/V10Lift/Utils/UpdateManager.java
deleted file mode 100644
index 0ba160e..0000000
--- a/src/main/java/nl/SBDeveloper/V10Lift/Utils/UpdateManager.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package nl.SBDeveloper.V10Lift.Utils;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import org.bukkit.Bukkit;
-import org.bukkit.plugin.Plugin;
-
-import javax.annotation.Nonnull;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.function.BiConsumer;
-
-/**
- * Update class for SBDevelopment
- * @author Stijn [SBDeveloper]
- * @since 12-01-2020
- * @version 1.1
- *
- * © Stijn Bannink - All rights reserved.
- */
-public class UpdateManager {
-
- private static String SPIGOT_API = "http://api.spiget.org/v2/resources/%d/versions?size=1&sort=-releaseDate";
- private static String SBDPLUGINS_API = "http://updates.sbdplugins.nl:4000/api/resources/%d";
-
- private Plugin plugin;
- private String currentVersion;
- private int resourceID;
- private CheckType type;
- private BiConsumer versionResponse;
-
- /**
- * Construct a new UpdateManager
- *s
- * @param plugin The javaplugin (Main class)
- * @param resourceID The resourceID on spigot/sbdplugins
- * @param type The check type
- */
- public UpdateManager(@Nonnull Plugin plugin, int resourceID, CheckType type) {
- this.plugin = plugin;
- this.currentVersion = plugin.getDescription().getVersion();
- this.resourceID = resourceID;
- this.type = type;
- }
-
- /**
- * Handle the response given by check();
- * @param versionResponse The response
- * @return The updatemanager
- */
- public UpdateManager handleResponse(BiConsumer versionResponse) {
- this.versionResponse = versionResponse;
- return this;
- }
-
- /**
- * Check for a new version
- */
- public void check() {
- Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
- try {
- HttpURLConnection con = null;
- if (type == CheckType.SPIGOT) {
- con = (HttpURLConnection) new URL(String.format(SPIGOT_API, this.resourceID)).openConnection();
- } else if (type == CheckType.SBDPLUGINS) {
- con = (HttpURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection();
- }
-
- if (con == null) return;
-
- con.setRequestMethod("GET");
- con.setRequestProperty("User-Agent", "Mozilla/5.0");
-
- String version = null;
-
- BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String inputLine;
- StringBuilder response = new StringBuilder();
- while ((inputLine = in.readLine()) != null) {
- response.append(inputLine);
- }
- in.close();
-
- JsonParser parser = new JsonParser();
-
- if (type == CheckType.SPIGOT) {
- JsonArray array = parser.parse(response.toString()).getAsJsonArray();
-
- version = array.get(0).getAsJsonObject().get("name").getAsString();
- } else if (type == CheckType.SBDPLUGINS) {
- JsonObject object = parser.parse(response.toString()).getAsJsonObject();
-
- version = object.get("data").getAsJsonObject().get("version").getAsString();
- }
-
- if (version == null) return;
-
- boolean latestVersion = version.equalsIgnoreCase(this.currentVersion);
-
- String finalVersion = version;
- Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(latestVersion ? VersionResponse.LATEST : VersionResponse.FOUND_NEW, latestVersion ? this.currentVersion : finalVersion));
- } catch (IOException | NullPointerException e) {
- e.printStackTrace();
- Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(VersionResponse.UNAVAILABLE, null));
- }
- });
- }
-
- public enum CheckType {
- SPIGOT, SBDPLUGINS
- }
-
- public enum VersionResponse {
- LATEST, FOUND_NEW, UNAVAILABLE
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java b/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java
index bc67bd7..298c7fb 100644
--- a/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java
+++ b/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java
@@ -7,8 +7,9 @@ import nl.SBDeveloper.V10Lift.Listeners.EntityDamageListener;
import nl.SBDeveloper.V10Lift.Listeners.PlayerInteractListener;
import nl.SBDeveloper.V10Lift.Listeners.SignChangeListener;
import nl.SBDeveloper.V10Lift.Managers.DBManager;
-import nl.SBDeveloper.V10Lift.Utils.SBYamlFile;
-import nl.SBDeveloper.V10Lift.Utils.UpdateManager;
+import nl.SBDevelopment.SBUtilities.Data.YamlFile;
+import nl.SBDevelopment.SBUtilities.PrivateManagers.UpdateManager;
+import nl.SBDevelopment.SBUtilities.SBUtilities;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@@ -18,7 +19,7 @@ import java.util.Objects;
public class V10LiftPlugin extends JavaPlugin {
private static V10LiftPlugin instance;
- private static SBYamlFile config;
+ private static YamlFile config;
private static DBManager dbManager;
private static V10LiftAPI api;
@@ -26,11 +27,13 @@ public class V10LiftPlugin extends JavaPlugin {
public void onEnable() {
instance = this;
- config = new SBYamlFile(this, "config");
+ //Initialize the util
+ new SBUtilities(this, "[V10Lift]");
+
+ config = new YamlFile("config");
config.loadDefaults();
- dbManager = new DBManager(this, "data");
-
+ dbManager = new DBManager("data");
try {
dbManager.load();
} catch (SQLException e) {
@@ -72,7 +75,7 @@ public class V10LiftPlugin extends JavaPlugin {
return instance;
}
- public static SBYamlFile getSConfig() {
+ public static YamlFile getSConfig() {
return config;
}