diff --git a/src/main/java/fr/hugman/build_rush/game/state/BRActive.java b/src/main/java/fr/hugman/build_rush/game/state/BRActive.java index 5515d2d..fdd0f15 100644 --- a/src/main/java/fr/hugman/build_rush/game/state/BRActive.java +++ b/src/main/java/fr/hugman/build_rush/game/state/BRActive.java @@ -38,6 +38,7 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; +import net.minecraft.util.Pair; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -62,10 +63,7 @@ import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; +import java.util.*; public class BRActive { private final ServerWorld world; @@ -918,25 +916,41 @@ public void startElimination() { this.perfectRoundsInARow++; } + List> scores = new ArrayList<>(); + for (var player : this.space.getPlayers()) { var data = this.playerDataMap.get(player.getUuid()); if (data == null || data.eliminated) { continue; } - if (data.score == this.maxScore) { - TextUtil.sendSubtitle(player, Text.translatable("title.build_rush.perfect").setStyle(Style.EMPTY.withColor(TextUtil.LEGENDARY).withBold(true)), 0, 3 * 20, 10); - player.playSoundToPlayer(SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1.0f, 1.0f); - } else { - float scorePercentage = data.score / (float) this.maxScore; - String scoreAsPercent = String.format("%.2f", scorePercentage * 100).replaceAll("0*$", "").replaceAll("[,.]$", ""); - var scoreText = Text.translatable("generic.build_rush.score", scoreAsPercent) - .setStyle(Style.EMPTY.withColor(TextUtil.lerpScoreColor(scorePercentage)).withBold(true)); + scores.add(new Pair<>(player, data.score)); + } + scores.sort(Comparator.comparing(Pair::getRight)); - player.sendMessage(TextUtil.translatable(TextUtil.DASH, TextUtil.NEUTRAL, "text.build_rush.score", scoreText), false); - TextUtil.sendSubtitle(player, scoreText, 0, 2 * 20, 5); - player.playSoundToPlayer(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0f, 1.0f); + this.world.getServer().getPlayerManager().broadcast(Text.translatable("generic.build_rush.round_stats.title").setStyle(Style.EMPTY.withColor(TextUtil.LEGENDARY).withBold(true)), false); + int rank = 0; + int previousScore = Integer.MAX_VALUE; + for (int i = scores.size() - 1; i >= 0; i--) { + Pair pair = scores.get(i); + if (pair.getRight() < previousScore) { + rank++; } + float scorePercentage = pair.getRight() / (float) this.maxScore; + String scoreAsPercent = String.format("%.2f", scorePercentage * 100).replaceAll("0*$", "").replaceAll("[,.]$", ""); + + var scoreText = Text.translatable("generic.build_rush.score", scoreAsPercent) + .setStyle(Style.EMPTY.withColor(TextUtil.lerpScoreColor(scorePercentage)).withBold(true)); + + int color = switch (rank) { + case 1 -> TextUtil.GOLD; + case 2 -> TextUtil.SILVER; + case 3 -> TextUtil.BRONZE; + default -> TextUtil.NEUTRAL; + }; + + this.world.getServer().getPlayerManager().broadcast(Text.translatable("generic.build_rush.round_stats.entry", rank, pair.getLeft().getDisplayName(), scoreText).setStyle(Style.EMPTY.withColor(color)), false); + previousScore = pair.getRight(); } if (this.loserUuid == null) { diff --git a/src/main/java/fr/hugman/build_rush/text/TextUtil.java b/src/main/java/fr/hugman/build_rush/text/TextUtil.java index 798ae4a..a7ad6b3 100644 --- a/src/main/java/fr/hugman/build_rush/text/TextUtil.java +++ b/src/main/java/fr/hugman/build_rush/text/TextUtil.java @@ -23,6 +23,10 @@ public class TextUtil { public static final int LEGENDARY = 0xface3e; public static final int LEGENDARY_S = 0xd9a107; + public static final int GOLD = 0xc98910; + public static final int SILVER = 0x965a38; + public static final int BRONZE = 0xa8a8a8; + public static final String DASH = "»"; public static final String SKULL = "☠"; public static final String PICKAXE = "⛏"; diff --git a/src/main/resources/data/build_rush/lang/en_us.json b/src/main/resources/data/build_rush/lang/en_us.json index 7c704de..800c0a1 100644 --- a/src/main/resources/data/build_rush/lang/en_us.json +++ b/src/main/resources/data/build_rush/lang/en_us.json @@ -9,8 +9,10 @@ "game.build_rush.flags.signal": "Build Rush: Signal Flags", "generic.build_rush.score": "%d%%", + "generic.build_rush.round_stats.title": "Round stats:", + "generic.build_rush.round_stats.entry": "%d. %s - %s", - "text.build_rush.eliminated": "%s has been eliminated! They got a %s percent correct build.", + "text.build_rush.eliminated": "%s has been eliminated! They got a %s percent correct build.", "text.build_rush.eliminated.self": "You have been eliminated!", "text.build_rush.score": "You got a %s correct build!", "text.build_rush.finished": "You got the entire build correctly!",