30
30
#include " main/SafeGuardRecord.h"
31
31
#include " mc/certificates/WebToken.h"
32
32
#include " mc/dataloadhelper/DefaultDataLoadHelper.h"
33
+ #include " mc/deps/core/mce/UUID.h"
33
34
#include " mc/enums/BossBarColor.h"
34
35
#include " mc/enums/MinecraftPacketIds.h"
35
36
#include " mc/enums/TextPacketType.h"
99
100
#include < unordered_map>
100
101
#include < vector>
101
102
102
-
103
103
// ////////////////// Class Definition ////////////////////
104
104
105
105
ClassDefine<PlayerClass> PlayerClassBuilder =
@@ -331,29 +331,15 @@ Local<Value> McClass::getPlayerNbt(const Arguments& args) {
331
331
CHECK_ARGS_COUNT (args, 1 );
332
332
CHECK_ARG_TYPE (args[0 ], ValueKind::kString );
333
333
try {
334
- auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
335
- Player* player = ll::service::getLevel ()->getPlayer (uuid);
336
- if (player) {
337
- std::unique_ptr<CompoundTag> tag;
338
- if (player->save (*tag)) {
339
- return NbtCompoundClass::pack (std::move (tag));
340
- }
341
- } else {
342
- DBStorage* db = MoreGlobal::dbStorage;
343
- if (db) {
344
- if (db->hasKey (" player_" + uuid.asString (), DBHelpers::Category::Player)) {
345
- std::unique_ptr<CompoundTag> playerTag =
346
- db->getCompoundTag (" player_" + uuid.asString (), DBHelpers::Category::Player);
347
- if (playerTag) {
348
- std::string serverId = playerTag->at (" ServerId" );
349
- if (!serverId.empty ()) {
350
- if (db->hasKey (serverId, DBHelpers::Category::Player)) {
351
- return NbtCompoundClass::pack (
352
- std::move (db->getCompoundTag (serverId, DBHelpers::Category::Player))
353
- );
354
- }
355
- }
356
- }
334
+ auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
335
+ DBStorage* db = MoreGlobal::dbStorage;
336
+ if (db && db->hasKey (" player_" + uuid.asString (), DBHelpers::Category::Player)) {
337
+ std::unique_ptr<CompoundTag> playerTag =
338
+ db->getCompoundTag (" player_" + uuid.asString (), DBHelpers::Category::Player);
339
+ if (playerTag) {
340
+ std::string serverId = playerTag->at (" ServerId" );
341
+ if (!serverId.empty () && db->hasKey (serverId, DBHelpers::Category::Player)) {
342
+ return NbtCompoundClass::pack (std::move (db->getCompoundTag (serverId, DBHelpers::Category::Player)));
357
343
}
358
344
}
359
345
}
@@ -366,25 +352,17 @@ Local<Value> McClass::setPlayerNbt(const Arguments& args) {
366
352
CHECK_ARGS_COUNT (args, 2 );
367
353
CHECK_ARG_TYPE (args[0 ], ValueKind::kString );
368
354
try {
369
- auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
370
- auto tag = NbtCompoundClass::extract (args[1 ]);
371
- Player* player = ll::service::getLevel ()->getPlayer (uuid);
372
- if (player && !MoreGlobal::defaultDataLoadHelper) {
373
- player->load (*tag, *MoreGlobal::defaultDataLoadHelper);
374
- return Boolean::newBoolean (true );
375
- } else {
376
- DBStorage* db = MoreGlobal::dbStorage;
377
- if (db) {
378
- if (db->hasKey (" player_" + uuid.asString (), DBHelpers::Category::Player)) {
379
- std::unique_ptr<CompoundTag> playerTag =
380
- db->getCompoundTag (" player_" + uuid.asString (), DBHelpers::Category::Player);
381
- if (playerTag) {
382
- std::string serverId = playerTag->at (" ServerId" );
383
- if (!serverId.empty ()) {
384
- db->saveData (serverId, tag->toBinaryNbt (), DBHelpers::Category::Player);
385
- return Boolean::newBoolean (true );
386
- }
387
- }
355
+ mce::UUID uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
356
+ CompoundTag* tag = NbtCompoundClass::extract (args[1 ]);
357
+ DBStorage* db = MoreGlobal::dbStorage;
358
+ if (db && db->hasKey (" player_" + uuid.asString (), DBHelpers::Category::Player)) {
359
+ std::unique_ptr<CompoundTag> playerTag =
360
+ db->getCompoundTag (" player_" + uuid.asString (), DBHelpers::Category::Player);
361
+ if (playerTag) {
362
+ std::string serverId = playerTag->at (" ServerId" );
363
+ if (!serverId.empty ()) {
364
+ db->saveData (serverId, tag->toBinaryNbt (), DBHelpers::Category::Player);
365
+ return Boolean::newBoolean (true );
388
366
}
389
367
}
390
368
}
@@ -398,25 +376,33 @@ Local<Value> McClass::setPlayerNbtTags(const Arguments& args) {
398
376
CHECK_ARG_TYPE (args[0 ], ValueKind::kString );
399
377
CHECK_ARG_TYPE (args[2 ], ValueKind::kArray );
400
378
try {
401
- auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
402
- CompoundTag* nbt = NbtCompoundClass::extract (args[1 ]);
403
- auto arr = args[2 ].asArray ();
404
- Player* player = ll::service::getLevel ()->getPlayer (uuid);
405
- CompoundTag playerNbt;
406
- player->save (playerNbt);
407
- if (player && MoreGlobal::defaultDataLoadHelper) {
408
- for (int i = 0 ; i < arr.size (); ++i) {
409
- auto value = arr.get (i);
410
- if (value.getKind () == ValueKind::kString ) {
411
- std::string tagName = value.asString ().toString ();
412
- if (!nbt->at (tagName).is_null ()) {
413
- playerNbt.at (tagName) = nbt->at (tagName);
379
+ mce::UUID uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
380
+ CompoundTag* tag = NbtCompoundClass::extract (args[1 ]);
381
+ Local<Array> arr = args[2 ].asArray ();
382
+ DBStorage* db = MoreGlobal::dbStorage;
383
+ if (db && db->hasKey (" player_" + uuid.asString (), DBHelpers::Category::Player)) {
384
+ std::unique_ptr<CompoundTag> playerTag =
385
+ db->getCompoundTag (" player_" + uuid.asString (), DBHelpers::Category::Player);
386
+ if (playerTag) {
387
+ std::string serverId = playerTag->at (" ServerId" );
388
+ if (!serverId.empty () && db->hasKey (serverId, DBHelpers::Category::Player)) {
389
+ auto loadedTag = db->getCompoundTag (serverId, DBHelpers::Category::Player);
390
+ if (loadedTag) {
391
+ for (int i = 0 ; i < arr.size (); ++i) {
392
+ auto value = arr.get (i);
393
+ if (value.getKind () == ValueKind::kString ) {
394
+ std::string tagName = value.asString ().toString ();
395
+ if (!tag->at (tagName).is_null ()) {
396
+ loadedTag->at (tagName) = tag->at (tagName);
397
+ }
398
+ }
399
+ }
400
+ db->saveData (serverId, loadedTag->toBinaryNbt (), DBHelpers::Category::Player);
401
+ return Boolean::newBoolean (true );
414
402
}
403
+ return Boolean::newBoolean (true );
415
404
}
416
405
}
417
- player->load (playerNbt, *MoreGlobal::defaultDataLoadHelper);
418
- player->refreshInventory ();
419
- return Boolean::newBoolean (true );
420
406
}
421
407
return Boolean::newBoolean (false );
422
408
}
@@ -427,7 +413,7 @@ Local<Value> McClass::deletePlayerNbt(const Arguments& args) {
427
413
CHECK_ARGS_COUNT (args, 1 );
428
414
CHECK_ARG_TYPE (args[0 ], ValueKind::kString );
429
415
try {
430
- auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
416
+ mce::UUID uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
431
417
ll::service::getLevel ()->getLevelStorage ().deleteData (" player_" + uuid.asString (), DBHelpers::Category::Player);
432
418
return Boolean::newBoolean (true );
433
419
}
@@ -443,13 +429,7 @@ Local<Value> McClass::getPlayerScore(const Arguments& args) {
443
429
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
444
430
Objective* objective = scoreboard.getObjective (obj);
445
431
DBStorage* db = MoreGlobal::dbStorage;
446
- if (!objective) {
447
- return Number::newNumber (0 );
448
- }
449
- if (!db) {
450
- return Number::newNumber (0 );
451
- }
452
- if (!db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
432
+ if (!objective || !db || !db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
453
433
return Number::newNumber (0 );
454
434
}
455
435
std::unique_ptr<CompoundTag> playerTag =
@@ -458,10 +438,7 @@ Local<Value> McClass::getPlayerScore(const Arguments& args) {
458
438
return Number::newNumber (0 );
459
439
}
460
440
std::string serverId = playerTag->at (" ServerId" );
461
- if (serverId.empty ()) {
462
- return Number::newNumber (0 );
463
- }
464
- if (!db->hasKey (serverId, DBHelpers::Category::Player)) {
441
+ if (serverId.empty () || !db->hasKey (serverId, DBHelpers::Category::Player)) {
465
442
return Number::newNumber (0 );
466
443
}
467
444
std::unique_ptr<CompoundTag> serverIdTag = db->getCompoundTag (serverId, DBHelpers::Category::Player);
@@ -487,14 +464,8 @@ Local<Value> McClass::setPlayerScore(const Arguments& args) {
487
464
auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
488
465
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
489
466
Objective* objective = scoreboard.getObjective (args[1 ].asString ().toString ());
490
- if (!objective) {
491
- return Boolean::newBoolean (false );
492
- }
493
- DBStorage* db = MoreGlobal::dbStorage;
494
- if (!db) {
495
- return Boolean::newBoolean (false );
496
- }
497
- if (!db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
467
+ DBStorage* db = MoreGlobal::dbStorage;
468
+ if (!objective || !db || !db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
498
469
return Boolean::newBoolean (false );
499
470
}
500
471
std::unique_ptr<CompoundTag> playerTag =
@@ -503,10 +474,7 @@ Local<Value> McClass::setPlayerScore(const Arguments& args) {
503
474
return Boolean::newBoolean (false );
504
475
}
505
476
std::string serverId = playerTag->at (" ServerId" );
506
- if (serverId.empty ()) {
507
- return Boolean::newBoolean (false );
508
- }
509
- if (!db->hasKey (serverId, DBHelpers::Category::Player)) {
477
+ if (serverId.empty () || !db->hasKey (serverId, DBHelpers::Category::Player)) {
510
478
return Boolean::newBoolean (false );
511
479
}
512
480
std::unique_ptr<CompoundTag> serverIdTag = db->getCompoundTag (serverId, DBHelpers::Category::Player);
@@ -535,14 +503,8 @@ Local<Value> McClass::addPlayerScore(const Arguments& args) {
535
503
auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
536
504
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
537
505
Objective* objective = scoreboard.getObjective (args[1 ].asString ().toString ());
538
- if (!objective) {
539
- return Boolean::newBoolean (false );
540
- }
541
- DBStorage* db = MoreGlobal::dbStorage;
542
- if (!db) {
543
- return Boolean::newBoolean (false );
544
- }
545
- if (!db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
506
+ DBStorage* db = MoreGlobal::dbStorage;
507
+ if (!objective || !db || !db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
546
508
return Boolean::newBoolean (false );
547
509
}
548
510
std::unique_ptr<CompoundTag> playerTag =
@@ -551,10 +513,7 @@ Local<Value> McClass::addPlayerScore(const Arguments& args) {
551
513
return Boolean::newBoolean (false );
552
514
}
553
515
std::string serverId = playerTag->at (" ServerId" );
554
- if (serverId.empty ()) {
555
- return Boolean::newBoolean (false );
556
- }
557
- if (!db->hasKey (serverId, DBHelpers::Category::Player)) {
516
+ if (serverId.empty () || !db->hasKey (serverId, DBHelpers::Category::Player)) {
558
517
return Boolean::newBoolean (false );
559
518
}
560
519
std::unique_ptr<CompoundTag> serverIdTag = db->getCompoundTag (serverId, DBHelpers::Category::Player);
@@ -583,14 +542,8 @@ Local<Value> McClass::reducePlayerScore(const Arguments& args) {
583
542
auto uuid = mce::UUID::fromString (args[0 ].asString ().toString ());
584
543
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
585
544
Objective* objective = scoreboard.getObjective (args[1 ].asString ().toString ());
586
- if (!objective) {
587
- return Boolean::newBoolean (false );
588
- }
589
- DBStorage* db = MoreGlobal::dbStorage;
590
- if (!db) {
591
- return Boolean::newBoolean (false );
592
- }
593
- if (!db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
545
+ DBStorage* db = MoreGlobal::dbStorage;
546
+ if (!objective || !db || !db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
594
547
return Boolean::newBoolean (false );
595
548
}
596
549
std::unique_ptr<CompoundTag> playerTag =
@@ -599,10 +552,7 @@ Local<Value> McClass::reducePlayerScore(const Arguments& args) {
599
552
return Boolean::newBoolean (false );
600
553
}
601
554
std::string serverId = playerTag->at (" ServerId" );
602
- if (serverId.empty ()) {
603
- return Boolean::newBoolean (false );
604
- }
605
- if (!db->hasKey (serverId, DBHelpers::Category::Player)) {
555
+ if (serverId.empty () || !db->hasKey (serverId, DBHelpers::Category::Player)) {
606
556
return Boolean::newBoolean (false );
607
557
}
608
558
std::unique_ptr<CompoundTag> serverIdTag = db->getCompoundTag (serverId, DBHelpers::Category::Player);
@@ -634,14 +584,8 @@ Local<Value> McClass::deletePlayerScore(const Arguments& args) {
634
584
try {
635
585
Scoreboard& scoreboard = ll::service::getLevel ()->getScoreboard ();
636
586
Objective* objective = scoreboard.getObjective (args[1 ].asString ().toString ());
637
- if (!objective) {
638
- return Boolean::newBoolean (false );
639
- }
640
- DBStorage* db = MoreGlobal::dbStorage;
641
- if (!db) {
642
- return Boolean::newBoolean (false );
643
- }
644
- if (!db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
587
+ DBStorage* db = MoreGlobal::dbStorage;
588
+ if (!objective || !db || !db->hasKey (" player_" + args[0 ].asString ().toString (), DBHelpers::Category::Player)) {
645
589
return Boolean::newBoolean (false );
646
590
}
647
591
std::unique_ptr<CompoundTag> playerTag =
@@ -650,10 +594,7 @@ Local<Value> McClass::deletePlayerScore(const Arguments& args) {
650
594
return Boolean::newBoolean (false );
651
595
}
652
596
std::string serverId = playerTag->at (" ServerId" );
653
- if (serverId.empty ()) {
654
- return Boolean::newBoolean (false );
655
- }
656
- if (!db->hasKey (serverId, DBHelpers::Category::Player)) {
597
+ if (serverId.empty () || !db->hasKey (serverId, DBHelpers::Category::Player)) {
657
598
return Boolean::newBoolean (false );
658
599
}
659
600
std::unique_ptr<CompoundTag> serverIdTag = db->getCompoundTag (serverId, DBHelpers::Category::Player);
0 commit comments