Skip to content

Commit

Permalink
Add ULibPostCommandCalled (#80)
Browse files Browse the repository at this point in the history
* Add hook for post command called

* Document the hide param

* Change tenses in defines

* Update versions

* Fix version numbers
  • Loading branch information
brandonsturgeon authored Aug 5, 2022
1 parent 8f86a5a commit e4272fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lua/ulib/server/concommand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lua/ulib/shared/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
23 changes: 20 additions & 3 deletions lua/ulib/shared/defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -467,6 +486,4 @@ if SERVER then
util.AddNetworkString( "tsayc" )
util.AddNetworkString( "ulib_repWriteCvar" )
util.AddNetworkString( "ulib_repChangeCvar" )


end

0 comments on commit e4272fe

Please sign in to comment.