Update phase transition notifications with detailed timing
Introduced specific second-based notifications for better accuracy as a phase approaches. Added distinct messaging for the game ending phase to improve clarity for players. Simplified code by replacing hard-coded values with a predefined list of notification intervals.
This commit is contained in:
parent
8b09e54106
commit
c3b11995c7
|
|
@ -13,6 +13,7 @@ import javax.annotation.Nullable;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -66,7 +67,8 @@ public class RunningGame implements Runnable {
|
||||||
gameManager.getPhaseExecutor(phase).start(flag);
|
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<Integer> NOTIFY_SECONDS = List.of(45, 30, 15, 10, 5, 3, 2, 1);
|
||||||
|
private void broadcastNextPhaseStartTime(GamePhase currentPhase, GamePhase nextPhase) {
|
||||||
//Remaining time for this phase
|
//Remaining time for this phase
|
||||||
Duration duration = phaseDurations.get(currentPhase).minus(Duration.between(phaseStartTime, Instant.now()));
|
Duration duration = phaseDurations.get(currentPhase).minus(Duration.between(phaseStartTime, Instant.now()));
|
||||||
log.debug(duration.toString());//TODO remove debug
|
log.debug(duration.toString());//TODO remove debug
|
||||||
|
|
@ -75,11 +77,21 @@ public class RunningGame implements Runnable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastMinuteBroadcast = (int) duration.toMinutes();
|
lastMinuteBroadcast = (int) duration.toMinutes();
|
||||||
|
if (nextPhase.equals(GamePhase.ENDED)) {
|
||||||
|
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
|
||||||
|
"<green>The game will end in <bold><red>" + duration.toMinutes() + "</red> minutes</bold></green>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
|
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
|
||||||
"<green>The <phase> will start in <bold><red>" + duration.toMinutes() + "</red> minutes</bold></green>",
|
"<green>The <phase> will start in <bold><red>" + duration.toMinutes() + "</red> minutes</bold></green>",
|
||||||
Placeholder.component("phase", nextPhase.getDisplayName())
|
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(
|
||||||
|
"<green>The game will end in <bold><red>" + duration.toSeconds() + "</red> seconds</bold></green>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
|
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(
|
||||||
"<green>The <phase> will start in <bold><red>" + duration.toSeconds() + "</red> seconds</bold></green>",
|
"<green>The <phase> will start in <bold><red>" + duration.toSeconds() + "</red> seconds</bold></green>",
|
||||||
Placeholder.component("phase", nextPhase.getDisplayName())
|
Placeholder.component("phase", nextPhase.getDisplayName())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user