From 8ab1f8bf7d2848c5f515be4bc1d5af7f363a6faf Mon Sep 17 00:00:00 2001 From: thiccaxe <51303986+thiccaxe@users.noreply.github.com> Date: Fri, 13 May 2022 22:55:39 -0700 Subject: [PATCH 1/2] limit time between stages --- .../net/minestom/arena/game/mob/MobArena.java | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) 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 6d21ba7..ce52d08 100644 --- a/src/main/java/net/minestom/arena/game/mob/MobArena.java +++ b/src/main/java/net/minestom/arena/game/mob/MobArena.java @@ -14,6 +14,7 @@ import net.minestom.arena.Messenger; 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; @@ -149,6 +150,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; @@ -365,8 +369,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) { @@ -381,13 +417,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."); @@ -398,6 +429,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; } From 99852a936642c8f724012e8baec090372293b602 Mon Sep 17 00:00:00 2001 From: thiccaxe <51303986+thiccaxe@users.noreply.github.com> Date: Fri, 13 May 2022 23:14:15 -0700 Subject: [PATCH 2/2] shorten stage start title --- src/main/java/net/minestom/arena/game/mob/MobArena.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 ce52d08..86b2aef 100644 --- a/src/main/java/net/minestom/arena/game/mob/MobArena.java +++ b/src/main/java/net/minestom/arena/game/mob/MobArena.java @@ -384,7 +384,7 @@ 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(); } @@ -484,7 +484,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));