Skip to content

Commit 52eab10

Browse files
committed
refactor(es_extended/server/functions): Refactor command argument validation logic
1 parent 6ef25f1 commit 52eab10

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

[core]/es_extended/server/functions.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
147147
end
148148
end
149149

150-
if v.isValid and not err then
150+
if ESX.IsFunctionReference(v.Validator?.validate) and not err then
151151
local candidate = newArgs[v.name]
152-
local ok, res = pcall(v.isValid, candidate)
152+
local ok, res = pcall(v.Validator.validate, candidate)
153153
if not ok or res ~= true then
154-
err = v.err or TranslateCap("commanderror_argumentmismatch")
154+
err = v.Validator.err or TranslateCap("commanderror_argumentmismatch")
155155
end
156156
end
157157

[core]/es_extended/server/modules/commands.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@ if not Config.CustomInventory then
313313
arguments = {
314314
{ name = "playerId", help = TranslateCap("commandgeneric_playerid"), type = "player" },
315315
{ name = "item", help = TranslateCap("command_giveitem_item"), type = "item" },
316-
{ name = "count", help = TranslateCap("command_giveitem_count"), type = "number", isValid = function (countValue)
317-
return countValue > 0
318-
end, err = TranslateCap("commanderror_argumentmismatch_positive_number", "count")},
316+
{ name = "count", help = TranslateCap("command_giveitem_count"), type = "number", Validator = {
317+
validate = function(x) return x > 0 end,
318+
err = TranslateCap("commanderror_argumentmismatch_positive_number", "count")
319+
}},
319320
},
320321
}
321322
)

0 commit comments

Comments
 (0)