From 71ff5f9286c10c6e729ce5078484abcc7be3901b Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Sun, 14 Jun 2020 00:20:56 +0200 Subject: [PATCH] Fix Second Chance --- .../spigot_ttt/game/items/impl/SecondChance.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt index 3d2e722..446b3fe 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/items/impl/SecondChance.kt @@ -84,6 +84,8 @@ object SecondChance: TTTItem, Buyable { state.timeoutAction = TimeoutAction(event.tttPlayer, event.tttCorpse.location) } } + + isc.forEveryState { s, _ -> if (s.timeoutAction != null) event.winnerRoleGroup = null } } @EventHandler @@ -137,18 +139,22 @@ object SecondChance: TTTItem, Buyable { val duration = Duration.between(startedAt, Instant.now()).toMillis().toDouble() / 1000 val progress = duration / TIMEOUT - if (progress > 1) stop() else bossBar.progress = 1.0 - progress + if (progress > 1) onTimeout() else bossBar.progress = 1.0 - progress }, 0, 1) + private fun onTimeout() { + try { + PlayerManager.letRemainingRoleGroupWin() + } catch (e: IllegalStateException) {} + + stop() + } + fun stop() { isc.remove(tttPlayer) task.cancel() tttPlayer.player.closeInventory() bossBar.removePlayer(tttPlayer.player) - - try { - PlayerManager.letRemainingRoleGroupWin() - } catch (e: IllegalStateException) {} } }