Browse Source

Migration to org.json

combat-2
MagicBot 7 months ago
parent
commit
ba47b30673
  1. 7
      src/engine/db/handlers/dbItemHandler.java
  2. 13
      src/engine/db/handlers/dbWarehouseHandler.java
  3. 2
      src/engine/gameManager/ForgeManager.java
  4. 4
      src/engine/loot/WorkOrder.java
  5. 8
      src/engine/objects/ItemTemplate.java
  6. 8
      src/engine/objects/Warehouse.java

7
src/engine/db/handlers/dbItemHandler.java

@ -17,8 +17,7 @@ import engine.objects.AbstractCharacter; @@ -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 { @@ -180,8 +179,6 @@ public class dbItemHandler extends dbHandlerBase {
public void LOAD_ITEM_TEMPLATES() {
JSONParser jsonParser = new JSONParser();
HashMap<ItemType, Integer> templateTCountMap = new HashMap<>();
try (Connection connection = DbManager.getConnection();
@ -190,7 +187,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -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);

13
src/engine/db/handlers/dbWarehouseHandler.java

@ -9,19 +9,18 @@ @@ -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 { @@ -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 { @@ -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;

2
src/engine/gameManager/ForgeManager.java

@ -16,7 +16,7 @@ import engine.net.DispatchMessage; @@ -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;

4
src/engine/loot/WorkOrder.java

@ -11,7 +11,7 @@ package engine.loot; @@ -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 { @@ -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);

8
src/engine/objects/ItemTemplate.java

@ -10,8 +10,8 @@ package engine.objects; @@ -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 { @@ -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 { @@ -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);

8
src/engine/objects/Warehouse.java

@ -19,8 +19,8 @@ import engine.net.client.ClientConnection; @@ -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 { @@ -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);
}

Loading…
Cancel
Save