Fix ToolUser exception when swapping player
Also made /swap by name exclude the current player when searching
This commit is contained in:
parent
5f0e44d60e
commit
a2d901bd66
@ -243,7 +243,7 @@ void Player::diskLoad(Json const& diskStore) {
|
|||||||
|
|
||||||
m_genericProperties = diskStore.getObject("genericProperties");
|
m_genericProperties = diskStore.getObject("genericProperties");
|
||||||
|
|
||||||
refreshEquipment();
|
refreshArmor();
|
||||||
|
|
||||||
m_codexes->learnInitialCodexes(species());
|
m_codexes->learnInitialCodexes(species());
|
||||||
|
|
||||||
@ -1228,7 +1228,14 @@ void Player::clearSwap() {
|
|||||||
endTrigger();
|
endTrigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::refreshEquipment() {
|
void Player::refreshItems() {
|
||||||
|
if (isSlave())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_tools->setItems(m_inventory->primaryHeldItem(), m_inventory->secondaryHeldItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::refreshArmor() {
|
||||||
if (isSlave())
|
if (isSlave())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1240,8 +1247,11 @@ void Player::refreshEquipment() {
|
|||||||
m_armor->setLegsCosmeticItem(m_inventory->legsCosmetic());
|
m_armor->setLegsCosmeticItem(m_inventory->legsCosmetic());
|
||||||
m_armor->setBackItem(m_inventory->backArmor());
|
m_armor->setBackItem(m_inventory->backArmor());
|
||||||
m_armor->setBackCosmeticItem(m_inventory->backCosmetic());
|
m_armor->setBackCosmeticItem(m_inventory->backCosmetic());
|
||||||
|
}
|
||||||
|
|
||||||
m_tools->setItems(m_inventory->primaryHeldItem(), m_inventory->secondaryHeldItem());
|
void Player::refreshEquipment() {
|
||||||
|
refreshArmor();
|
||||||
|
refreshItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerBlueprintsPtr Player::blueprints() const {
|
PlayerBlueprintsPtr Player::blueprints() const {
|
||||||
|
@ -217,6 +217,9 @@ public:
|
|||||||
// Clear the item swap slot.
|
// Clear the item swap slot.
|
||||||
void clearSwap();
|
void clearSwap();
|
||||||
|
|
||||||
|
void refreshArmor();
|
||||||
|
void refreshItems();
|
||||||
|
|
||||||
// Refresh worn equipment from the inventory
|
// Refresh worn equipment from the inventory
|
||||||
void refreshEquipment();
|
void refreshEquipment();
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ Maybe<Uuid> PlayerStorage::playerUuidAt(size_t index) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe<Uuid> PlayerStorage::playerUuidByName(String const& name) {
|
Maybe<Uuid> PlayerStorage::playerUuidByName(String const& name, Maybe<Uuid> except) {
|
||||||
String cleanMatch = Text::stripEscapeCodes(name).toLower();
|
String cleanMatch = Text::stripEscapeCodes(name).toLower();
|
||||||
Maybe<Uuid> uuid;
|
Maybe<Uuid> uuid;
|
||||||
|
|
||||||
@ -107,7 +107,9 @@ Maybe<Uuid> PlayerStorage::playerUuidByName(String const& name) {
|
|||||||
|
|
||||||
size_t longest = SIZE_MAX;
|
size_t longest = SIZE_MAX;
|
||||||
for (auto& cache : m_savedPlayersCache) {
|
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 cleanName = Text::stripEscapeCodes(*name).toLower();
|
||||||
auto len = cleanName.size();
|
auto len = cleanName.size();
|
||||||
if (len < longest && cleanName.utf8().rfind(cleanMatch.utf8()) == 0) {
|
if (len < longest && cleanName.utf8().rfind(cleanMatch.utf8()) == 0) {
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
// Returns nothing if index is out of bounds.
|
// Returns nothing if index is out of bounds.
|
||||||
Maybe<Uuid> playerUuidAt(size_t index);
|
Maybe<Uuid> playerUuidAt(size_t index);
|
||||||
// Returns nothing if name doesn't match a player.
|
// 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.
|
// Also returns the diskStore Json if needed.
|
||||||
Json savePlayer(PlayerPtr const& player);
|
Json savePlayer(PlayerPtr const& player);
|
||||||
|
@ -537,7 +537,7 @@ bool UniverseClient::switchPlayer(size_t index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool UniverseClient::switchPlayer(String const& name) {
|
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);
|
return switchPlayer(*uuid);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user