refactor: optimize FloatingText

This commit is contained in:
Tsubasa6848
2024-05-28 08:39:32 +08:00
Unverified
parent 8f9447bcdb
commit 32e70d8318
8 changed files with 102 additions and 110 deletions
+23 -22
View File
@@ -19,10 +19,10 @@ void Export_Compatibility_API() {
if (!level) {
return false;
}
return GMLIB::Mod::CustomRecipe::unregisterRecipe(id);
return CustomRecipe::unregisterRecipe(id);
});
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string const& path) -> void {
GMLIB::Mod::CustomPacks::addCustomPackPath(path);
CustomPacks::addCustomPackPath(path);
});
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float {
auto level = GMLIB_Level::getInstance();
@@ -96,70 +96,71 @@ void Export_Compatibility_API() {
"GMLIB_API",
"createFloatingText",
[](std::pair<Vec3, int> pos, std::string const& text, bool papi) -> int {
auto ft = std::make_shared<GMLIB::Server::StaticFloatingText>(text, pos.first, pos.second, papi);
GMLIB::Server::FloatingTextManager::getInstance().add(ft);
auto& manager = FloatingTextManager::getInstance();
auto ft = manager.createStatic(text, pos.first, pos.second, papi);
manager.add(ft);
return ft->getRuntimeID();
}
);
RemoteCall::exportAs("GMLIB_API", "setFloatingTextData", [](int id, std::string const& text) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->setText(text);
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "deleteFloatingText", [](int id) -> bool {
return GMLIB::Server::FloatingTextManager::getInstance().remove(id);
return FloatingTextManager::getInstance().remove(id);
});
RemoteCall::exportAs("GMLIB_API", "sendFloatingTextToPlayer", [](int id, Player* pl) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->sendTo(*pl);
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "sendFloatingText", [](int id) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->sendToClients();
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "removeFloatingTextFromPlayer", [](int id, Player* pl) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->removeFrom(*pl);
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "removeFloatingText", [](int id) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->removeFromClients();
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "updateClientFloatingTextData", [](int id, Player* pl) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->update(*pl);
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "updateAllClientsFloatingTextData", [](int id) -> bool {
if (auto ft = GMLIB::Server::FloatingTextManager::getInstance().getFloatingText(id)) {
if (auto ft = FloatingTextManager::getInstance().getFloatingText(id)) {
ft->updateClients();
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "isVersionMatched", [](int a, int b, int c) -> bool {
auto version = GMLIB::Version(a, b, c, "", "");
auto version = Version(a, b, c, "", "");
return LIB_VERSION >= version;
});
RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); });
RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string {
return GMLIB::Version::getLibVersionString();
return Version::getLibVersionString();
});
RemoteCall::exportAs(
"GMLIB_API",
@@ -555,32 +556,32 @@ void Export_Compatibility_API() {
);
RemoteCall::exportAs("GMLIB_API", "getXuidByUuid", [](std::string const& uuid) -> std::string {
auto uid = mce::UUID::fromString(uuid);
auto result = GMLIB::UserCache::getXuidByUuid(uid);
auto result = UserCache::getXuidByUuid(uid);
return result ? result.value() : "";
});
RemoteCall::exportAs("GMLIB_API", "getNameByUuid", [](std::string const& uuid) -> std::string {
auto uid = mce::UUID::fromString(uuid);
auto result = GMLIB::UserCache::getNameByUuid(uid);
auto result = UserCache::getNameByUuid(uid);
return result ? result.value() : "";
});
RemoteCall::exportAs("GMLIB_API", "getUuidByXuid", [](std::string const& xuid) -> std::string {
auto result = GMLIB::UserCache::getUuidByXuid(xuid);
auto result = UserCache::getUuidByXuid(xuid);
return result ? result.value().asString() : "";
});
RemoteCall::exportAs("GMLIB_API", "getNameByXuid", [](std::string const& xuid) -> std::string {
auto result = GMLIB::UserCache::getNameByXuid(xuid);
auto result = UserCache::getNameByXuid(xuid);
return result ? result.value() : "";
});
RemoteCall::exportAs("GMLIB_API", "getXuidByName", [](std::string const& name) -> std::string {
auto result = GMLIB::UserCache::getXuidByName(name);
auto result = UserCache::getXuidByName(name);
return result ? result.value() : "";
});
RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string {
auto result = GMLIB::UserCache::getUuidByName(name);
auto result = UserCache::getUuidByName(name);
return result ? result.value().asString() : "";
});
RemoteCall::exportAs("GMLIB_API", "getUuidByName", [](std::string const& name) -> std::string {
auto result = GMLIB::UserCache::getUuidByName(name);
auto result = UserCache::getUuidByName(name);
return result ? result.value().asString() : "";
});
RemoteCall::exportAs(
@@ -588,7 +589,7 @@ void Export_Compatibility_API() {
"getAllPlayerInfo",
[]() -> std::vector<std::unordered_map<std::string, std::string>> {
std::vector<std::unordered_map<std::string, std::string>> result;
GMLIB::UserCache::forEach([&result](const GMLIB::UserCache::UserCacheEntry& entry) {
UserCache::forEach([&result](const UserCache::UserCacheEntry& entry) {
std::unordered_map<std::string, std::string> info;
info["Name"] = entry.mName;
info["Xuid"] = entry.mXuid;
+2 -2
View File
@@ -19,7 +19,7 @@ bool LegacyRemoteCallApi::load() {
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
logger.info(
"Loaded Version: {} with {}",
fmt::format(fg(fmt::color::pink), "GMLIB-" + GMLIB::Version::getLibVersionString()),
fmt::format(fg(fmt::color::pink), "GMLIB-" + Version::getLibVersionString()),
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-" + LIB_VERSION.asString())
);
logger.info("Author: GroupMountain");
@@ -33,4 +33,4 @@ bool LegacyRemoteCallApi::disable() { return true; }
} // namespace GMLIB
LL_REGISTER_PLUGIN(GMLIB::LegacyRemoteCallApi, GMLIB::LegacyRemoteCallApi::getInstance());
LL_REGISTER_PLUGIN(LegacyRemoteCallApi, LegacyRemoteCallApi::getInstance());
+20 -20
View File
@@ -16,8 +16,8 @@ void Export_Event_API() {
std::string const& serverXuid,
std::string const& clientXuid
)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::PacketEvent::ClientLoginAfterEvent>(
[Call](GMLIB::Event::PacketEvent::ClientLoginAfterEvent& ev) {
eventBus->emplaceListener<Event::PacketEvent::ClientLoginAfterEvent>(
[Call](Event::PacketEvent::ClientLoginAfterEvent& ev) {
try {
Call(
ev.getRealName(),
@@ -36,8 +36,8 @@ void Export_Event_API() {
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent>(
[Call](GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
eventBus->emplaceListener<Event::LevelEvent::WeatherUpdateBeforeEvent>(
[Call](Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
bool result = true;
try {
result = Call(
@@ -56,8 +56,8 @@ void Export_Event_API() {
}
case doHash("onMobPick"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
eventBus->emplaceListener<Event::EntityEvent::MobPickupItemBeforeEvent>(
[Call](Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self(), (Actor*)&ev.getItemActor());
@@ -72,8 +72,8 @@ void Export_Event_API() {
case doHash("onItemTrySpawn"): {
auto Call = RemoteCall::importAs<
bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnBeforeEvent>(
[Call](Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
auto pos = ev.getPosition();
auto dimid = ev.getBlockSource().getDimensionId().id;
std::pair<Vec3, int> lsePos = {pos, dimid};
@@ -94,8 +94,8 @@ void Export_Event_API() {
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnAfterEvent>(
[Call](Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
auto pos = ev.getPosition();
auto dimid = ev.getBlockSource().getDimensionId().id;
std::pair<Vec3, int> lsePos = {pos, dimid};
@@ -108,8 +108,8 @@ void Export_Event_API() {
}
case doHash("onEntityChangeDim"): {
auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
eventBus->emplaceListener<Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
[Call](Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self(), ev.getToDimensionId());
@@ -123,8 +123,8 @@ void Export_Event_API() {
}
case doHash("onLeaveBed"): {
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
[Call](GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
eventBus->emplaceListener<Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
[Call](Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self());
@@ -142,8 +142,8 @@ void Export_Event_API() {
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::DeathMessageAfterEvent>(
[Call](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) {
eventBus->emplaceListener<Event::EntityEvent::DeathMessageAfterEvent>(
[Call](Event::EntityEvent::DeathMessageAfterEvent& ev) {
auto msg = ev.getDeathMessage();
auto source = ev.getDamageSource();
try {
@@ -158,8 +158,8 @@ void Export_Event_API() {
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobHurtAfterEvent>(
[Call](GMLIB::Event::EntityEvent::MobHurtAfterEvent& ev) {
eventBus->emplaceListener<Event::EntityEvent::MobHurtAfterEvent>(
[Call](Event::EntityEvent::MobHurtAfterEvent& ev) {
auto& damageSource = ev.getSource();
Actor* source = nullptr;
if (damageSource.isEntitySource()) {
@@ -178,8 +178,8 @@ void Export_Event_API() {
}
case doHash("onEndermanTake"): {
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
eventBus->emplaceListener<Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
[Call](Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self());
+5 -1
View File
@@ -3,13 +3,17 @@
#include <RemoteCallAPI.h>
using namespace GMLIB;
using namespace Server;
using namespace Mod;
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
#define LIB_VERSION_MAJOR 0
#define LIB_VERSION_MINOR 12
#define LIB_VERSION_PATCH 7
#define LIB_VERSION GMLIB::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
#define LIB_VERSION Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
extern ll::Logger logger;
+10 -10
View File
@@ -33,7 +33,7 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
}
);
RemoteCall::exportAs(
@@ -56,7 +56,7 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
}
);
RemoteCall::exportAs(
@@ -72,7 +72,7 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
}
);
RemoteCall::exportAs(
@@ -85,7 +85,7 @@ void Export_Legacy_GMLib_ModAPI() {
return;
}
auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
}
);
RemoteCall::exportAs(
@@ -100,7 +100,7 @@ void Export_Legacy_GMLib_ModAPI() {
auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1);
auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
}
);
RemoteCall::exportAs(
@@ -115,7 +115,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) {
return;
}
GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
JsonRecipe::registerSmithingTransformRecipe(
recipe_id,
smithing_template,
base,
@@ -135,7 +135,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) {
return;
}
GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
}
);
RemoteCall::exportAs(
@@ -153,12 +153,12 @@ void Export_Legacy_GMLib_ModAPI() {
}
auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
}
);
// 错误方块清理
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
GMLIB::Mod::VanillaFix::setAutoCleanUnknownBlockEnabled();
VanillaFix::setAutoCleanUnknownBlockEnabled();
});
// 实验性
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
@@ -193,6 +193,6 @@ void Export_Legacy_GMLib_ModAPI() {
return false;
});
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
GMLIB::Mod::VanillaFix::setFixI18nEnabled();
VanillaFix::setFixI18nEnabled();
});
}
+3 -3
View File
@@ -64,13 +64,13 @@ void Export_Legacy_GMLib_ServerAPI() {
"GMLib_ServerAPI",
"addFakeList",
[](const std::string& name, const std::string& xuid) -> bool {
return GMLIB::Server::FakeList::addFakeList(name, xuid, ActorUniqueID(-1));
return FakeList::addFakeList(name, xuid, ActorUniqueID(-1));
}
);
RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool {
return GMLIB::Server::FakeList::removeFakeList(nameOrXuid);
return FakeList::removeFakeList(nameOrXuid);
});
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
return GMLIB::Server::FakeList::removeAllFakeLists();
return FakeList::removeAllFakeLists();
});
}
+12 -12
View File
@@ -13,10 +13,10 @@ bool isParameters(std::string const& str) {
return std::regex_search(removeBrackets(str), reg);
}
std::string GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); }
std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from); }
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
return PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
}
bool registerPlayerPlaceholder(
@@ -30,14 +30,14 @@ bool registerPlayerPlaceholder(
PluginName,
FuncName
);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
PlaceholderAPI::registerPlayerPlaceholder(
PAPIName,
[Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
PluginName
);
} else {
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
PlaceholderAPI::registerPlayerPlaceholder(
PAPIName,
[Call](Player* sp) { return Call(sp); },
PluginName
@@ -57,14 +57,14 @@ bool registerServerPlaceholder(
if (isParameters(PAPIName)) {
auto Call =
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
PlaceholderAPI::registerServerPlaceholder(
PAPIName,
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
PluginName
);
} else {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
}
return true;
}
@@ -81,13 +81,13 @@ bool registerStaticPlaceholder(
if (isParameters(PAPIName)) {
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
if (num == -1) {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
[Call] { return Call(); },
PluginName
);
} else {
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
PlaceholderAPI::registerStaticPlaceholder(
PAPIName,
num,
[Call] { return Call(); },
@@ -101,14 +101,14 @@ bool registerStaticPlaceholder(
}
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
return GMLIB::Server::PlaceholderAPI::translateString(str, pl);
return PlaceholderAPI::translateString(str, pl);
}
std::string translateString(std::string const& str) { return GMLIB::Server::PlaceholderAPI::translateString(str); }
std::string translateString(std::string const& str) { return PlaceholderAPI::translateString(str); }
bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unregisterPlaceholder(str); }
bool unRegisterPlaceholder(std::string const& str) { return PlaceholderAPI::unregisterPlaceholder(str); }
std::vector<std::string> getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); }
std::vector<std::string> getAllPAPI() { return PlaceholderAPI::getAllPAPI(); }
} // namespace PAPIRemoteCall