mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 02:01:31 +00:00
refactor(ox_inventory): update account list parsing and enhance export validation
This commit is contained in:
@@ -15,11 +15,11 @@ local requiredMethods = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
---Parses the inventory:accounts convar to build a lookup table.
|
---Parses the inventory:accounts convar to build a lookup table.
|
||||||
---Handles both JSON array format (["money"]) and plain text.
|
---Uses the same default as ox_inventory: '["money"]'
|
||||||
---@return table<string, boolean>
|
---@return table<string, boolean>
|
||||||
local function getAccountList()
|
local function getAccountList()
|
||||||
local accounts = {}
|
local accounts = {}
|
||||||
local convar = GetConvar("inventory:accounts", "[]")
|
local convar = GetConvar("inventory:accounts", '["money"]')
|
||||||
local ok, list = pcall(json.decode, convar)
|
local ok, list = pcall(json.decode, convar)
|
||||||
|
|
||||||
if ok and type(list) == "table" then
|
if ok and type(list) == "table" then
|
||||||
@@ -44,11 +44,16 @@ local function createOxInventoryProxy()
|
|||||||
local proxy = {}
|
local proxy = {}
|
||||||
local accounts = getAccountList()
|
local accounts = getAccountList()
|
||||||
|
|
||||||
-- Validate that the exports actually exist before wrapping them
|
print("^3[es_extended] ox_inventory: using direct export proxy (Inventory() module unavailable)^7")
|
||||||
|
|
||||||
for i = 1, #requiredMethods do
|
for i = 1, #requiredMethods do
|
||||||
local method = requiredMethods[i]
|
local method = requiredMethods[i]
|
||||||
if exports.ox_inventory[method] == nil then
|
local ok, err = pcall(function()
|
||||||
print(("^3[es_extended] WARNING: exports.ox_inventory.%s is missing — ox_inventory integration may be broken^7"):format(method))
|
exports.ox_inventory[method](exports.ox_inventory, 0, "test", 0)
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not ok and tostring(err):find("No such export") then
|
||||||
|
print(("^1[es_extended] CRITICAL: exports.ox_inventory.%s is missing^7"):format(method))
|
||||||
end
|
end
|
||||||
|
|
||||||
proxy[method] = function(...)
|
proxy[method] = function(...)
|
||||||
@@ -56,10 +61,6 @@ local function createOxInventoryProxy()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not OxInventory then
|
|
||||||
print("^2[es_extended] ox_inventory: using direct export proxy (Inventory() module unavailable)^7")
|
|
||||||
end
|
|
||||||
|
|
||||||
proxy.accounts = accounts
|
proxy.accounts = accounts
|
||||||
return proxy
|
return proxy
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user