local itemFilter = {
swapItems = function(payload)
DebugPrint('收到物品交换请求')
DebugPrint(string.format('交换类型: %s', payload.toType or 'nil'))
DebugPrint(string.format('完整payload: %s', json.encode(payload)))
if not payload then
DebugPrint('payload为空')
return true
end
if not payload.fromSlot then
DebugPrint('fromSlot为空')
return true
end
if not payload.fromSlot.name then
DebugPrint('fromSlot.name为空')
return true
end
if payload.toType == 'drop' then
local itemName = payload.fromSlot.name
DebugPrint(string.format('检查物品: %s, 限制状态: %s', itemName, tostring(Config.RestrictedItems[itemName])))
DebugPrint(string.format('当前限制物品列表: %s', json.encode(Config.RestrictedItems)))
if Config.RestrictedItems[itemName] then
DebugPrint(string.format(Config.Lang.Debug.ItemCheck, itemName))
Notify(payload.fromInventory, Config.Lang.Messages.Discard)
return false
end
end
return true
end
}
-- 注册钩子
exports.ox_inventory:registerHook('swapItems', itemFilter.swapItems)