From 28cda3a34c85a35be2e1e4fa35b10fae5d0956d7 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Mon, 5 Jul 2021 18:36:28 +0500 Subject: Added disconnect messages --- src/Plugin.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/Plugin.cpp') 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 onTick; const std::function onRequestBlockInfo; const std::function onChatMessage; + const std::function onDisconnected; }; @@ -45,6 +46,7 @@ namespace PluginApi { plugin["onTick"].get_or(std::function()), plugin["onRequestBlockInfo"].get_or(std::function()), plugin["onChatMessage"].get_or(std::function()), + plugin["onDisconnected"].get_or(std::function()), }; 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++; + } + } +} -- cgit v1.2.3