feat(Core/Scripts): Optimize AllCommandScript (#18703)

* Add files via upload

* Update AllCommandScript.h
This commit is contained in:
天鹿
2024-04-12 21:59:56 +08:00
committed by GitHub
parent d87af54675
commit a4af83b277
2 changed files with 19 additions and 14 deletions

View File

@@ -21,24 +21,21 @@
void ScriptMgr::OnHandleDevCommand(Player* player, bool& enable)
{
ExecuteScript<AllCommandScript>([&](AllCommandScript* script)
{
script->OnHandleDevCommand(player, enable);
});
CALL_ENABLED_HOOKS(AllCommandScript, ALLCOMMANDHOOK_ON_HANDLE_DEV_COMMAND, script->OnHandleDevCommand(player, enable));
}
bool ScriptMgr::CanExecuteCommand(ChatHandler& handler, std::string_view cmdStr)
{
auto ret = IsValidBoolScript<AllCommandScript>([&](AllCommandScript* script)
{
return !script->CanExecuteCommand(handler, cmdStr);
});
return ReturnValidBool(ret);
CALL_ENABLED_BOOLEAN_HOOKS(AllCommandScript, ALLCOMMANDHOOK_CAN_EXECUTE_COMMAND, !script->CanExecuteCommand(handler, cmdStr));
}
AllCommandScript::AllCommandScript(const char* name)
: ScriptObject(name)
AllCommandScript::AllCommandScript(const char* name, std::vector<uint16> enabledHooks)
: ScriptObject(name, ALLCOMMANDHOOK_END)
{
ScriptRegistry<AllCommandScript>::AddScript(this);
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < ALLCOMMANDHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<AllCommandScript>::AddScript(this, std::move(enabledHooks));
}

View File

@@ -19,11 +19,19 @@
#define SCRIPT_OBJECT_ALL_COMMAND_SCRIPT_H_
#include "ScriptObject.h"
#include <vector>
enum AllCommandHook
{
ALLCOMMANDHOOK_ON_HANDLE_DEV_COMMAND,
ALLCOMMANDHOOK_CAN_EXECUTE_COMMAND,
ALLCOMMANDHOOK_END
};
class AllCommandScript : public ScriptObject
{
protected:
AllCommandScript(const char* name);
AllCommandScript(const char* name, std::vector<uint16> enabledHooks = std::vector<uint16>());
public:
[[nodiscard]] bool IsDatabaseBound() const override { return false; }