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}
0 commit comments