From 410f7b4027d574146db9c1a0812ab7661e7bfd1b Mon Sep 17 00:00:00 2001 From: jannis Date: Mon, 16 Feb 2026 21:07:30 +0100 Subject: [PATCH] perfekted colorjump --- .../stateless/types/colorJump/ColorJump.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/colorJump/ColorJump.java b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/colorJump/ColorJump.java index 0f29bc1..51a9c5b 100644 --- a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/colorJump/ColorJump.java +++ b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/colorJump/ColorJump.java @@ -32,6 +32,7 @@ public class ColorJump extends StatelessGame { Block.PINK_CONCRETE ); private Block currentBlock; + private Block blockLastRound; private double roundTime = 5; private final double multiplierNextRoundTime = 0.9; @@ -56,6 +57,8 @@ public class ColorJump extends StatelessGame { this.generate(); this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size())); + if(this.currentBlock == this.blockLastRound) this.nextRound(); + this.blockLastRound = this.currentBlock; ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material())); this.getPlayers().forEach(player -> { player.getInventory().clear(); @@ -80,15 +83,31 @@ public class ColorJump extends StatelessGame { if(this.roundTime > 0.5) this.roundTime = this.roundTime * this.multiplierNextRoundTime; - long secondsLeft = Math.max(0, (long) this.roundTime); + long totalMillis = (long) (this.roundTime * 1000); + long startTime = System.currentTimeMillis(); - for (int i = Math.min(3, (int) secondsLeft); i >= 0; i--) { - int level = i; - scheduler.scheduleTask(() -> { - this.getPlayers().forEach(player -> player.setLevel(level)); + scheduler.scheduleTask(() -> { + if (!this.isRunning) return stop; + + long elapsed = System.currentTimeMillis() - startTime; + long remaining = totalMillis - elapsed; + + if (remaining <= 0) { + this.getPlayers().forEach(player -> { + player.setExp(0f); + player.setLevel(0); + }); return stop; - }, TaskSchedule.seconds(secondsLeft-i)); - } + } + + float progress = (float) remaining / totalMillis; + + this.getPlayers().forEach(player -> { + player.setExp(progress); + player.setLevel((int) Math.ceil(remaining / 1000.0)); + }); + return TaskSchedule.millis(50); // 1 Tick (20 TPS) + }, TaskSchedule.millis(0)); } private void generate() {