Fixes and De-Spagetti Code

This commit is contained in:
2024-12-12 16:09:25 +01:00
parent b12846d011
commit e1d3e47845
4 changed files with 9 additions and 9 deletions
@@ -22,6 +22,8 @@ package de.steamwar.tntleague.game
import de.steamwar.tntleague.colorByTeam
import de.steamwar.tntleague.config.TNTLeagueWorldConfig
import de.steamwar.tntleague.config.targetedBlocks
import de.steamwar.tntleague.game.TNTLeagueGame.WinReason
import de.steamwar.tntleague.game.TNTLeagueGame.win
import de.steamwar.tntleague.message
import de.steamwar.tntleague.plugin
import net.kyori.adventure.text.Component
@@ -127,9 +129,8 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va
}
fun leave(player: Player) {
members.remove(player)
if (TNTLeagueGame.state != TNTLeagueGame.GameState.RUNNING) {
members.remove(player)
if (members.isEmpty()) {
plugin.server.onlinePlayers.firstOrNull { it != player && TNTLeagueGame.getTeam(it) == null }?.run {
members.add(this)
@@ -142,6 +143,10 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va
isReady = false
}
}
} else if (TNTLeagueGame.state == TNTLeagueGame.GameState.RUNNING) {
if (members.isEmpty()) {
win(this.opposite, WinReason.LEAVE)
}
}
}