All pastes #66635 Raw Edit

Unnamed

public text v1 · immutable
#66635 ·published 2006-06-17 20:13 UTC
rendered paste body
public void restore()
    {
        java.sql.Connection con = null;
        try
        {
            con = L2DatabaseFactory.getInstance().getConnection();
            PreparedStatement statement = con.prepareStatement(
                    "SELECT object_id FROM items WHERE owner_id=? AND (loc=? OR loc=?) " +
                    "ORDER BY object_id DESC");
            statement.setInt(1, getOwner().getObjectId());
            statement.setString(2, getBaseLocation().name());
            statement.setString(3, getEquipLocation().name());
            ResultSet inv = statement.executeQuery();
            
            L2ItemInstance item;
            while (inv.next())
            {
                int objectId = inv.getInt(1);
                item = L2ItemInstance.restoreFromDb(objectId);
                if (item == null) continue;
                
                if(getOwner() instanceof L2PcInstance)
                {
                    L2PcInstance player = (L2PcInstance)getOwner();
                    
                    if(!player.isGM())
                        if (!player.isHero())
                        {
                            int itemId = item.getItemId();
                            if ((itemId >= 6611 && itemId <= 6621) || itemId == 6842)
                                item.setLocation(ItemLocation.INVENTORY);
                        }
                }
                
                L2World.getInstance().storeObject(item);

                // If stackable item is found in inventory just add to current quantity
                if (item.isStackable() && getItemByItemId(item.getItemId()) != null)
                    addItem("Restore", item, null, getOwner());
                else addItem(item);
            }
            
            inv.close();
            statement.close();
            refreshWeight();
        }
        catch (Exception e)
        {
            _log.warning("Could not restore inventory : " + e);
        } 
        finally 
        {
            try { con.close(); } catch (Exception e) {}
        }
    }