3
0
Fork 0

Release v2.1.4: Fixed updatechecker (changed ID), and added saving for Malfunction GUI

This commit is contained in:
stijnb1234 2021-02-28 12:25:45 +01:00
parent 75a5c96d39
commit 54437672d0
6 changed files with 62 additions and 11 deletions

View file

@ -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;

View file

@ -38,6 +38,10 @@ public class PlusAPI {
return reports.containsKey(rideID);
}
public static HashMap<String, MalfunctionReport> getReports() {
return reports;
}
/**
* Add a gate
*

View file

@ -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<XMaterial> stack = XMaterial.matchXMaterial(material);
return stack.map(xMaterial -> new ItemBuilder(xMaterial.parseItem()).name(name).lore(loresFormatted).build()).orElse(null);
}
}

View file

@ -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<String, WaitingRow> 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<String, MalfunctionReport> 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() {

View file

@ -1,4 +1,4 @@
License: 'TPABCD-1234-ABCD-1234SBD'
License: ''
AntiFreerun:
Enabled: false
UpdateChecker:

View file

@ -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.'
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'