summaryrefslogtreecommitdiffstats
path: root/src/Plugin.cpp
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-07-04 14:21:50 +0200
committerLaG1924 <lag1924@gmail.com>2021-07-04 14:21:50 +0200
commitb37e52c9facd4c41183c016fd5c91f8829407766 (patch)
tree7672459f9480a7b4cb0d95cdf09823d5072746fa /src/Plugin.cpp
parentAdded RmlDebugger (diff)
downloadAltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.gz
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.bz2
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.lz
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.xz
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.zst
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.zip
Diffstat (limited to 'src/Plugin.cpp')
-rw-r--r--src/Plugin.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Plugin.cpp b/src/Plugin.cpp
index 64fc00b..98df8c3 100644
--- a/src/Plugin.cpp
+++ b/src/Plugin.cpp
@@ -12,6 +12,7 @@
#include "AssetManager.hpp"
#include "Settings.hpp"
#include "DebugInfo.hpp"
+#include "Chat.hpp"
struct Plugin {
@@ -23,6 +24,7 @@ struct Plugin {
const std::function<void(std::string)> onChangeState;
const std::function<void(double)> onTick;
const std::function<BlockInfo(Vector)> onRequestBlockInfo;
+ const std::function<void(Chat, int)> onChatMessage;
};
@@ -42,6 +44,7 @@ namespace PluginApi {
plugin["onChangeState"].get_or(std::function<void(std::string)>()),
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)>()),
};
plugins.push_back(nativePlugin);
LOG(INFO)<<"Loading plugin " << (!nativePlugin.displayName.empty() ? nativePlugin.displayName : nativePlugin.name);
@@ -128,6 +131,10 @@ namespace PluginApi {
return 0;
}
}
+
+ void SendChatMessage(const std::string& msg) {
+ PUSH_EVENT("SendChatMessage", msg);
+ }
}
int LoadFileRequire(lua_State* L) {
@@ -265,6 +272,9 @@ void PluginSystem::Init() {
"GetDeltaS", &LoopExecutionTimeController::GetDeltaS,
"GetRealDeltaS", &LoopExecutionTimeController::GetRealDeltaS);
+ lua.new_usertype<Chat>("Chat",
+ "ToPlainText", &Chat::ToPlainText);
+
sol::table apiTable = lua["AC"].get_or_create<sol::table>();
sol::table apiSettings = lua["AC"]["Settings"].get_or_create<sol::table>();
@@ -293,6 +303,7 @@ void PluginSystem::Init() {
apiTable["GetTime"] = GetTime;
apiTable["GetBlockInfo"] = GetBlockInfo;
apiTable["GetDebugValue"] = PluginApi::GetDebugValue;
+ apiTable["SendChatMessage"] = PluginApi::SendChatMessage;
}
lua_State* PluginSystem::GetLuaState() {
@@ -356,3 +367,17 @@ BlockInfo PluginSystem::RequestBlockInfo(Vector blockPos) {
}
return ret;
}
+
+void PluginSystem::CallOnChatMessage(const Chat& chat, int position) {
+ OPTICK_EVENT();
+ for (Plugin& plugin : plugins) {
+ if (plugin.onRequestBlockInfo && plugin.errors < 10)
+ try {
+ plugin.onChatMessage(chat, position);
+ }
+ catch (sol::error& e) {
+ LOG(ERROR) << e.what();
+ plugin.errors++;
+ }
+ }
+}