From 52eab1020005ca78a79ac5d8a43fd7b875e732b4 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sun, 31 Aug 2025 16:21:46 +0200 Subject: [PATCH] refactor(es_extended/server/functions): Refactor command argument validation logic --- [core]/es_extended/server/functions.lua | 6 +++--- [core]/es_extended/server/modules/commands.lua | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index e28920ba..4ff790b0 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -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 diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index f445ad82..2320e82f 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -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") + }}, }, } )