This commit is contained in:
2026-07-20 14:49:38 +02:00
parent f7ad5acd33
commit 6f1ca8fc3b
7 changed files with 104 additions and 9 deletions

View File

@@ -186,7 +186,8 @@ Minecraft::Minecraft() :
commandPort(4711),
reserved_d1(0),reserved_d2(0),
reserved_f1(0),reserved_f2(0), options(this),
m_commandManager()
m_commandManager(),
m_pluginsManager(*level)
{
//#ifdef ANDROID

View File

@@ -3,6 +3,8 @@
#include "Options.h"
#include "commands/CommandManager.hpp"
#include <plugins/PluginsManager.hpp>
#ifndef STANDALONE_SERVER
#include "MouseHandler.h"
#include "gui/Gui.h"
@@ -243,6 +245,8 @@ private:
CommandServer* _commandServer;
CommandManager m_commandManager;
PluginsManager m_pluginsManager;
};
#endif /*NET_MINECRAFT_CLIENT__Minecraft_H__*/

View File

@@ -15,6 +15,7 @@
#include "platform/time.h"
#include "SharedConstants.h"
#include "world/level/LevelConstants.h"
#include <sol/sol.hpp>
#define MAIN_CLASS NinecraftApp
static App* g_app = 0;
@@ -64,7 +65,6 @@ std::string findStringInConfig(std::string line, std::string config) {
return valueStr;
}
int main(int numArguments, char* pszArgs[]) {
std::ifstream serverProperties("server.properties");
@@ -148,7 +148,7 @@ int main(int numArguments, char* pszArgs[]) {
}
printf("Level Name: %s\n", levelName.c_str());
AppContext appContext;
appContext.platform = new AppPlatform();
App* app = new MAIN_CLASS();
@@ -201,6 +201,15 @@ int main(int numArguments, char* pszArgs[]) {
}
}
std::string pluginsFolder = "plugins/";
struct stat sb;
if (stat(pluginsFolder.c_str(), &sb) == 0) {
} else {
}
std::cout << "Level has been generated in " << getTimeS() - startTime << std::endl;
((MAIN_CLASS*)g_app)->level->saveLevelData();
std::cout << "Level has been saved!" << std::endl;

View File

@@ -226,7 +226,6 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
std::string nicknameLower = packet->clientName.C_String();
std::transform(nicknameLower.begin(), nicknameLower.end(), nicknameLower.begin(), ::tolower);
printf("%s lower \n", nicknameLower.c_str());
for (int i = 0; i < level->players.size(); i++) {
ServerPlayer* player = (ServerPlayer*) level->players.at(i);
@@ -306,8 +305,6 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ReadyPac
if (packet->type == ReadyPacket::READY_REQUESTEDCHUNKS)
onReady_RequestedChunks(source);
LOGI("Ready player two ready ready player two!!\n ");
}
void ServerSideNetworkHandler::onReady_ClientGeneration(const RakNet::RakNetGUID& source)

View File

@@ -0,0 +1,16 @@
#include <plugins/PluginsManager.hpp>
#include <world/level/Level.h>
PluginsManager::PluginsManager(Level& level) : m_level(level) {
m_lua.open_libraries(sol::lib::base);
registerTypes();
}
void PluginsManager::registerTypes() {
m_lua.set_function("subscribe", &PluginsManager::subscribe);
}
void PluginsManager::subscribe(std::string event, sol::function function) {
m_callbacks.at(event).push_back(function);
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include <unordered_map>
#include <sol/sol.hpp>
#include <vector>
class Level;
class PluginsManager {
public:
PluginsManager(Level& level);
void registerTypes();
void subscribe(std::string event, sol::function function);
private:
std::unordered_map<std::string, std::vector<sol::function>> m_callbacks;
sol::state m_lua;
Level& m_level;
};