added possibility for same scores Tournament

This commit is contained in:
2025-10-11 01:07:40 +02:00
parent e871c0bcb5
commit 123c01da14
2 changed files with 26 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import eu.mhsl.minenet.minigames.score.Score;
import net.minestom.server.entity.Player;
import java.util.*;
import java.util.stream.Collectors;
public class Tournament {
private final List<Score> gameScores = new ArrayList<>();
@@ -43,9 +44,11 @@ public class Tournament {
public Rewards getRewards() {
Map<UUID, Integer> itemCount = new HashMap<>();
int count = 0;
for (Player player : getPlaces()) {
for (Set<Player> players : getPlaces()) {
if(count >= this.rewardConfiguration.rewardCount().size()) break;
for(Player player : players) {
itemCount.put(player.getUuid(), this.rewardConfiguration.rewardCount().get(count));
}
count++;
}
@@ -53,18 +56,21 @@ public class Tournament {
this.memorialConfiguration.memorialMaterial().namespace().value(),
this.memorialConfiguration.memorialTitle(),
this.memorialConfiguration.memorialLore(),
getPlaces().stream().map(Player::getUuid).toList(),
getGameScores().keySet().stream().map(Player::getUuid).toList(),
this.rewardConfiguration.item().namespace().value(),
itemCount
);
}
public List<Player> getPlaces() {
List<Player> players = new ArrayList<>(
public List<Set<Player>> getPlaces() {
List<Set<Player>> players = new ArrayList<>(
getGameScores().entrySet().stream()
.sorted(Map.Entry.comparingByValue())
.map(Map.Entry::getKey)
.toList()
.collect(
Collectors.groupingBy(
Map.Entry::getValue,
Collectors.mapping(Map.Entry::getKey, Collectors.toSet())
)
).values()
);
Collections.reverse(players);

View File

@@ -12,10 +12,12 @@ import net.minestom.server.entity.*;
import net.minestom.server.event.player.PlayerMoveEvent;
import net.minestom.server.instance.anvil.AnvilLoader;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
public class TournamentDisplay extends MineNetInstance implements Spawnable {
private final List<Player> places;
private final List<Set<Player>> places;
private final Tournament tournament;
private final Pos[] placePositions = new Pos[] {
@@ -30,7 +32,7 @@ public class TournamentDisplay extends MineNetInstance implements Spawnable {
this.places = tournament.getPlaces();
this.tournament = tournament;
this.places.forEach(player -> player.setGameMode(GameMode.ADVENTURE));
this.places.forEach(players -> players.forEach(player -> player.setGameMode(GameMode.ADVENTURE)));
eventNode().addListener(PlayerMoveEvent.class, playerMoveEvent -> {
if(isOnDisplay(playerMoveEvent.getPlayer()) && !playerMoveEvent.getNewPosition().sameBlock(placePositions[getRankPosition(playerMoveEvent.getPlayer())])) {
@@ -45,7 +47,10 @@ public class TournamentDisplay extends MineNetInstance implements Spawnable {
}
private int getRankPosition(Player player) {
return this.places.indexOf(player);
for (int i = 0; i < places.size(); i++) {
if (places.get(i).contains(player)) return i;
}
return -1;
}
@Override
@@ -56,8 +61,11 @@ public class TournamentDisplay extends MineNetInstance implements Spawnable {
p.teleport(placePositions[getRankPosition(p)]);
}
});
List<Player> players = this.places.stream()
.flatMap(s -> s.stream().sorted(Comparator.comparing(Player::getUsername)))
.toList();
new ChatMessage(Icon.STAR)
.numberedList(this.places.stream().map(player -> String.format("%s - %s Punkte", player.getUsername(), tournament.getGameScores().get(player))).toList())
.list(players.stream().map(player -> String.format("%s. %s - %s Punkte", this.getRankPosition(player)+1, player.getUsername(), tournament.getGameScores().get(player))).toList())
.send(p);
return false;
}