From fe5aedc7c9c004c76307b81f6032918905a7b77c Mon Sep 17 00:00:00 2001 From: Brandon Sturgeon Date: Wed, 14 Sep 2022 18:46:17 -0500 Subject: [PATCH] Simplify the purpose of PostCommandCalled (#87) --- lua/ulib/server/concommand.lua | 4 +--- lua/ulib/shared/commands.lua | 6 ++---- lua/ulib/shared/defines.lua | 21 ++------------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/lua/ulib/server/concommand.lua b/lua/ulib/server/concommand.lua index 4e39df3..0c42ba8 100644 --- a/lua/ulib/server/concommand.lua +++ b/lua/ulib/server/concommand.lua @@ -25,7 +25,6 @@ ULib.sayCmds = ULib.sayCmds or {} Revisions: v2.10 - Made case-insensitive - v2.72 - Added ULibPostCommandCalled ]] local function sayCmdCheck( ply, strText, bTeam ) local match @@ -69,8 +68,7 @@ local function sayCmdCheck( ply, strText, bTeam ) local fn = data.fn local hide = data.hide - local err = ULib.pcallError( fn, ply, match:Trim(), argv, args ) - hook.Call( ULib.HOOK_POST_COMMAND_CALLED, _, ply, data.__cmd, argv, hide, not err ) + ULib.pcallError( fn, ply, match:Trim(), argv, args ) if hide then return "" end end diff --git a/lua/ulib/shared/commands.lua b/lua/ulib/shared/commands.lua index a67e419..f9f36ab 100644 --- a/lua/ulib/shared/commands.lua +++ b/lua/ulib/shared/commands.lua @@ -948,8 +948,8 @@ local function translateCmdCallback( ply, commandName, argv ) end end - cmd:call( isOpposite, unpack( args ) ) - hook.Call( ULib.HOOK_POST_TRANSLATED_COMMAND, _, ply, commandName, args ) + local callResult = cmd:call( isOpposite, unpack( args ) ) + hook.Call( ULib.HOOK_POST_TRANSLATED_COMMAND, _, ply, commandName, args, callResult ) end local function translateAutocompleteCallback( commandName, args ) @@ -1315,7 +1315,6 @@ end Revisions: v2.62 - Initial - v2.72 - Added ULibPostCommandCalled ]] function cmds.execute( cmdTable, ply, commandName, argv ) if CLIENT and not cmdTable.__client_only then @@ -1330,7 +1329,6 @@ function cmds.execute( cmdTable, ply, commandName, argv ) local return_value = hook.Call( ULib.HOOK_COMMAND_CALLED, _, ply, commandName, argv ) if return_value ~= false then cmdTable.__fn( ply, commandName, argv ) - hook.Call( ULib.HOOK_POST_COMMAND_CALLED, _, ply, commandName, argv ) end end diff --git a/lua/ulib/shared/defines.lua b/lua/ulib/shared/defines.lua index e3a5e03..de40877 100644 --- a/lua/ulib/shared/defines.lua +++ b/lua/ulib/shared/defines.lua @@ -116,25 +116,6 @@ ULib.HOOK_LOCALPLAYERREADY = "ULibLocalPlayerReady" ]] ULib.HOOK_COMMAND_CALLED = "ULibCommandCalled" ---[[ - Hook: ULibPostCommandCalled - - Called *on server* after a ULib command is run. - - Parameters passed to callback: - - ply - The player that executed the command. - commandName - The command that was executed. - args - The table of args for the command. - hide - If triggered from a chat command, a boolean indicating if the output of the command should be hidden. - success - If triggered from a chat command, a boolean indicating if the command ran successfully. - - Revisions: - - v2.72 - Initial -]] -ULib.HOOK_POST_COMMAND_CALLED = "ULibPostCommandCalled" - --[[ Hook: ULibPlayerTarget @@ -186,10 +167,12 @@ ULib.HOOK_PLAYER_TARGETS = "ULibPlayerTargets" -- Exactly the same as the above ply - The player that executed the command. commandName - The command that's being executed. translated_args - A table of the translated arguments, as passed into the callback function itself. + callResult - The return value of the command function. Revisions: v2.40 - Initial + v2.72 - Add the callResult parameter ]] ULib.HOOK_POST_TRANSLATED_COMMAND = "ULibPostTranslatedCommand"