From e8361dfa7636e84b87e7a2c993580ab47c51022d Mon Sep 17 00:00:00 2001 From: Karthik Bandagonda <32044378+Karthik99999@users.noreply.github.com> Date: Wed, 24 Jul 2024 01:05:59 +0000 Subject: [PATCH] Auctions: Fix edge case for removing players after an undo (#10437) --- server/chat-plugins/auction.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/server/chat-plugins/auction.ts b/server/chat-plugins/auction.ts index dd41edf5c38b..93d101bdc47a 100644 --- a/server/chat-plugins/auction.ts +++ b/server/chat-plugins/auction.ts @@ -37,21 +37,13 @@ class Team { } getManagers() { - const managers = []; - for (const manager of this.auction.managers.values()) { - if (manager.team !== this) continue; - const user = Users.getExact(manager.id); - if (user) { - managers.push(user.name); - } else { - managers.push(manager.id); - } - } - return managers; + return [...this.auction.managers.values()] + .filter(m => m.team === this) + .map(m => Users.getExact(m.id)?.name || m.id); } addPlayer(player: Player, price = 0) { - if (player.team) player.team.removePlayer(player); + player.team?.removePlayer(player); this.players.push(player); this.credits -= price; player.team = this; @@ -59,7 +51,9 @@ class Team { } removePlayer(player: Player) { - this.players.splice(this.players.indexOf(player), 1); + const pIndex = this.players.indexOf(player); + if (pIndex === -1) return; + this.players.splice(pIndex, 1); delete player.team; player.price = 0; }