From 9ff384b9fcef79d1914eb4839721897c2c60c261 Mon Sep 17 00:00:00 2001 From: aysihuniks Date: Wed, 27 May 2026 15:28:01 +0300 Subject: [PATCH 1/2] feat(commands): add pre-execution middleware event --- server/commands.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/commands.lua b/server/commands.lua index 7048ca1..bd1c728 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -21,6 +21,10 @@ function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, perm if permission == 'user' then restricted = false end -- allow all users to use command RegisterCommand(name, function(source, args, rawCommand) -- Register command within fivem + + TriggerEvent('QBCore:Server:PreCommandExecution', source, name, args, rawCommand) + if WasEventCanceled() then return end + if argsrequired and #args < #arguments then return TriggerClientEvent('chat:addMessage', source, { color = { 255, 0, 0 }, From ae51ed75aabe5e240cdb3833f3c467a981b08c01 Mon Sep 17 00:00:00 2001 From: aysihuniks Date: Wed, 27 May 2026 15:39:19 +0300 Subject: [PATCH 2/2] fix: move PreCommandExecution event after argument validation --- server/commands.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index bd1c728..6f339b4 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -21,10 +21,6 @@ function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, perm if permission == 'user' then restricted = false end -- allow all users to use command RegisterCommand(name, function(source, args, rawCommand) -- Register command within fivem - - TriggerEvent('QBCore:Server:PreCommandExecution', source, name, args, rawCommand) - if WasEventCanceled() then return end - if argsrequired and #args < #arguments then return TriggerClientEvent('chat:addMessage', source, { color = { 255, 0, 0 }, @@ -32,6 +28,10 @@ function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, perm args = { 'System', Lang:t('error.missing_args2') } }) end + + TriggerEvent('QBCore:Server:PreCommandExecution', source, name, args, rawCommand) + if WasEventCanceled() then return end + callback(source, args, rawCommand) end, restricted)