mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 09:17:18 +00:00
fix(Scripts/Misc) CanExecuteCommand renamed and moved to be executed for all commands. (#19081)
* Fix CanExecuteCommand only being executed on command failure. * Updated for style guide. * Removed pointless hook call. * Modified the name of the hook to better reflect function and moved the call to trigger for non-existent commands. * Updated to OnTryExecuteCommand because Foe has a special place in my heart. * Forgot to change these 2 areas.
This commit is contained in:
@@ -322,8 +322,12 @@ namespace Acore::Impl::ChatCommands
|
||||
oldTail = newTail;
|
||||
}
|
||||
|
||||
if (!sScriptMgr->OnTryExecuteCommand(handler, cmdStr))
|
||||
return true;
|
||||
|
||||
/* if we matched a command at some point, invoke it */
|
||||
if (cmd)
|
||||
{ /* if we matched a command at some point, invoke it */
|
||||
{
|
||||
handler.SetSentErrorMessage(false);
|
||||
if (cmd->IsInvokerVisible(handler) && cmd->_invoker(&handler, oldTail))
|
||||
{ /* invocation succeeded, log this */
|
||||
@@ -332,11 +336,6 @@ namespace Acore::Impl::ChatCommands
|
||||
}
|
||||
else if (!handler.HasSentErrorMessage()) /* invocation failed, we should show usage */
|
||||
{
|
||||
if (!sScriptMgr->CanExecuteCommand(handler, cmdStr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
cmd->SendCommandHelp(handler);
|
||||
handler.SetSentErrorMessage(true);
|
||||
}
|
||||
@@ -344,11 +343,6 @@ namespace Acore::Impl::ChatCommands
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sScriptMgr->CanExecuteCommand(handler, cmdStr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ void ScriptMgr::OnHandleDevCommand(Player* player, bool& enable)
|
||||
CALL_ENABLED_HOOKS(AllCommandScript, ALLCOMMANDHOOK_ON_HANDLE_DEV_COMMAND, script->OnHandleDevCommand(player, enable));
|
||||
}
|
||||
|
||||
bool ScriptMgr::CanExecuteCommand(ChatHandler& handler, std::string_view cmdStr)
|
||||
bool ScriptMgr::OnTryExecuteCommand(ChatHandler& handler, std::string_view cmdStr)
|
||||
{
|
||||
CALL_ENABLED_BOOLEAN_HOOKS(AllCommandScript, ALLCOMMANDHOOK_CAN_EXECUTE_COMMAND, !script->CanExecuteCommand(handler, cmdStr));
|
||||
CALL_ENABLED_BOOLEAN_HOOKS(AllCommandScript, ALLCOMMANDHOOK_ON_TRY_EXECUTE_COMMAND, !script->OnTryExecuteCommand(handler, cmdStr));
|
||||
}
|
||||
|
||||
AllCommandScript::AllCommandScript(const char* name, std::vector<uint16> enabledHooks)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
enum AllCommandHook
|
||||
{
|
||||
ALLCOMMANDHOOK_ON_HANDLE_DEV_COMMAND,
|
||||
ALLCOMMANDHOOK_CAN_EXECUTE_COMMAND,
|
||||
ALLCOMMANDHOOK_ON_TRY_EXECUTE_COMMAND,
|
||||
ALLCOMMANDHOOK_END
|
||||
};
|
||||
|
||||
@@ -39,12 +39,12 @@ public:
|
||||
virtual void OnHandleDevCommand(Player* /*player*/, bool& /*enable*/) { }
|
||||
|
||||
/**
|
||||
* @brief This hook runs execute chat command
|
||||
* @brief This hook is triggered when a command is parsed, but before it is executed
|
||||
*
|
||||
* @param handler Contains information about the ChatHandler
|
||||
* @param cmdStr Contains information about the command name
|
||||
*/
|
||||
[[nodiscard]] virtual bool CanExecuteCommand(ChatHandler& /*handler*/, std::string_view /*cmdStr*/) { return true; }
|
||||
[[nodiscard]] virtual bool OnTryExecuteCommand(ChatHandler& /*handler*/, std::string_view /*cmdStr*/) { return true; }
|
||||
};
|
||||
|
||||
// Compatibility for old scripts
|
||||
|
||||
@@ -670,7 +670,7 @@ public: /* MiscScript */
|
||||
public: /* CommandSC */
|
||||
|
||||
void OnHandleDevCommand(Player* player, bool& enable);
|
||||
bool CanExecuteCommand(ChatHandler& handler, std::string_view cmdStr);
|
||||
bool OnTryExecuteCommand(ChatHandler& handler, std::string_view cmdStr);
|
||||
|
||||
public: /* DatabaseScript */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user