login plugin works yoy
This commit is contained in:
@@ -7,6 +7,42 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int PluginsManager::emitCommands(std::string command, const RakNet::RakNetGUID& source) {
|
||||
std::vector<std::string> args;
|
||||
std::string cmd;
|
||||
|
||||
int i = 0;
|
||||
std::string word;
|
||||
std::stringstream ss(command);
|
||||
|
||||
while (ss >> word) {
|
||||
if (i == 0) {
|
||||
cmd = word;
|
||||
} else {
|
||||
args.push_back(word);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
std::cout << cmd << " " << " ff" << std::endl;
|
||||
|
||||
auto it = m_luaCommands.find(cmd);
|
||||
|
||||
if (it == m_luaCommands.end()) return 1;
|
||||
|
||||
for (auto& callback : it->second) {
|
||||
sol::protected_function_result result = callback(LuaPlayer(source), sol::as_table(args));
|
||||
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
std::cout << err.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PluginsManager::init(Minecraft& minecraft) {
|
||||
m_lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string, sol::lib::math, sol::lib::table, sol::lib::io);
|
||||
registerTypes();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <plugins/LuaServer.hpp>
|
||||
#include <raknet/RakNetTypes.h>
|
||||
|
||||
class Minecraft;
|
||||
|
||||
@@ -42,23 +43,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
int emitCommands(std::string event, Args&&... args) {
|
||||
auto it = m_luaCommands.find(event);
|
||||
|
||||
if (it == m_luaCommands.end()) return 1;
|
||||
|
||||
for (auto& callback : it->second) {
|
||||
sol::protected_function_result result = callback(std::forward<Args>(args)...);
|
||||
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
std::cout << err.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int emitCommands(std::string command, const RakNet::RakNetGUID& source);
|
||||
|
||||
Minecraft* getMinecraft() { return m_minecraft; }
|
||||
private:
|
||||
std::unordered_map<std::string, std::vector<sol::function>> m_callbacks;
|
||||
|
||||
Reference in New Issue
Block a user