Compare commits

...
3 Commits
Author SHA1 Message Date
Kiritiop 58d5478b30 Edit CHANGELOG.md 2026-10-11 09:00:34 +00:00
Kiritiop 2bde3058dc Fixed spectating not being cancelled when the spectator enters a battle
Closes #1955
2026-10-11 08:53:43 +00:00
Kiritiop ffdbbe0e21 Fixed /spectatebattle not starting the battle theme music
Closes #2047
2026-10-11 08:53:43 +00:00
3 changed files with 14 additions and 5 deletions
+2
View File
@@ -28,6 +28,8 @@
- Fixed the Pokédex evolution tree crashing with a stack overflow on evolutions that loop back on themselves.
- Fixed form-changing evolutions sometimes resolving to the source form in the Pokédex evolution tree.
- Broken datapack evolutions are now logged and skipped in the Pokédex evolution tree instead of crashing.
- Fixed `/spectatebattle` not starting the battle theme music, unlike spectating through the interaction wheel
- Fixed spectating not being cancelled when a battle starts for the spectator, which merged the two battles into an unplayable state, and fixed spectating a second battle leaving the first one still sending updates
### Developer
@@ -202,6 +202,7 @@ object BattleRegistry {
): BattleStartResult {
val battle = PokemonBattle(battleFormat, side1, side2)
val start: () -> Unit = {
battle.playerUUIDs.forEach { stopSpectating(it) }
battleMap[battle.battleId] = battle
startShowdown(battle)
}
@@ -224,6 +225,11 @@ object BattleRegistry {
ShowdownService.service.endBattle(battle)
}
@JvmStatic
fun stopSpectating(playerId: UUID) {
battleMap.values.forEach { it.spectators.remove(playerId) }
}
@JvmStatic
fun getBattle(id: UUID): PokemonBattle? {
return battleMap[id]
@@ -35,8 +35,6 @@ object SpectateBattleHandler : ServerNetworkPacketHandler<SpectateBattlePacket>
) {
val battle = BattleRegistry.getBattleByParticipatingPlayerId(packet.targetedEntityId)
if (battle != null && Cobblemon.config.allowSpectating) {
val target = battle.actors.filterIsInstance<PlayerBattleActor>().firstOrNull { it.uuid == packet.targetedEntityId }
// Check los and range
val targetedPlayerEntity = packet.targetedEntityId.getPlayer() ?: return
if (player.traceFirstEntityCollision(
@@ -49,9 +47,6 @@ object SpectateBattleHandler : ServerNetworkPacketHandler<SpectateBattlePacket>
}
this.spectateBattle(targetedPlayerEntity, player)
// Handle music
target?.battleTheme?.let { player.sendPacket(BattleMusicPacket(it)) }
}
else {
LOGGER.error("Battle of player id ${packet.targetedEntityId} not found (${player.uuid} tried spectating)")
@@ -76,9 +71,15 @@ object SpectateBattleHandler : ServerNetworkPacketHandler<SpectateBattlePacket>
val battle = BattleRegistry.getBattleByParticipatingPlayer(target) ?: return
BattleRegistry.stopSpectating(player.uuid)
battle.spectators.add(player.uuid)
player.sendPacket(BattleInitializePacket(battle, null))
player.sendPacket(BattleMessagePacket(battle.chatLog))
battle.actors.filterIsInstance<PlayerBattleActor>()
.firstOrNull { it.uuid == target.uuid }
?.battleTheme
?.let { player.sendPacket(BattleMusicPacket(it)) }
}
}