Fix ToolUser exception when swapping player

Also made /swap by name exclude the current player when searching
This commit is contained in:
Kae 2023-07-24 17:54:31 +10:00
parent 5f0e44d60e
commit a2d901bd66
5 changed files with 22 additions and 7 deletions

View File

@ -243,7 +243,7 @@ void Player::diskLoad(Json const& diskStore) {
m_genericProperties = diskStore.getObject("genericProperties");
refreshEquipment();
refreshArmor();
m_codexes->learnInitialCodexes(species());
@ -1228,7 +1228,14 @@ void Player::clearSwap() {
endTrigger();
}
void Player::refreshEquipment() {
void Player::refreshItems() {
if (isSlave())
return;
m_tools->setItems(m_inventory->primaryHeldItem(), m_inventory->secondaryHeldItem());
}
void Player::refreshArmor() {
if (isSlave())
return;
@ -1240,8 +1247,11 @@ void Player::refreshEquipment() {
m_armor->setLegsCosmeticItem(m_inventory->legsCosmetic());
m_armor->setBackItem(m_inventory->backArmor());
m_armor->setBackCosmeticItem(m_inventory->backCosmetic());
}
m_tools->setItems(m_inventory->primaryHeldItem(), m_inventory->secondaryHeldItem());
void Player::refreshEquipment() {
refreshArmor();
refreshItems();
}
PlayerBlueprintsPtr Player::blueprints() const {

View File

@ -217,6 +217,9 @@ public:
// Clear the item swap slot.
void clearSwap();
void refreshArmor();
void refreshItems();
// Refresh worn equipment from the inventory
void refreshEquipment();

View File

@ -99,7 +99,7 @@ Maybe<Uuid> PlayerStorage::playerUuidAt(size_t index) {
return {};
}
Maybe<Uuid> PlayerStorage::playerUuidByName(String const& name) {
Maybe<Uuid> PlayerStorage::playerUuidByName(String const& name, Maybe<Uuid> except) {
String cleanMatch = Text::stripEscapeCodes(name).toLower();
Maybe<Uuid> uuid;
@ -107,7 +107,9 @@ Maybe<Uuid> PlayerStorage::playerUuidByName(String const& name) {
size_t longest = SIZE_MAX;
for (auto& cache : m_savedPlayersCache) {
if (auto name = cache.second.optQueryString("identity.name")) {
if (except && *except == cache.first)
continue;
else if (auto name = cache.second.optQueryString("identity.name")) {
auto cleanName = Text::stripEscapeCodes(*name).toLower();
auto len = cleanName.size();
if (len < longest && cleanName.utf8().rfind(cleanMatch.utf8()) == 0) {

View File

@ -19,7 +19,7 @@ public:
// Returns nothing if index is out of bounds.
Maybe<Uuid> playerUuidAt(size_t index);
// Returns nothing if name doesn't match a player.
Maybe<Uuid> playerUuidByName(String const& name);
Maybe<Uuid> playerUuidByName(String const& name, Maybe<Uuid> except = {});
// Also returns the diskStore Json if needed.
Json savePlayer(PlayerPtr const& player);

View File

@ -537,7 +537,7 @@ bool UniverseClient::switchPlayer(size_t index) {
}
bool UniverseClient::switchPlayer(String const& name) {
if (auto uuid = m_playerStorage->playerUuidByName(name))
if (auto uuid = m_playerStorage->playerUuidByName(name, mainPlayer()->uuid()))
return switchPlayer(*uuid);
else
return false;