From aa0afa533d0ab5fa899aaae5b43ff6b746971aaa Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 17 Mar 2024 10:42:36 -0400 Subject: [PATCH] Duplicate key logic makes sense here. --- src/engine/db/handlers/dbWarehouseHandler.java | 5 +++-- src/engine/objects/Warehouse.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index c13e3b37..ee32dc7e 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -87,10 +87,11 @@ public class dbWarehouseHandler extends dbHandlerBase { JSONObject warehouseJSON = new JSONObject(warehouse.resources); try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_warehouse` SET `warehouse` = ? WHERE `cityUID` = ?")) { + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse` (`cityUUID`, `warehouse`) VALUES (?, ?) " + + "ON DUPLICATE KEY UPDATE `warehouse` = VALUES(`warehouse`)")) { - preparedStatement.setString(2, warehouseJSON.toString()); preparedStatement.setInt(1, warehouse.city.getObjectUUID()); + preparedStatement.setString(2, warehouseJSON.toString()); return (preparedStatement.executeUpdate() > 0); diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index a3d509cd..472b0d3c 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -46,7 +46,7 @@ public class Warehouse { resources.put(resourceType, value); } - JSONArray lockedResources = (JSONArray) warehouse.get("locked"); + JSONArray lockedResources = (JSONArray) warehouse.get("locks"); if (lockedResources.isEmpty() == false) for (Object o : lockedResources)