From e4272fe74209d3493be9f355070d55bf80232a7d Mon Sep 17 00:00:00 2001 From: Brandon Sturgeon Date: Thu, 4 Aug 2022 22:53:15 -0500 Subject: [PATCH] Add ULibPostCommandCalled (#80) * Add hook for post command called * Document the hide param * Change tenses in defines * Update versions * Fix version numbers --- lua/ulib/server/concommand.lua | 5 ++++- lua/ulib/shared/commands.lua | 2 ++ lua/ulib/shared/defines.lua | 23 ++++++++++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lua/ulib/server/concommand.lua b/lua/ulib/server/concommand.lua index 47b8fa6..4e39df3 100644 --- a/lua/ulib/server/concommand.lua +++ b/lua/ulib/server/concommand.lua @@ -25,6 +25,7 @@ ULib.sayCmds = ULib.sayCmds or {} Revisions: v2.10 - Made case-insensitive + v2.72 - Added ULibPostCommandCalled ]] local function sayCmdCheck( ply, strText, bTeam ) local match @@ -68,7 +69,9 @@ local function sayCmdCheck( ply, strText, bTeam ) local fn = data.fn local hide = data.hide - ULib.pcallError( fn, ply, match:Trim(), argv, args ) + local err = ULib.pcallError( fn, ply, match:Trim(), argv, args ) + hook.Call( ULib.HOOK_POST_COMMAND_CALLED, _, ply, data.__cmd, argv, hide, not err ) + if hide then return "" end end diff --git a/lua/ulib/shared/commands.lua b/lua/ulib/shared/commands.lua index 238df60..a67e419 100644 --- a/lua/ulib/shared/commands.lua +++ b/lua/ulib/shared/commands.lua @@ -1315,6 +1315,7 @@ end Revisions: v2.62 - Initial + v2.72 - Added ULibPostCommandCalled ]] function cmds.execute( cmdTable, ply, commandName, argv ) if CLIENT and not cmdTable.__client_only then @@ -1329,6 +1330,7 @@ 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 00cd21e..e3a5e03 100644 --- a/lua/ulib/shared/defines.lua +++ b/lua/ulib/shared/defines.lua @@ -7,7 +7,7 @@ ULib = ULib or {} ULib.RELEASE = false -- Don't access these two directly, use ULib.pluginVersionStr("ULib") -ULib.VERSION = 2.71 +ULib.VERSION = 2.72 ULib.AUTOMATIC_UPDATE_CHECKS = true ULib.ACCESS_ALL = "user" @@ -116,6 +116,25 @@ 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 @@ -467,6 +486,4 @@ if SERVER then util.AddNetworkString( "tsayc" ) util.AddNetworkString( "ulib_repWriteCvar" ) util.AddNetworkString( "ulib_repChangeCvar" ) - - end