diff --git a/src/MyPlayer.cpp b/src/MyPlayer.cpp index 6ced314..842bc4f 100644 --- a/src/MyPlayer.cpp +++ b/src/MyPlayer.cpp @@ -2,31 +2,67 @@ * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 */ -#include "ScriptMgr.h" -#include "Player.h" -#include "Config.h" #include "Chat.h" +#include "ConfigValueCache.h" +#include "Player.h" +#include "ScriptMgr.h" enum MyPlayerAcoreString { HELLO_WORLD = 35410 }; +enum class MyConfig +{ + ENABLED, + + NUM_CONFIGS, +}; + +class MyConfigData : public ConfigValueCache +{ +public: + MyConfigData() : ConfigValueCache(MyConfig::NUM_CONFIGS) { }; + + void BuildConfigCache() override + { + SetConfigValue(MyConfig::ENABLED, "MyModule.Enable", true); + } +}; + +static MyConfigData myConfigData; + // Add player scripts class MyPlayer : public PlayerScript { public: - MyPlayer() : PlayerScript("MyPlayer") { } + MyPlayer() : PlayerScript("MyPlayer", { + PLAYERHOOK_ON_LOGIN + }) { } void OnPlayerLogin(Player* player) override { - if (sConfigMgr->GetOption("MyModule.Enable", false)) + if (myConfigData.GetConfigValue(MyConfig::ENABLED)) ChatHandler(player->GetSession()).PSendSysMessage(HELLO_WORLD); } }; +class MyWorldScript : public WorldScript +{ +public: + MyWorldScript() : WorldScript("MyWorldScript", { + WORLDHOOK_ON_BEFORE_CONFIG_LOAD + }) { } + + void OnBeforeConfigLoad(bool reload) override + { + myConfigData.Initialize(reload); + } +}; + // Add all scripts in one void AddMyPlayerScripts() { new MyPlayer(); + new MyWorldScript(); }