Fixed removing lifts (DB)

This commit is contained in:
stijnb1234 2020-02-03 16:51:20 +01:00
parent e1055f234f
commit 144f9cdaf1

View file

@ -45,12 +45,28 @@ public class DBManager {
}
public void save() {
try {
Gson gson = new Gson();
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
String query0 = "SELECT * FROM lifts";
PreparedStatement statement0 = data.getConnection().prepareStatement(query0);
ResultSet liftSet = statement0.executeQuery();
while (liftSet.next()) {
if (!DataManager.containsLift(liftSet.getString("liftName"))) {
Bukkit.getLogger().info("[V10Lift] Removing lift " + liftSet.getString("liftName") + " to data...");
String query = "DELETE FROM lifts WHERE liftName = ?";
PreparedStatement statement = data.getConnection().prepareStatement(query);
statement.setString(1, liftSet.getString("liftName"));
statement.executeUpdate();
}
}
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
byte[] blob = gson.toJson(entry.getValue()).getBytes();
try {
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
String query = "INSERT INTO lifts (liftName, liftData) VALUES (?, ?)";
PreparedStatement statement = data.getConnection().prepareStatement(query);
statement.setString(1, entry.getKey());
@ -62,10 +78,8 @@ public class DBManager {
statement2.setBytes(1, blob);
statement2.setString(2, entry.getKey());
statement2.executeUpdate();
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
} catch(SQLException ignored) {}
}
} catch(SQLException ignored) {}
}
public void closeConnection() {