Skip to content

Commit 31e1706

Browse files
committed
fix: fix #94
1 parent 412363e commit 31e1706

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

src/legacy/api/MoreGlobal.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
#include "mc/world/level/storage/DBStorage.h"
55
#include "mc/world/level/storage/DBStorageConfig.h"
66

7+
DBStorage* MoreGlobal::db;
8+
79
LL_TYPE_INSTANCE_HOOK(
810
DBStorageHook,
911
HookPriority::Normal,
1012
DBStorage,
1113
"??0DBStorage@@QEAA@UDBStorageConfig@@V?$not_null@V?$NonOwnerPointer@VLevelDbEnv@@@Bedrock@@@gsl@@@Z",
12-
DBStorage,
14+
DBStorage*,
1315
struct DBStorageConfig& cfg,
1416
Bedrock::NotNullNonOwnerPtr<class LevelDbEnv>& dbEnv
1517
) {
16-
DBStorage ori = origin(cfg, dbEnv);
17-
MoreGlobal::setDBStorage(&ori);
18+
DBStorage* ori = origin(cfg, dbEnv);
19+
MoreGlobal::db = ori;
1820
return ori;
1921
};
2022

2123
void MoreGlobal::Init() { DBStorageHook::hook(); }
22-
23-
DBStorage* MoreGlobal::db = nullptr;

src/legacy/api/MoreGlobal.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
class DBStorage;
2-
class MoreGlobal {
3-
private:
4-
static DBStorage* db;
5-
6-
public:
7-
static void Init();
8-
static DBStorage* getDBStorage() { return db; };
9-
static void setDBStorage(DBStorage* dbs) { db = dbs; };
10-
};
2+
namespace MoreGlobal {
3+
extern DBStorage* db;
4+
extern void Init();
5+
}; // namespace MoreGlobal

src/legacy/api/PlayerAPI.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,28 +330,32 @@ Local<Value> McClass::getPlayerNbt(const Arguments& args) {
330330
CHECK_ARGS_COUNT(args, 1);
331331
CHECK_ARG_TYPE(args[0], ValueKind::kString);
332332
try {
333-
auto uuid = mce::UUID::fromString(args[0].asString().toString());
334-
CompoundTag* tag = new CompoundTag();
335-
Player* player = ll::service::getLevel()->getPlayer(uuid);
333+
auto uuid = mce::UUID::fromString(args[0].asString().toString());
334+
std::unique_ptr<CompoundTag> tag = std::make_unique<CompoundTag>();
335+
Player* player = ll::service::getLevel()->getPlayer(uuid);
336336
if (player) {
337337
player->save(*tag);
338338
} else {
339-
DBStorage* db = MoreGlobal::getDBStorage();
339+
DBStorage* db = MoreGlobal::db;
340340
if (db) {
341-
auto tagPtr = db->loadPlayerDataFromTag(uuid.asString());
342-
if (tagPtr) {
343-
tag = std::move(tagPtr.get());
341+
if (db->hasKey("player_" + uuid.asString(), DBHelpers::Category::Player)) {
342+
std::unique_ptr<CompoundTag> playerTag =
343+
db->getCompoundTag("player_" + uuid.asString(), DBHelpers::Category::Player);
344+
if (playerTag) {
345+
std::string serverId = playerTag->at("ServerId");
346+
if (!serverId.empty()) {
347+
if (db->hasKey(serverId, DBHelpers::Category::Player)) {
348+
tag = db->getCompoundTag(serverId, DBHelpers::Category::Player);
349+
}
350+
}
351+
}
344352
}
345-
} else {
346-
return Local<Value>();
347353
}
348354
}
349-
350-
if (!tag->isEmpty()) {
351-
return NbtCompoundClass::pack(tag);
352-
} else {
353-
return Local<Value>();
355+
if (tag && !tag->isEmpty()) {
356+
return NbtCompoundClass::pack(std::move(tag));
354357
}
358+
return Local<Value>();
355359
}
356360
CATCH("Fail in getPlayerNbt!")
357361
}

xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ add_requires(
99
"legacymoney 0.5.0",
1010
"legacyparticleapi 0.5.0",
1111
"legacyremotecall 0.5.0",
12-
"levilamina 0.10.2",
12+
"levilamina 0.10.5",
1313
"lightwebsocketclient",
1414
"magic_enum",
1515
"nlohmann_json",

0 commit comments

Comments
 (0)