Skip to content

Commit 599c0a6

Browse files
committed
Merge branch 'main' into develop
2 parents 09f617a + cb0537e commit 599c0a6

File tree

11 files changed

+63
-38
lines changed

11 files changed

+63
-38
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.4] - 2024-04-08
9+
10+
### Fixed
11+
12+
- Fix getPlayerNbt [#94]
13+
- Fix offline setPlayerNbt
14+
815
## [0.5.3] - 2024-04-05
916

1017
### Fixed
@@ -240,7 +247,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
240247
[#82]: https://github.com/LiteLDev/LegacyScriptEngine/issues/82
241248
[#91]: https://github.com/LiteLDev/LegacyScriptEngine/issues/91
242249
[#92]: https://github.com/LiteLDev/LegacyScriptEngine/issues/92
250+
[#94]: https://github.com/LiteLDev/LegacyScriptEngine/issues/94
243251

252+
[0.5.4]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.5.3...v0.5.4
244253
[0.5.3]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.5.2...v0.5.3
245254
[0.5.2]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.5.1...v0.5.2
246255
[0.5.1]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.4.15...v0.5.1

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "native",
55
"description": "A plugin engine for running LLSE plugins on LeviLamina",
66
"author": "LiteLDev",
7-
"version": "0.5.3",
7+
"version": "0.5.4",
88
"dependencies": [
99
{
1010
"name": "LegacyMoney"

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: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "mc/enums/MinecraftPacketIds.h"
3838
#include "mc/enums/ScorePacketType.h"
3939
#include "mc/enums/TextPacketType.h"
40+
#include "mc/enums/d_b_helpers/Category.h"
4041
#include "mc/nbt/ListTag.h"
4142
#include "mc/network/ConnectionRequest.h"
4243
#include "mc/network/MinecraftPackets.h"
@@ -330,28 +331,32 @@ Local<Value> McClass::getPlayerNbt(const Arguments& args) {
330331
CHECK_ARGS_COUNT(args, 1);
331332
CHECK_ARG_TYPE(args[0], ValueKind::kString);
332333
try {
333-
auto uuid = mce::UUID::fromString(args[0].asString().toString());
334-
CompoundTag* tag = new CompoundTag();
335-
Player* player = ll::service::getLevel()->getPlayer(uuid);
334+
auto uuid = mce::UUID::fromString(args[0].asString().toString());
335+
std::unique_ptr<CompoundTag> tag = std::make_unique<CompoundTag>();
336+
Player* player = ll::service::getLevel()->getPlayer(uuid);
336337
if (player) {
337338
player->save(*tag);
338339
} else {
339-
DBStorage* db = MoreGlobal::getDBStorage();
340+
DBStorage* db = MoreGlobal::db;
340341
if (db) {
341-
auto tagPtr = db->loadPlayerDataFromTag(uuid.asString());
342-
if (tagPtr) {
343-
tag = std::move(tagPtr.get());
342+
if (db->hasKey("player_" + uuid.asString(), DBHelpers::Category::Player)) {
343+
std::unique_ptr<CompoundTag> playerTag =
344+
db->getCompoundTag("player_" + uuid.asString(), DBHelpers::Category::Player);
345+
if (playerTag) {
346+
std::string serverId = playerTag->at("ServerId");
347+
if (!serverId.empty()) {
348+
if (db->hasKey(serverId, DBHelpers::Category::Player)) {
349+
tag = db->getCompoundTag(serverId, DBHelpers::Category::Player);
350+
}
351+
}
352+
}
344353
}
345-
} else {
346-
return Local<Value>();
347354
}
348355
}
349-
350-
if (!tag->isEmpty()) {
351-
return NbtCompoundClass::pack(tag);
352-
} else {
353-
return Local<Value>();
356+
if (tag && !tag->isEmpty()) {
357+
return NbtCompoundClass::pack(std::move(tag));
354358
}
359+
return Local<Value>();
355360
}
356361
CATCH("Fail in getPlayerNbt!")
357362
}
@@ -365,8 +370,24 @@ Local<Value> McClass::setPlayerNbt(const Arguments& args) {
365370
Player* player = ll::service::getLevel()->getPlayer(uuid);
366371
if (player) {
367372
player->load(*tag);
373+
return Boolean::newBoolean(true);
374+
} else {
375+
DBStorage* db = MoreGlobal::db;
376+
if (db) {
377+
if (db->hasKey("player_" + uuid.asString(), DBHelpers::Category::Player)) {
378+
std::unique_ptr<CompoundTag> playerTag =
379+
db->getCompoundTag("player_" + uuid.asString(), DBHelpers::Category::Player);
380+
if (playerTag) {
381+
std::string serverId = playerTag->at("ServerId");
382+
if (!serverId.empty()) {
383+
db->saveData(serverId, tag->toBinaryNbt(), DBHelpers::Category::Player);
384+
return Boolean::newBoolean(true);
385+
}
386+
}
387+
}
388+
}
368389
}
369-
return Boolean::newBoolean(true);
390+
return Boolean::newBoolean(false);
370391
}
371392
CATCH("Fail in setPlayerNbt!")
372393
}

tooth.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "github.com/LiteLDev/LegacyScriptEngine",
4-
"version": "0.5.3",
4+
"version": "0.5.4",
55
"info": {
66
"name": "LegacyScriptEngine",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",
@@ -12,7 +12,7 @@
1212
]
1313
},
1414
"dependencies": {
15-
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.5.3",
16-
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.5.3"
15+
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.5.4",
16+
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.5.4"
1717
}
1818
}

tooth.lua.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-lua",
4-
"version": "0.5.3",
4+
"version": "0.5.4",
55
"info": {
66
"name": "LegacyScriptEngine with Lua backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.nodejs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-nodejs",
4-
"version": "0.5.3",
4+
"version": "0.5.4",
55
"info": {
66
"name": "LegacyScriptEngine with NodeJs backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.python.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-python",
4-
"version": "0.5.3",
4+
"version": "0.5.4",
55
"info": {
66
"name": "LegacyScriptEngine with Python backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.quickjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs",
4-
"version": "0.5.3",
4+
"version": "0.5.4",
55
"info": {
66
"name": "LegacyScriptEngine with QuickJs backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

0 commit comments

Comments
 (0)