From ba47b30673bbd591e87771ba28ac86b3908cc98f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 22 Apr 2024 09:21:46 -0400 Subject: [PATCH] Migration to org.json --- src/engine/db/handlers/dbItemHandler.java | 7 ++----- src/engine/db/handlers/dbWarehouseHandler.java | 13 +++++-------- src/engine/gameManager/ForgeManager.java | 2 +- src/engine/loot/WorkOrder.java | 4 ++-- src/engine/objects/ItemTemplate.java | 8 ++++---- src/engine/objects/Warehouse.java | 8 ++++---- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/engine/db/handlers/dbItemHandler.java b/src/engine/db/handlers/dbItemHandler.java index 83229178..008ca9e9 100644 --- a/src/engine/db/handlers/dbItemHandler.java +++ b/src/engine/db/handlers/dbItemHandler.java @@ -17,8 +17,7 @@ import engine.objects.AbstractCharacter; import engine.objects.CharacterItemManager; import engine.objects.Item; import engine.objects.ItemTemplate; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -180,8 +179,6 @@ public class dbItemHandler extends dbHandlerBase { public void LOAD_ITEM_TEMPLATES() { - JSONParser jsonParser = new JSONParser(); - HashMap templateTCountMap = new HashMap<>(); try (Connection connection = DbManager.getConnection(); @@ -190,7 +187,7 @@ public class dbItemHandler extends dbHandlerBase { while (rs.next()) { int templateID = rs.getInt("id"); - JSONObject jsonObject = (JSONObject) jsonParser.parse(rs.getString("template")); + JSONObject jsonObject = new JSONObject(rs.getString("template")); ItemTemplate itemTemplate = new ItemTemplate(jsonObject); itemTemplate.template_id = templateID; ItemTemplate.templates.put(templateID, itemTemplate); diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index f70cb5ff..03033d4b 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -9,19 +9,18 @@ package engine.db.handlers; +import engine.gameManager.DbManager; import engine.mbEnums; import engine.mbEnums.GameObjectType; import engine.mbEnums.TransactionType; -import engine.gameManager.DbManager; import engine.objects.Building; import engine.objects.City; import engine.objects.Transaction; import engine.objects.Warehouse; import engine.server.MBServerStatics; import org.joda.time.DateTime; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import org.json.JSONArray; +import org.json.JSONObject; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -106,7 +105,7 @@ public class dbWarehouseHandler extends dbHandlerBase { JSONArray locks = new JSONArray(); for (mbEnums.ResourceType resource : warehouse.locked) - locks.add(resource.name()); + locks.put(resource.name()); warehouseJSON.put("locked", locks); @@ -127,15 +126,13 @@ public class dbWarehouseHandler extends dbHandlerBase { public void LOAD_WAREHOUSES() { - JSONParser jsonParser = new JSONParser(); - try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_warehouse`;"); ResultSet rs = preparedStatement.executeQuery()) { while (rs.next()) { int cityUID = rs.getInt("cityUUID"); - JSONObject jsonObject = (JSONObject) jsonParser.parse(rs.getString("warehouse")); + JSONObject jsonObject = new JSONObject(rs.getString("warehouse")); City city = City.getCity(cityUID); city.warehouse = new Warehouse(jsonObject); city.warehouse.city = city; diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 23f28f90..f38ff8e0 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -16,7 +16,7 @@ import engine.net.DispatchMessage; import engine.net.client.msg.ItemProductionMsg; import engine.objects.*; import engine.powers.EffectsBase; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.pmw.tinylog.Logger; import java.util.ArrayList; diff --git a/src/engine/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index 76586f00..971ebf74 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -11,7 +11,7 @@ package engine.loot; import engine.mbEnums; import engine.objects.Item; import engine.objects.NPC; -import org.json.simple.JSONObject; +import org.json.JSONObject; import java.time.Duration; import java.time.Instant; @@ -55,7 +55,7 @@ public class WorkOrder implements Delayed { JSONObject jsonWorkOrder = new JSONObject(); - jsonWorkOrder.put("jsonWorkOrder", workOrder.workOrderID); + jsonWorkOrder.put("workOrderID", workOrder.workOrderID); jsonWorkOrder.put("vendor", workOrder.vendor.getObjectUUID()); jsonWorkOrder.put("slots_used", workOrder.slots_used); jsonWorkOrder.put("total_to_produce", workOrder.total_to_produce); diff --git a/src/engine/objects/ItemTemplate.java b/src/engine/objects/ItemTemplate.java index 0ac29787..e4c2d2e3 100644 --- a/src/engine/objects/ItemTemplate.java +++ b/src/engine/objects/ItemTemplate.java @@ -10,8 +10,8 @@ package engine.objects; import engine.math.Vector3fImmutable; import engine.mbEnums; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; import org.pmw.tinylog.Logger; import java.util.ArrayList; @@ -194,7 +194,7 @@ public class ItemTemplate { JSONObject resist_json = (JSONObject) jsonObject.get("combat_attack_resist"); - for (Object key : resist_json.keySet()) { + for (String key : resist_json.keySet()) { float resist = ((Double) resist_json.get(key)).floatValue(); combat_attack_resist.put((String) key, resist); } @@ -488,7 +488,7 @@ public class ItemTemplate { JSONObject rune_speed_json = (JSONObject) jsonObject.get("rune_speed"); - for (Object key : rune_speed_json.keySet()) { + for (String key : rune_speed_json.keySet()) { mbEnums.MovementType movementType = mbEnums.MovementType.valueOf((String) key); float speed = ((Double) rune_speed_json.get(key)).floatValue(); rune_speed.put(movementType, speed); diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 53eebeba..f15a6611 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -19,8 +19,8 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.*; import engine.server.MBServerStatics; import org.joda.time.DateTime; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; import org.pmw.tinylog.Logger; import java.sql.SQLException; @@ -56,8 +56,8 @@ public class Warehouse { JSONObject resources = (JSONObject) warehouse.get("resources"); - for (Object key : resources.keySet()) { - mbEnums.ResourceType resourceType = mbEnums.ResourceType.valueOf((String) key); + for (String key : resources.keySet()) { + mbEnums.ResourceType resourceType = mbEnums.ResourceType.valueOf(key); int value = ((Long) resources.get(key)).intValue(); this.resources.put(resourceType, value); }