|
42 | 42 | #include "mc/legacy/ActorUniqueID.h" |
43 | 43 | #include "mc/nbt/CompoundTag.h" |
44 | 44 | #include "mc/nbt/ListTag.h" |
| 45 | +#include "mc/nbt/StringTag.h" |
45 | 46 | #include "mc/network/ConnectionRequest.h" |
46 | 47 | #include "mc/network/MinecraftPacketIds.h" |
47 | 48 | #include "mc/network/MinecraftPackets.h" |
|
117 | 118 | #include <climits> |
118 | 119 | #include <memory> |
119 | 120 | #include <optional> |
| 121 | +#include <stdexcept> |
120 | 122 | #include <string> |
121 | 123 | #include <vector> |
122 | 124 |
|
@@ -468,7 +470,28 @@ Local<Value> McClass::deletePlayerNbt(const Arguments& args) { |
468 | 470 | CHECK_ARG_TYPE(args[0], ValueKind::kString); |
469 | 471 | try { |
470 | 472 | mce::UUID uuid = mce::UUID::fromString(args[0].asString().toString()); |
471 | | - ll::service::getLevel()->getLevelStorage().deleteData("player_" + uuid.asString(), DBHelpers::Category::Player); |
| 473 | + if (uuid == mce::UUID::EMPTY()) { |
| 474 | + throw std::invalid_argument(args[0].asString().toString() + " is not a valid UUID"); |
| 475 | + } |
| 476 | + auto storage = ll::service::getLevel().transform([](auto& level) { return &level.getLevelStorage(); }); |
| 477 | + if (!storage) { |
| 478 | + return Boolean::newBoolean(false); |
| 479 | + } |
| 480 | + auto playerIds = storage->getCompoundTag("player_" + uuid.asString(), DBHelpers::Category::Player); |
| 481 | + if (!playerIds) { |
| 482 | + return Boolean::newBoolean(false); |
| 483 | + } |
| 484 | + for (auto& [type, id] : *playerIds) { |
| 485 | + if (!id.is_string()) { |
| 486 | + continue; |
| 487 | + } |
| 488 | + std::string& key = id.get<StringTag>(); |
| 489 | + if (type == "ServerId") { |
| 490 | + storage->deleteData(key, ::DBHelpers::Category::Player); |
| 491 | + } else { |
| 492 | + storage->deleteData("player_" + key, ::DBHelpers::Category::Player); |
| 493 | + } |
| 494 | + } |
472 | 495 | return Boolean::newBoolean(true); |
473 | 496 | } |
474 | 497 | CATCH("Fail in deletePlayerNbt!") |
|
0 commit comments