From 4fc7c90c15000e21dc35261aec0b8542b6167cd1 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 24 Mar 2024 08:41:53 -0400 Subject: [PATCH] Method moved to handler. Less in Item the better. --- .../client/handlers/BuyFromNPCMsgHandler.java | 18 +++++++++++++++++- src/engine/objects/Item.java | 15 --------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java b/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java index 6bf663c4..e094b918 100644 --- a/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java +++ b/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java @@ -10,6 +10,7 @@ package engine.net.client.handlers; import engine.Enum; import engine.exception.MsgSendException; +import engine.gameManager.DbManager; import engine.gameManager.SessionManager; import engine.net.client.ClientConnection; import engine.net.client.msg.BuyFromNPCMsg; @@ -26,6 +27,21 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler { super(BuyFromNPCMsg.class); } + public static Item createItemForPlayer(PlayerCharacter pc, int templateID) { + + Item item = new Item(templateID); + item.ownerID = pc.getObjectUUID(); + item.ownerType = Enum.OwnerType.PlayerCharacter; + item.containerType = Enum.ItemContainerType.INVENTORY; + + try { + item = DbManager.ItemQueries.PERSIST(item); + } catch (Exception e) { + Logger.error(e); + } + return item; + } + @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { @@ -108,7 +124,7 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler { return true; } - vendorItem = Item.createItemForPlayer(sourcePlayer, me.templateID); + vendorItem = createItemForPlayer(sourcePlayer, me.templateID); if (vendorItem != null) { // me.transferEnchants(buy); diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index 043de218..5add89ad 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -532,21 +532,6 @@ public class Item extends AbstractWorldObject { writer.putIntAt(serialized, indexPosition); } - public static Item createItemForPlayer(PlayerCharacter pc, int templateID) { - - Item item = new Item(templateID); - item.ownerID = pc.getObjectUUID(); - item.ownerType = OwnerType.PlayerCharacter; - item.containerType = ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.PERSIST(item); - } catch (Exception e) { - Logger.error(e); - } - return item; - } - public static Item getFromCache(int id) { return (Item) DbManager.getFromCache(GameObjectType.Item, id); }