mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:01:22 +00:00
refactor(es_extended/server/functions): Refactor command argument validation logic
This commit is contained in:
@@ -147,11 +147,11 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
||||
end
|
||||
end
|
||||
|
||||
if v.isValid and not err then
|
||||
if ESX.IsFunctionReference(v.Validator?.validate) and not err then
|
||||
local candidate = newArgs[v.name]
|
||||
local ok, res = pcall(v.isValid, candidate)
|
||||
local ok, res = pcall(v.Validator.validate, candidate)
|
||||
if not ok or res ~= true then
|
||||
err = v.err or TranslateCap("commanderror_argumentmismatch")
|
||||
err = v.Validator.err or TranslateCap("commanderror_argumentmismatch")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -313,9 +313,10 @@ if not Config.CustomInventory then
|
||||
arguments = {
|
||||
{ name = "playerId", help = TranslateCap("commandgeneric_playerid"), type = "player" },
|
||||
{ name = "item", help = TranslateCap("command_giveitem_item"), type = "item" },
|
||||
{ name = "count", help = TranslateCap("command_giveitem_count"), type = "number", isValid = function (countValue)
|
||||
return countValue > 0
|
||||
end, err = TranslateCap("commanderror_argumentmismatch_positive_number", "count")},
|
||||
{ name = "count", help = TranslateCap("command_giveitem_count"), type = "number", Validator = {
|
||||
validate = function(x) return x > 0 end,
|
||||
err = TranslateCap("commanderror_argumentmismatch_positive_number", "count")
|
||||
}},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user