Merge pull request #374 from Karrz1/hook-after-reload

Scripts: hook after a .reload command
This commit is contained in:
Karrz1
2026-11-20 07:56:06 +00:00
committed by GitHub
3 changed files with 24 additions and 0 deletions
@@ -257,6 +257,7 @@ namespace Trinity::Impl::ChatCommands
{
ChatCommandNode const* cmd = nullptr;
ChatSubCommandMap const* map = &GetTopLevelMap();
std::string path; // full names of the matched commands, e.g. "reload all quest"
while (!cmdStr.empty() && (cmdStr.front() == COMMAND_DELIMITER))
cmdStr.remove_prefix(1);
@@ -297,6 +298,9 @@ namespace Trinity::Impl::ChatCommands
/* now we matched exactly one subcommand, and it1 points to it; go down the rabbit hole */
cmd = &it1->second;
map = &cmd->_subCommands;
if (!path.empty())
path += COMMAND_DELIMITER;
path += it1->first;
oldTail = newTail;
}
@@ -308,6 +312,10 @@ namespace Trinity::Impl::ChatCommands
{ /* invocation succeeded, log this */
if (!handler.IsConsole())
LogCommandUsage(*handler.GetSession(), cmd->_permission.RequiredPermission, cmdStr);
// let modules refresh what they cached after any successful .reload
if (StringEqualI(std::string_view(path).substr(0, path.find(COMMAND_DELIMITER)), "reload"))
sScriptMgr->OnAfterReload(path);
}
else if (!handler.HasSentErrorMessage())
{ /* invocation failed, we should show usage */
+9
View File
@@ -1992,6 +1992,11 @@ bool ScriptMgr::CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId
return allowed;
}
void ScriptMgr::OnAfterReload(std::string_view command)
{
FOREACH_SCRIPT(WorldScript)->OnAfterReload(command);
}
// Achievement
void ScriptMgr::OnAchievementCompleted(Player* player, AchievementEntry const* achievement)
{
@@ -2630,6 +2635,10 @@ bool WorldScript::CanCreateBattleground(uint32 /*battlemasterListId*/, uint8 /*b
return true;
}
void WorldScript::OnAfterReload(std::string_view /*command*/)
{
}
FormulaScript::FormulaScript(char const* name) noexcept
: ScriptObject(name)
{
+7
View File
@@ -23,6 +23,7 @@
#include "Tuples.h"
#include <boost/preprocessor/punctuation/remove_parens.hpp>
#include <memory>
#include <string_view>
#include <vector>
class AccountMgr;
@@ -287,6 +288,11 @@ class TC_GAME_API WorldScript : public ScriptObject
// Called before a battleground queue opens a new (non arena) instance; return false to hold it for now.
virtual bool CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId);
// Called after a .reload command (in game, console or remote) finished without error, with the
// full command path, e.g. "reload config", "reload creature_template", "reload all quest".
// Lets modules refresh what they cached from the reloaded config or tables.
virtual void OnAfterReload(std::string_view command);
};
class TC_GAME_API FormulaScript : public ScriptObject
@@ -1201,6 +1207,7 @@ class TC_GAME_API ScriptMgr
void OnStartup();
void OnShutdown();
bool CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId);
void OnAfterReload(std::string_view command);
public: /* FormulaScript */