mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 05:56:02 +01:00
Stop crafting trying to check blank stash names
Skimmed through the stash checking and editing functions and added more "security" for handling nil or blank stash names
This commit is contained in:
@@ -89,7 +89,7 @@ function craftingMenu(data)
|
|||||||
-- Check if the player can carry the required items (server callback).
|
-- Check if the player can carry the required items (server callback).
|
||||||
local canCarryTable = triggerCallback(getScript()..':server:canCarry', tempCarryTable)
|
local canCarryTable = triggerCallback(getScript()..':server:canCarry', tempCarryTable)
|
||||||
|
|
||||||
local usingStash = data.stashName ~= nil
|
local usingStash = data.stashName ~= nil and data.stashName ~= ""
|
||||||
|
|
||||||
Menu[#Menu+1] = {
|
Menu[#Menu+1] = {
|
||||||
icon = usingStash and "fas fa-boxes-stacked" or "fas fa-person",
|
icon = usingStash and "fas fa-boxes-stacked" or "fas fa-person",
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ local stash
|
|||||||
-- If running on the server, create a callback to retrieve stash items.
|
-- If running on the server, create a callback to retrieve stash items.
|
||||||
if isServer() then
|
if isServer() then
|
||||||
createCallback(getScript()..':server:GetStashItems', function(source, stashName)
|
createCallback(getScript()..':server:GetStashItems', function(source, stashName)
|
||||||
|
if stashName == nil or stashName == "" then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
stash = getStash(stashName)
|
stash = getStash(stashName)
|
||||||
return stash
|
return stash
|
||||||
end)
|
end)
|
||||||
@@ -35,9 +38,9 @@ local stashCache = {}
|
|||||||
--- local cached = GetStashTimeout("playerStash")
|
--- local cached = GetStashTimeout("playerStash")
|
||||||
--- ```
|
--- ```
|
||||||
function GetStashTimeout(stashName, stop)
|
function GetStashTimeout(stashName, stop)
|
||||||
if stop then
|
if stop or (stashName == nil or stashName == "") then
|
||||||
stashCache = {}
|
stashCache = {}
|
||||||
return
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Retrieve cache for this stash, or initialize if not present.
|
-- Retrieve cache for this stash, or initialize if not present.
|
||||||
@@ -85,7 +88,7 @@ end
|
|||||||
--- local found, stashName = checkStashItem({"playerStash", "storageStash"}, { iron = 2, wood = 5 })
|
--- local found, stashName = checkStashItem({"playerStash", "storageStash"}, { iron = 2, wood = 5 })
|
||||||
--- ```
|
--- ```
|
||||||
function checkStashItem(stashes, itemTable)
|
function checkStashItem(stashes, itemTable)
|
||||||
if not stashes then
|
if not stashes or stashes == "" then
|
||||||
return hasItem(itemTable), nil
|
return hasItem(itemTable), nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -317,7 +320,7 @@ end
|
|||||||
--- ```
|
--- ```
|
||||||
function getStash(stashName)
|
function getStash(stashName)
|
||||||
local stashResource = ""
|
local stashResource = ""
|
||||||
if type(stashName) ~= "string" then
|
if stashName == "" or type(stashName) ~= "string" then
|
||||||
print("^6Bridge^7: ^2Stash name was not a string ^3"..stashName.."^7(^3"..type(stashName).."^7)")
|
print("^6Bridge^7: ^2Stash name was not a string ^3"..stashName.."^7(^3"..type(stashName).."^7)")
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
@@ -420,6 +423,10 @@ end
|
|||||||
--- stashRemoveItem(currentItems, "playerStash", { iron = 2, wood = 5 })
|
--- stashRemoveItem(currentItems, "playerStash", { iron = 2, wood = 5 })
|
||||||
--- ```
|
--- ```
|
||||||
function stashRemoveItem(stashItems, stashName, items)
|
function stashRemoveItem(stashItems, stashName, items)
|
||||||
|
if stashName == "" or stashName == nil then
|
||||||
|
print("^1ERROR^7: ^1stashRemoveItem triggered but stashName was empty^7")
|
||||||
|
return
|
||||||
|
end
|
||||||
if type(stashName) ~= "table" then
|
if type(stashName) ~= "table" then
|
||||||
stashName = { stashName }
|
stashName = { stashName }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user