diff --git a/src/engine/db/handlers/dbItemHandler.java b/src/engine/db/handlers/dbItemHandler.java index 5b94ddf1..e04f68cc 100644 --- a/src/engine/db/handlers/dbItemHandler.java +++ b/src/engine/db/handlers/dbItemHandler.java @@ -26,6 +26,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashSet; @@ -497,6 +498,34 @@ public class dbItemHandler extends dbHandlerBase { } } + public void UPDATE_ALL_FLAGS() { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_item`")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + + int item_uuid = rs.getInt("UID"); + int templateID = rs.getInt("item_itembaseID"); + EnumSet item_flags = EnumSet.noneOf(Enum.ItemFlags.class); + item_flags.addAll(ItemTemplate.templates.get(templateID).item_flags); + + int identified = rs.getInt("old_flags"); + + if (identified != 0) + item_flags.add(Enum.ItemFlags.Identified); + + UPDATE_FLAGS(item_uuid, item_flags); + } + + } catch (SQLException e) { + Logger.error(e); + } + + } + public boolean UPDATE_FLAGS(Item item) { try (Connection connection = DbManager.getConnection(); @@ -518,6 +547,27 @@ public class dbItemHandler extends dbHandlerBase { } } + public boolean UPDATE_FLAGS(int itemUUID, EnumSet itemFlags) { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) { + + String flagString = ""; + + for (Enum.ItemFlags itemflag : itemFlags) + flagString += itemflag.toString() + ";"; + + preparedStatement.setString(1, flagString); + preparedStatement.setLong(2, itemUUID); + + return (preparedStatement.executeUpdate() > 0); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + } + public boolean UPDATE_VALUE(Item item, int value) { try (Connection connection = DbManager.getConnection(); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 4043e974..411f0f2f 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -343,6 +343,9 @@ public class WorldServer { Logger.info("Loading Item Templates"); DbManager.ItemQueries.LOAD_ITEM_TEMPLATES(); + Logger.info("Back filling item flags"); + DbManager.ItemQueries.UPDATE_ALL_FLAGS(); + Logger.info("Loading ItemBases"); ItemBase.loadAllItemBases();