From 366815f1f95cc805b3a30d2c8fb0975f11aecf59 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Mon, 20 May 2024 14:11:29 -0500 Subject: [PATCH] databse update for stacked resources --- src/engine/db/handlers/dbItemHandler.java | 20 ++++++++++++++++++++ src/engine/net/client/ClientMessagePump.java | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/engine/db/handlers/dbItemHandler.java b/src/engine/db/handlers/dbItemHandler.java index 2fc9b64e..4cd9f336 100644 --- a/src/engine/db/handlers/dbItemHandler.java +++ b/src/engine/db/handlers/dbItemHandler.java @@ -504,4 +504,24 @@ public class dbItemHandler extends dbHandlerBase { return false; } } + + public boolean UPDATE_NUM_ITEMS(final Item item, int newValue, int oldValue) { + + if (item.getItemBase().getType().equals(ItemType.GOLD)) + return false; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) { + + preparedStatement.setInt(1, newValue); + preparedStatement.setLong(2, item.getObjectUUID()); + + return (preparedStatement.executeUpdate() > 0); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + + } } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 3398eeb0..f1121716 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -1475,7 +1475,7 @@ public class ClientMessagePump implements NetMsgHandler { item.setNumOfItems(item.getNumOfItems() + 1); stacked = true; itemMan.updateInventory(); - item.updateDatabase(); + DbManager.ItemQueries.UPDATE_NUM_ITEMS(item,item.getNumOfItems(),0); break; } }