Skip to content

Commit

Permalink
Simplify the purpose of PostCommandCalled (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsturgeon authored Sep 14, 2022
1 parent e4272fe commit fe5aedc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
4 changes: 1 addition & 3 deletions lua/ulib/server/concommand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lua/ulib/shared/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand All @@ -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

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

Expand Down

0 comments on commit fe5aedc

Please sign in to comment.