From 0d93850813a2929848d2ff2e2be22e3c926b9fda Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 18 Feb 2024 11:08:46 -0500 Subject: [PATCH] dbHandler created --- src/engine/db/handlers/dbItemHandler.java | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/engine/db/handlers/dbItemHandler.java b/src/engine/db/handlers/dbItemHandler.java index 8e6ffd95..2367563c 100644 --- a/src/engine/db/handlers/dbItemHandler.java +++ b/src/engine/db/handlers/dbItemHandler.java @@ -15,6 +15,9 @@ import engine.gameManager.DbManager; 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.pmw.tinylog.Logger; import java.sql.Connection; @@ -163,6 +166,28 @@ public class dbItemHandler extends dbHandlerBase { return itemList; } + public void LOAD_ITEM_TEMPLATES() { + + JSONParser jsonParser = new JSONParser(); + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `cache_data_items`;")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + + JSONObject jsonObject = (JSONObject) jsonParser.parse(rs.getString("template")); + ItemTemplate itemTemplate = new ItemTemplate(jsonObject); + ItemTemplate.itemTemplates.put(rs.getInt("id"), itemTemplate); + } + + } catch (Exception e) { + Logger.error(e); + } + + } + public Item GET_ITEM(final int itemUUID) { Item item;