From 568b0291a255246427d9d823544bdd6e6f94ea12 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 23 May 2023 11:18:21 -0400 Subject: [PATCH] Duplicate method removed. --- src/engine/db/handlers/dbBuildingHandler.java | 12 +++++------ src/engine/db/handlers/dbItemHandler.java | 20 ------------------- src/engine/objects/Item.java | 20 ++++++++++++------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index 94b43be4..a7696dae 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -649,11 +649,11 @@ public class dbBuildingHandler extends dbHandlerBase { public final DbObjectType GET_UID_ENUM(long object_UID) { - DbObjectType storedEnum = DbObjectType.INVALID; - String objectType = "INVALID"; + DbObjectType objectType = DbObjectType.INVALID; + String typeString = "INVALID"; if (object_UID == 0) - return storedEnum; + return objectType; try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `object`.`UID` = ? LIMIT 1;")) { @@ -663,8 +663,8 @@ public class dbBuildingHandler extends dbHandlerBase { ResultSet rs = preparedStatement.executeQuery(); if (rs.next()) { - objectType = rs.getString("type").toUpperCase(); - storedEnum = DbObjectType.valueOf(objectType); + typeString = rs.getString("type").toUpperCase(); + objectType = DbObjectType.valueOf(typeString); } } catch (SQLException e) { @@ -672,7 +672,7 @@ public class dbBuildingHandler extends dbHandlerBase { return DbObjectType.INVALID; } - return storedEnum; + return objectType; } public boolean updateBuildingRank(final Building b, int Rank) { diff --git a/src/engine/db/handlers/dbItemHandler.java b/src/engine/db/handlers/dbItemHandler.java index 5b21c257..9615bfe9 100644 --- a/src/engine/db/handlers/dbItemHandler.java +++ b/src/engine/db/handlers/dbItemHandler.java @@ -107,26 +107,6 @@ public class dbItemHandler extends dbHandlerBase { return null; } - public String GET_OWNER(int ownerID) { - - String ownerType; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `UID`=?")) { - - preparedStatement.setInt(1, ownerID); - ResultSet rs = preparedStatement.executeQuery(); - - ownerType = rs.getString("type"); - - } catch (SQLException e) { - Logger.error(e); - return ""; - } - - return ownerType; - } - public boolean DO_TRADE(HashSet from1, HashSet from2, CharacterItemManager man1, CharacterItemManager man2, Item inventoryGold1, Item inventoryGold2, int goldFrom1, int goldFrom2) { diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index add14aa3..11bd94e5 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -210,14 +210,20 @@ public class Item extends AbstractWorldObject { this.durabilityCurrent = rs.getShort("item_durabilityCurrent"); this.durabilityMax = rs.getShort("item_durabilityMax"); - String ot = DbManager.ItemQueries.GET_OWNER(this.ownerID); + DbObjectType ownerType; + ownerType = DbManager.BuildingQueries.GET_UID_ENUM(this.ownerID); - if (ot.equals("character")) - this.ownerType = OwnerType.PlayerCharacter; - else if (ot.equals("npc")) - this.ownerType = OwnerType.Npc; - else if (ot.equals("account")) - this.ownerType = OwnerType.Account; + switch (ownerType) { + case CHARACTER: + this.ownerType = OwnerType.PlayerCharacter; + break; + case NPC: + this.ownerType = OwnerType.Npc; + break; + case ACCOUNT: + this.ownerType = OwnerType.Account; + break; + } this.canDestroy = true;