fix: fix crash before ServerStarted
This commit is contained in:
@@ -2,13 +2,25 @@
|
||||
|
||||
void Export_Compatibility_API() {
|
||||
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float {
|
||||
return GMLIB_Level::getLevel()->getServerMspt();
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return 0.0f;
|
||||
}
|
||||
return level->getServerMspt();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float {
|
||||
return GMLIB_Level::getLevel()->getServerCurrentTps();
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return 0.0f;
|
||||
}
|
||||
return level->getServerCurrentTps();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> float {
|
||||
return GMLIB_Level::getLevel()->getServerAverageTps();
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return 0.0f;
|
||||
}
|
||||
return level->getServerAverageTps();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
|
||||
return GMLIB_Player::getAllUuids();
|
||||
|
||||
@@ -23,6 +23,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string result,
|
||||
int count,
|
||||
std::string unlock) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
std::vector<RecipeIngredient> types;
|
||||
for (auto ing : ingredients) {
|
||||
auto key = RecipeIngredient(ing, 0, 1);
|
||||
@@ -42,6 +46,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string result,
|
||||
int count,
|
||||
std::string unlock) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
std::vector<RecipeIngredient> types;
|
||||
for (auto ing : ingredients) {
|
||||
auto key = RecipeIngredient(ing, 0, 1);
|
||||
@@ -56,6 +64,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"GMLib_ModAPI",
|
||||
"registerFurnaceRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::vector<std::string> tags) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
|
||||
@@ -65,6 +77,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"GMLib_ModAPI",
|
||||
"registerBrewingMixRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
|
||||
}
|
||||
@@ -73,6 +89,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"GMLib_ModAPI",
|
||||
"registerBrewingContainerRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
@@ -87,6 +107,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string base,
|
||||
std::string addition,
|
||||
std::string result) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
@@ -100,6 +124,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"GMLib_ModAPI",
|
||||
"registerSmithingTrimRecipe",
|
||||
[](std::string recipe_id, std::string smithing_template, std::string base, std::string addition) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
GMLIB::Mod::CustomRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
|
||||
}
|
||||
);
|
||||
@@ -112,6 +140,10 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string output,
|
||||
int output_data,
|
||||
int output_count) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
GMLIB::Mod::CustomRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
|
||||
@@ -130,11 +162,19 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
if (ExperimentsList.count(experiment_id)) {
|
||||
GMLIB_Level::getLevel()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
||||
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return false;
|
||||
}
|
||||
if (ExperimentsList.count(experiment_id)) {
|
||||
return GMLIB_Level::getLevel()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
} else {
|
||||
|
||||
+50
-32
@@ -1,49 +1,67 @@
|
||||
#include "Global.h"
|
||||
|
||||
void Export_Legacy_GMLib_ServerAPI() {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
||||
GMLIB_Level::addEducationEditionRequired();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
||||
GMLIB_Level::forceEnableAbilityCommand();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "addFloatingTextPacket", [](std::string text, std::pair<Vec3, int> pos, int dimid) -> int {
|
||||
auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second);
|
||||
return ft->getRuntimeID();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "deleteFloatingTextPacket", [](int id) -> void {
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"addFloatingTextPacket",
|
||||
[](std::string text, std::pair<Vec3, int> pos, int dimid) -> int {
|
||||
auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second);
|
||||
return ft->getRuntimeID();
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "deleteFloatingTextPacket", [](int id) -> void {
|
||||
GMLIB::Server::FloatingText::deleteFloatingText(id);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
||||
GMLIB_Level::setForceAchievementsEnabled();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void {
|
||||
GMLIB_Level::setForceTrustSkin();
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::setForceTrustSkin(); });
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { GMLIB_Level::setCoResourcePack(); });
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return "";
|
||||
}
|
||||
return level->getLevelName();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
|
||||
GMLIB_Level::setCoResourcePack();
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
return level->setLevelName(name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||
return GMLIB_Level::getLevel()->getLevelName();
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
return level->setFakeSeed(seed);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void {
|
||||
GMLIB_Level::getLevel()->setLevelName(name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
||||
GMLIB_Level::getLevel()->setFakeSeed(seed);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair<Vec3, int> pos, std::string name) -> Actor* {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair<Vec3, int> pos, std::string name) -> Actor* {
|
||||
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "shootProjectile", [](Actor* owner, std::string name, float speed, float offset) -> Actor* {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
return ac->shootProjectile(name, speed, offset);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "throwEntity", [](Actor* owner, Actor* actor, float speed, float offset) -> bool {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
return ac->throwEntity(actor, speed, offset);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* {
|
||||
return (Actor*)player;
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"shootProjectile",
|
||||
[](Actor* owner, std::string name, float speed, float offset) -> Actor* {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
return ac->shootProjectile(name, speed, offset);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"throwEntity",
|
||||
[](Actor* owner, Actor* actor, float speed, float offset) -> bool {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
return ac->throwEntity(actor, speed, offset);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { return (Actor*)player; });
|
||||
}
|
||||
Reference in New Issue
Block a user