Wide variety of changes for release
This commit is contained in:
@@ -55,8 +55,9 @@ public abstract class Score {
|
||||
this.checkGameEnd();
|
||||
}
|
||||
|
||||
private void insertRemainingPlayers(Set<Player> players) {
|
||||
public void insertRemainingPlayers(Set<Player> players) {
|
||||
this.insertResultImplementation(players.stream().filter(p -> !hasResult(p)).collect(Collectors.toSet()));
|
||||
setDone();
|
||||
}
|
||||
|
||||
public boolean hasResult(Player p) {
|
||||
|
@@ -0,0 +1,6 @@
|
||||
package eu.mhsl.minenet.minigames.score.tournament;
|
||||
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
public record MemorialConfiguration(Material memorialMaterial, String memorialTitle, String memorialLore) {
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package eu.mhsl.minenet.minigames.score.tournament;
|
||||
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record RewardConfiguration(Material item, List<Integer> rewardCount) {
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package eu.mhsl.minenet.minigames.score.tournament;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public record Rewards(String memorialMaterial, String memorialTitle, String memorialLore, List<UUID> memorials, String material, Map<UUID, Integer> rewards) {
|
||||
}
|
@@ -3,26 +3,88 @@ package eu.mhsl.minenet.minigames.score.tournament;
|
||||
import eu.mhsl.minenet.minigames.score.Score;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class Tournament {
|
||||
private final List<Score> scores = new ArrayList<>();
|
||||
private final List<Score> gameScores = new ArrayList<>();
|
||||
private RewardConfiguration rewardConfiguration;
|
||||
private MemorialConfiguration memorialConfiguration;
|
||||
|
||||
public void addScore(Score score) {
|
||||
this.scores.add(score);
|
||||
this.gameScores.add(score);
|
||||
}
|
||||
|
||||
public int getScoreCount() {
|
||||
return this.scores.size();
|
||||
return this.gameScores.size();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.scores.clear();
|
||||
this.gameScores.clear();
|
||||
}
|
||||
|
||||
public List<Map<Player, Integer>> getScores() {
|
||||
return null;
|
||||
|
||||
public Map<Player, Integer> getGameScores() {
|
||||
Map<Player, Integer> data = new HashMap<>();
|
||||
gameScores.forEach(game -> {
|
||||
int count = 0;
|
||||
for (Set<Player> players : game.getScores()) {
|
||||
count++;
|
||||
for (Player player : players) {
|
||||
int points = (game.getScores().size() - count) + boost(count, game.getScores().size());
|
||||
|
||||
data.computeIfPresent(player, (existingPlayer, existingPoints) -> existingPoints + points);
|
||||
data.computeIfAbsent(player, newPlayer -> points);
|
||||
}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
public Rewards getRewards() {
|
||||
Map<UUID, Integer> itemCount = new HashMap<>();
|
||||
int count = 0;
|
||||
for (Player player : getPlaces()) {
|
||||
if(count >= this.rewardConfiguration.rewardCount().size()) break;
|
||||
itemCount.put(player.getUuid(), this.rewardConfiguration.rewardCount().get(count));
|
||||
count++;
|
||||
}
|
||||
|
||||
return new Rewards(
|
||||
this.memorialConfiguration.memorialMaterial().namespace().value(),
|
||||
this.memorialConfiguration.memorialTitle(),
|
||||
this.memorialConfiguration.memorialLore(),
|
||||
getPlaces().stream().map(Player::getUuid).toList(),
|
||||
this.rewardConfiguration.item().namespace().value(),
|
||||
itemCount
|
||||
);
|
||||
}
|
||||
|
||||
public List<Player> getPlaces() {
|
||||
List<Player> players = new ArrayList<>(
|
||||
getGameScores().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue())
|
||||
.map(Map.Entry::getKey)
|
||||
.toList()
|
||||
);
|
||||
|
||||
Collections.reverse(players);
|
||||
return players;
|
||||
}
|
||||
|
||||
private int boost(int selfPlace, int placeCount) {
|
||||
return switch (selfPlace) {
|
||||
case 0 -> placeCount / 3;
|
||||
case 1 -> placeCount / 4;
|
||||
case 2 -> placeCount / 5;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
public void setRewardConfiguration(RewardConfiguration rewardConfiguration) {
|
||||
this.rewardConfiguration = rewardConfiguration;
|
||||
}
|
||||
|
||||
public void setMemorialConfiguration(MemorialConfiguration memorialConfiguration) {
|
||||
this.memorialConfiguration = memorialConfiguration;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,67 @@
|
||||
package eu.mhsl.minenet.minigames.score.tournament;
|
||||
|
||||
import eu.mhsl.minenet.minigames.Resource;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.MineNetInstance;
|
||||
import eu.mhsl.minenet.minigames.instance.Spawnable;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.AnvilLoader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TournamentDisplay extends MineNetInstance implements Spawnable {
|
||||
private final List<Player> places;
|
||||
private final Tournament tournament;
|
||||
|
||||
private final Pos[] placePositions = new Pos[] {
|
||||
new Pos(8.5, -57, 21.5, 180, 0),
|
||||
new Pos(9.5, -58, 21.5, 180, 0),
|
||||
new Pos(7.5, -59, 21.5, 180, 0)
|
||||
};
|
||||
|
||||
public TournamentDisplay(Tournament tournament) {
|
||||
super(Dimension.OVERWORLD.DIMENSION);
|
||||
setChunkLoader(new AnvilLoader(Resource.RESULT_DISPLAY.getPath()));
|
||||
this.places = tournament.getPlaces();
|
||||
this.tournament = tournament;
|
||||
|
||||
eventNode().addListener(PlayerMoveEvent.class, playerMoveEvent -> {
|
||||
if(isOnDisplay(playerMoveEvent.getPlayer()) && !playerMoveEvent.getNewPosition().sameBlock(placePositions[getRankPosition(playerMoveEvent.getPlayer())])) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isOnDisplay(Player player) {
|
||||
if(getRankPosition(player) == -1) return false;
|
||||
return getRankPosition(player) < this.placePositions.length;
|
||||
}
|
||||
|
||||
private int getRankPosition(Player player) {
|
||||
return this.places.indexOf(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPlayerJoin(Player p) {
|
||||
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> {
|
||||
if(isOnDisplay(p)) {
|
||||
p.sendMessage("You are on Display!");
|
||||
p.teleport(placePositions[getRankPosition(p)]);
|
||||
}
|
||||
});
|
||||
new ChatMessage(Icon.STAR)
|
||||
.numberedList(this.places.stream().map(player -> String.format("%s - %s Punkte", player.getUsername(), tournament.getGameScores().get(player))).toList())
|
||||
.send(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(8.5, -55, 8.5);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user