diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2021-07-06 15:00:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 15:00:50 +0200 |
commit | 4354b1b85b92e378ac0ea7c542edc033c6abdaff (patch) | |
tree | 4e2fa2a75f76778b1982a84c5a17d8d8744dd078 /src/Plugin.cpp | |
parent | Merge pull request #66 from LaG1924/ftr/more-rmlui (diff) | |
parent | Added disconnect messages (diff) | |
download | AltCraft-build-3.tar AltCraft-build-3.tar.gz AltCraft-build-3.tar.bz2 AltCraft-build-3.tar.lz AltCraft-build-3.tar.xz AltCraft-build-3.tar.zst AltCraft-build-3.zip |
Diffstat (limited to 'src/Plugin.cpp')
-rw-r--r-- | src/Plugin.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 98df8c3..3e06b0c 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -25,6 +25,7 @@ struct Plugin { const std::function<void(double)> onTick; const std::function<BlockInfo(Vector)> onRequestBlockInfo; const std::function<void(Chat, int)> onChatMessage; + const std::function<void(std::string)> onDisconnected; }; @@ -45,6 +46,7 @@ namespace PluginApi { plugin["onTick"].get_or(std::function<void(double)>()), plugin["onRequestBlockInfo"].get_or(std::function<BlockInfo(Vector)>()), plugin["onChatMessage"].get_or(std::function<void(Chat, int)>()), + plugin["onDisconnected"].get_or(std::function<void(std::string)>()), }; plugins.push_back(nativePlugin); LOG(INFO)<<"Loading plugin " << (!nativePlugin.displayName.empty() ? nativePlugin.displayName : nativePlugin.name); @@ -371,7 +373,7 @@ BlockInfo PluginSystem::RequestBlockInfo(Vector blockPos) { void PluginSystem::CallOnChatMessage(const Chat& chat, int position) { OPTICK_EVENT(); for (Plugin& plugin : plugins) { - if (plugin.onRequestBlockInfo && plugin.errors < 10) + if (plugin.errors < 10) try { plugin.onChatMessage(chat, position); } @@ -381,3 +383,17 @@ void PluginSystem::CallOnChatMessage(const Chat& chat, int position) { } } } + +void PluginSystem::CallOnDisconnected(const std::string &reason) { + OPTICK_EVENT(); + for (Plugin& plugin : plugins) { + if (plugin.errors < 10) + try { + plugin.onDisconnected(reason); + } + catch (sol::error& e) { + LOG(ERROR) << e.what(); + plugin.errors++; + } + } +} |