diff --git a/src/main/java/net/minestom/arena/game/mob/MobArena.java b/src/main/java/net/minestom/arena/game/mob/MobArena.java index 9a0d25c..b480d1b 100644 --- a/src/main/java/net/minestom/arena/game/mob/MobArena.java +++ b/src/main/java/net/minestom/arena/game/mob/MobArena.java @@ -13,6 +13,7 @@ import net.minestom.arena.*; import net.minestom.arena.feature.Feature; import net.minestom.arena.feature.Features; +import net.minestom.arena.game.ArenaManager; import net.minestom.arena.game.Generator; import net.minestom.arena.game.SingleInstanceArena; import net.minestom.arena.group.Group; @@ -148,6 +149,9 @@ public final class MobArena implements SingleInstanceArena { private static final int SPAWN_RADIUS = 10; private static final int HEIGHT = 16; + + private static final Duration ROUND_WAIT_TIME = Duration.ofSeconds(30); + private final AtomicInteger mobCount = new AtomicInteger(); private boolean stageInProgress; private int initialMobCount; @@ -381,8 +385,40 @@ private void onStageCleared() { bossBar.color(BossBar.Color.GREEN); group().playSound(Sound.sound(SoundEvent.UI_TOAST_CHALLENGE_COMPLETE, Sound.Source.MASTER, 0.5f, 1), Sound.Emitter.self()); + arenaInstance.showTitle(Title.title( + Component.text("Stage Cleared", NamedTextColor.GREEN), + Component.text(ROUND_WAIT_TIME.getSeconds() + " seconds to prepare for next stage"), + Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ofMillis(300)) + )); Messenger.info(group(), "Stage " + stage + " cleared! Talk to the NPC to continue to the next stage"); new NextStageNPC().setInstance(arenaInstance, new Pos(0.5, HEIGHT, 0.5)); + + startForceContinueCountdown(); + } + + private void startForceContinueCountdown() { + final AtomicInteger countdown = new AtomicInteger((int) ROUND_WAIT_TIME.getSeconds()); + MinecraftServer.getSchedulerManager().submitTask(() -> { + final int count = countdown.getAndDecrement(); + + if (stageInProgress() || !ArenaManager.list().contains(this)) { + return TaskSchedule.stop(); + } + if (count == 0) { + continueToNextStage(false); + return TaskSchedule.stop(); + } + + if (count > 3) { + if (count % 10 == 0) { + Messenger.info(group(), count + " seconds remain to prepare for the next stage."); + } + } else { + Messenger.info(group(), count + " seconds remain."); + } + + return TaskSchedule.seconds(1); + }); } public void continueToNextStage(Player player) { @@ -397,13 +433,8 @@ public void continueToNextStage(Player player) { if (untilStart <= 0) { Messenger.info(group(), player.getUsername() + " has continued. Starting the next wave."); - bossBar.name(Component.text("Wave starting...")); - bossBar.progress(1); - bossBar.color(BossBar.Color.BLUE); + continueToNextStage(true); - Messenger.countdown(group(), 3) - .thenRun(this::nextStage) - .thenRun(continued::clear); } else { Messenger.info(group(), player.getUsername() + " has continued. " + untilStart + " more players must continue to start the next wave."); @@ -414,6 +445,20 @@ public void continueToNextStage(Player player) { } } + private void continueToNextStage(boolean showCountdown) { + bossBar.name(Component.text("Wave starting...")); + bossBar.progress(1); + bossBar.color(BossBar.Color.BLUE); + continued.clear(); + + if (showCountdown) { + Messenger.countdown(group(), 3) + .thenRun(this::nextStage); + } else { + nextStage(); + } + } + public int stage() { return stage; } @@ -455,7 +500,8 @@ public void nextStage() { arenaInstance.showTitle(Title.title( Component.text("Stage " + stage, NamedTextColor.GREEN), - Component.text(initialMobCount + mobOrMobs) + Component.text(initialMobCount + mobOrMobs), + Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(1), Duration.ofMillis(500)) )); arenaInstance.playSound(Sound.sound(SoundEvent.BLOCK_NOTE_BLOCK_PLING, Sound.Source.MASTER, 1f, 2f));