diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java index fcf16e6..bdc08c9 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/ThemeParkPlus.java @@ -152,7 +152,7 @@ public final class ThemeParkPlus extends JavaPlugin { new Metrics(this, 5023); if (getSConfig().getFile().getBoolean("UpdateChecker.Enabled")) { - UpdateManager updateManager = new UpdateManager(this, 2, license); + UpdateManager updateManager = new UpdateManager(this, 7, license); updateManager.handleResponse((versionResponse, version) -> { switch (versionResponse) { @@ -195,8 +195,9 @@ public final class ThemeParkPlus extends JavaPlugin { @Override public void onDisable() { - Bukkit.getLogger().info("[ThemeParkPlus] Saving data to data file..."); + Bukkit.getLogger().info("[ThemeParkPlus] Saving data..."); data.save(); + data.closeConnection(); Bukkit.getLogger().info("[ThemeParkPlus] Plugin disabled!"); instance = null; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java index f574d6b..514b198 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java @@ -38,6 +38,10 @@ public class PlusAPI { return reports.containsKey(rideID); } + public static HashMap getReports() { + return reports; + } + /** * Add a gate * diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/gui/MalfunctionGUI.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/gui/MalfunctionGUI.java index 2c3e7c9..23fd1f1 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/gui/MalfunctionGUI.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/gui/MalfunctionGUI.java @@ -18,6 +18,7 @@ import org.bukkit.inventory.ItemStack; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -31,9 +32,9 @@ public class MalfunctionGUI { PlusAPI.addReport(malfunctionReport); att.setStatus(Status.MALFUNCTION, null); //Player must be null, otherwise we will get a loop in the listener - //TODO Send message + p.sendMessage(ConfigUtil.getMessage("Malfunction.Reported", Collections.singletonMap("%ride%", att.getName()))); } else { - //TODO Already reported + p.sendMessage(ConfigUtil.getMessage("Malfunction.AlreadyReported", Collections.singletonMap("%ride%", att.getName()))); } p.closeInventory(); }); @@ -45,9 +46,9 @@ public class MalfunctionGUI { PlusAPI.removeReport(att.getId()); att.setStatus(Status.CLOSED, null); //Player must be null, otherwise we will get a loop in the listener - //TODO Send message + p.sendMessage(ConfigUtil.getMessage("Malfunction.Fixed", Collections.singletonMap("%ride%", att.getName()))); } else { - //TODO No malfunction + p.sendMessage(ConfigUtil.getMessage("Malfunction.AlreadyFixed", Collections.singletonMap("%ride%", att.getName()))); } p.closeInventory(); }); @@ -76,7 +77,7 @@ public class MalfunctionGUI { lores.forEach(lore -> loresFormatted.add(lore.replace("%ridename%", (String) data[0]))); break; case "Fix": - String ridename = "this ride"; + String ridename = ConfigUtil.getMessage("Malfunction.ThisRide"); String reporter = "-"; String date = "-"; String reason = "-"; @@ -96,7 +97,6 @@ public class MalfunctionGUI { } Optional stack = XMaterial.matchXMaterial(material); - return stack.map(xMaterial -> new ItemBuilder(xMaterial.parseItem()).name(name).lore(loresFormatted).build()).orElse(null); } } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java index b14a69f..7adb6d9 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java @@ -4,6 +4,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.api.objects.Gate; +import nl.sbdeveloper.themeparkplus.api.objects.MalfunctionReport; import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer; import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB; @@ -36,6 +37,10 @@ public class DBManager { query = "CREATE TABLE IF NOT EXISTS rows (rideID varchar(255) NOT NULL, rowData blob NOT NULL, UNIQUE (rideID))"; statement = con.prepareStatement(query); statement.execute(); + + query = "CREATE TABLE IF NOT EXISTS malfunction_reports (rideID varchar(255) NOT NULL, reportData blob NOT NULL, UNIQUE (rideID))"; + statement = con.prepareStatement(query); + statement.execute(); } catch (SQLException e) { e.printStackTrace(); } @@ -74,6 +79,20 @@ public class DBManager { WaitingRow row = gson.fromJson(json, WaitingRow.class); PlusAPI.addRow(row); } + + /* Load reports */ + query = "SELECT * FROM malfunction_reports"; + statement = con.prepareStatement(query); + ResultSet reportSet = statement.executeQuery(); + while (reportSet.next()) { + //Loading a gates... + byte[] blob = reportSet.getBytes("reportData"); + String json = new String(blob); + + Gson gson = getGson(); + MalfunctionReport report = gson.fromJson(json, MalfunctionReport.class); + PlusAPI.addReport(report); + } } public void save() { @@ -103,7 +122,6 @@ public class DBManager { } for (Map.Entry entry : PlusAPI.getRows().entrySet()) { - Gson gson = getGson(); byte[] blob = gson.toJson(entry.getValue()).getBytes(); @@ -125,6 +143,29 @@ public class DBManager { e.printStackTrace(); } } + + for (Map.Entry entry : PlusAPI.getReports().entrySet()) { + Gson gson = getGson(); + byte[] blob = gson.toJson(entry.getValue()).getBytes(); + + try { + String query = "INSERT INTO malfunction_reports (rideID, reportData) VALUES (?, ?)"; + PreparedStatement statement = con.prepareStatement(query); + statement.setString(1, entry.getKey()); + statement.setBytes(2, blob); + statement.executeUpdate(); + } catch (SQLException ignored) {} + + try { + String query2 = "UPDATE malfunction_reports SET reportData = ? WHERE rideID = ?"; + PreparedStatement statement2 = con.prepareStatement(query2); + statement2.setBytes(1, blob); + statement2.setString(2, entry.getKey()); + statement2.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + } } public void closeConnection() { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a87d1e1..ec7f48f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,4 @@ -License: 'TPABCD-1234-ABCD-1234SBD' +License: '' AntiFreerun: Enabled: false UpdateChecker: diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index e346250..aa4f560 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -40,4 +40,9 @@ WaitingRow: RedstoneTimer: Started: '&aThe timer successfully started. It will go off in &f%sec1% &asecond(s), and will turn off in &f%sec2% &asecond(s) after that.' Malfunction: - NoCommand: '&cYou can''t report or fix a ride using the command. Please use this Malfunction Sign at the ride.' \ No newline at end of file + NoCommand: '&cYou can''t report or fix a ride using the command. Please use this Malfunction Sign at the ride.' + Reported: '&aSuccessfully reported a malfunction for &f%ride%&a.' + AlreadyReported: '&cThere is already a malfunction reported for &f%ride%&c.' + Fixed: '&aThe ride &f%ride%&a is now successfully fixed.' + AlreadyFixed: '&cThe ride &f%ride%&a &chas no malfunction report, and therefore cannot be fixed.' + ThisRide: 'this ride' \ No newline at end of file