mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
Make PluginMonitor not try to run non-lua files
This commit is contained in:
parent
6c3174ac08
commit
10ea0cf59e
@ -57,21 +57,26 @@ void TPluginMonitor::operator()() {
|
|||||||
mFileTimes[Pair.first] = CurrentTime;
|
mFileTimes[Pair.first] = CurrentTime;
|
||||||
// grandparent of the path should be Resources/Server
|
// grandparent of the path should be Resources/Server
|
||||||
if (fs::equivalent(fs::path(Pair.first).parent_path().parent_path(), mPath)) {
|
if (fs::equivalent(fs::path(Pair.first).parent_path().parent_path(), mPath)) {
|
||||||
beammp_infof("File \"{}\" changed, reloading", Pair.first);
|
if (fs::path(Pair.first).extension() == ".lua") {
|
||||||
// is in root folder, so reload
|
beammp_infof("File \"{}\" changed, reloading", Pair.first);
|
||||||
std::ifstream FileStream(Pair.first, std::ios::in | std::ios::binary);
|
// is in root folder, so reload
|
||||||
auto Size = std::filesystem::file_size(Pair.first);
|
std::ifstream FileStream(Pair.first, std::ios::in | std::ios::binary);
|
||||||
auto Contents = std::make_shared<std::string>();
|
auto Size = std::filesystem::file_size(Pair.first);
|
||||||
Contents->resize(Size);
|
auto Contents = std::make_shared<std::string>();
|
||||||
FileStream.read(Contents->data(), Contents->size());
|
Contents->resize(Size);
|
||||||
TLuaChunk Chunk(Contents, Pair.first, fs::path(Pair.first).parent_path().string());
|
FileStream.read(Contents->data(), Contents->size());
|
||||||
auto StateID = mEngine->GetStateIDForPlugin(fs::path(Pair.first).parent_path());
|
TLuaChunk Chunk(Contents, Pair.first, fs::path(Pair.first).parent_path().string());
|
||||||
auto Res = mEngine->EnqueueScript(StateID, Chunk);
|
auto StateID = mEngine->GetStateIDForPlugin(fs::path(Pair.first).parent_path());
|
||||||
Res->WaitUntilReady();
|
auto Res = mEngine->EnqueueScript(StateID, Chunk);
|
||||||
if (Res->Error) {
|
Res->WaitUntilReady();
|
||||||
beammp_lua_errorf("Error while hot-reloading \"{}\": {}", Pair.first, Res->ErrorMessage);
|
if (Res->Error) {
|
||||||
|
beammp_lua_errorf("Error while hot-reloading \"{}\": {}", Pair.first, Res->ErrorMessage);
|
||||||
|
} else {
|
||||||
|
mEngine->ReportErrors(mEngine->TriggerLocalEvent(StateID, "onInit"));
|
||||||
|
mEngine->ReportErrors(mEngine->TriggerEvent("onFileChanged", "", Pair.first));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mEngine->ReportErrors(mEngine->TriggerLocalEvent(StateID, "onInit"));
|
beammp_debugf("File \"{}\" changed, not reloading because it's not a lua file. Triggering 'onFileChanged' event instead", Pair.first);
|
||||||
mEngine->ReportErrors(mEngine->TriggerEvent("onFileChanged", "", Pair.first));
|
mEngine->ReportErrors(mEngine->TriggerEvent("onFileChanged", "", Pair.first));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user