forked from mirrors/kolyah35-minecraft-pe-0.6.1
1
This commit is contained in:
parent
c62daa9c1c
commit
d9dfff3339
6 changed files with 113 additions and 32 deletions
|
|
@ -8,7 +8,7 @@
|
|||
namespace fs = std::filesystem;
|
||||
|
||||
void PluginsManager::init(Minecraft& minecraft) {
|
||||
m_lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string, sol::lib::math, sol::lib::table);
|
||||
m_lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string, sol::lib::math, sol::lib::table, sol::lib::io);
|
||||
registerTypes();
|
||||
|
||||
m_minecraft = &minecraft;
|
||||
|
|
@ -19,10 +19,13 @@ void PluginsManager::registerTypes() {
|
|||
// m_lua.set_function("subscribe", &PluginsManager::subscribe);
|
||||
|
||||
m_lua.set_function("subscribe", [this](std::string event, sol::protected_function func) {
|
||||
// @note: why the .at() not working?
|
||||
m_callbacks[event].push_back(func);
|
||||
});
|
||||
|
||||
|
||||
m_lua.set_function("addCommand", [this](std::string commandName, sol::function func) {
|
||||
m_luaCommands[commandName].push_back(func);
|
||||
});
|
||||
|
||||
m_lua.new_usertype<LuaServer>(
|
||||
"Server",
|
||||
"sendMessage", &LuaServer::sendServerMessage
|
||||
|
|
@ -31,9 +34,10 @@ void PluginsManager::registerTypes() {
|
|||
m_lua.new_usertype<LuaPlayer>(
|
||||
"Player",
|
||||
"getNickname", &LuaPlayer::getNickname,
|
||||
"getX", &LuaPlayer::getX,
|
||||
"getY", &LuaPlayer::getY,
|
||||
"getZ", &LuaPlayer::getZ
|
||||
"getPos", &LuaPlayer::getPos,
|
||||
"setPos", &LuaPlayer::setPos,
|
||||
"sendMessage", &LuaPlayer::sendMessage,
|
||||
"getInventory", &LuaPlayer::getInventory
|
||||
);
|
||||
|
||||
m_lua["Server"] = &m_srv;
|
||||
|
|
@ -42,7 +46,13 @@ void PluginsManager::registerTypes() {
|
|||
void PluginsManager::loadPlugins() {
|
||||
std::string path = "plugins/";
|
||||
|
||||
for (const auto & entry : fs::directory_iterator(path)) {
|
||||
m_lua.script_file(entry.path().string());
|
||||
if (fs::exists(path)) {
|
||||
for (const auto& entry : fs::directory_iterator(path)) {
|
||||
if (!fs::is_directory(entry.path().string())) {
|
||||
m_lua.script_file(entry.path().string());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::filesystem::create_directory(path);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue