diff --git a/src/main/java/com/alttd/ctf/game/RunningGame.java b/src/main/java/com/alttd/ctf/game/RunningGame.java index 8279c94..d376d47 100644 --- a/src/main/java/com/alttd/ctf/game/RunningGame.java +++ b/src/main/java/com/alttd/ctf/game/RunningGame.java @@ -13,6 +13,7 @@ import javax.annotation.Nullable; import java.time.Duration; import java.time.Instant; import java.util.HashMap; +import java.util.List; import java.util.concurrent.ScheduledExecutorService; @Slf4j @@ -66,7 +67,8 @@ public class RunningGame implements Runnable { gameManager.getPhaseExecutor(phase).start(flag); } - private void broadcastNextPhaseStartTime(GamePhase currentPhase, GamePhase nextPhase) {//TODO check how this works/what it should do + private static final List NOTIFY_SECONDS = List.of(45, 30, 15, 10, 5, 3, 2, 1); + private void broadcastNextPhaseStartTime(GamePhase currentPhase, GamePhase nextPhase) { //Remaining time for this phase Duration duration = phaseDurations.get(currentPhase).minus(Duration.between(phaseStartTime, Instant.now())); log.debug(duration.toString());//TODO remove debug @@ -75,11 +77,21 @@ public class RunningGame implements Runnable { return; } lastMinuteBroadcast = (int) duration.toMinutes(); + if (nextPhase.equals(GamePhase.ENDED)) { + Bukkit.broadcast(MiniMessage.miniMessage().deserialize( + "The game will end in " + duration.toMinutes() + " minutes")); + return; + } Bukkit.broadcast(MiniMessage.miniMessage().deserialize( "The will start in " + duration.toMinutes() + " minutes", Placeholder.component("phase", nextPhase.getDisplayName()) )); - } else if (duration.toMinutes() < 1 && duration.toSeconds() % 15 == 0) { + } else if (duration.toMinutes() < 1 && NOTIFY_SECONDS.contains(duration.toSecondsPart())) { + if (nextPhase.equals(GamePhase.ENDED)) { + Bukkit.broadcast(MiniMessage.miniMessage().deserialize( + "The game will end in " + duration.toSeconds() + " seconds")); + return; + } Bukkit.broadcast(MiniMessage.miniMessage().deserialize( "The will start in " + duration.toSeconds() + " seconds", Placeholder.component("phase", nextPhase.getDisplayName())