Archiviert
1
0

Update some stuff

Dieser Commit ist enthalten in:
yoyosource 2022-04-04 20:00:21 +02:00
Ursprung c2219dec4e
Commit 350ac8b66f

Datei anzeigen

@ -24,18 +24,16 @@ import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.comms.packets.FightEndsPacket;
import de.steamwar.bungeecore.sql.*;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.config.ServerInfo;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
public class FightEndsHandler implements SpigotHandler {
private Map<String, List<Game>> gameModeGames = new HashMap<>();
private int K = 20;
private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */;
private Map<String, Long> fightRanges = new HashMap<>();
@ -82,9 +80,13 @@ public class FightEndsHandler implements SpigotHandler {
}
}
try {
if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) {
return;
}
} finally {
gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new ArrayList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers()));
}
int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem());
int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem());
@ -118,28 +120,27 @@ public class FightEndsHandler implements SpigotHandler {
}
private boolean teamComboExistedAlready(List<Integer> bluePlayers, List<Integer> redPlayers, String gameMode) {
long time = Timestamp.from(Instant.now()).getTime() - fightRanges.getOrDefault(gameMode, defaultFightRange);
int page = 0;
do {
List<Fight> fightsPage = Fight.getPage(page, 32);
if (fightsPage.isEmpty()) {
if (!gameModeGames.containsKey(gameMode)) {
return false;
}
for (Fight fight : fightsPage) {
if (!gameMode.equals(fight.getGameMode().getSchemType())) continue;
if (fight.getStartTime().getTime() < time) return false;
if (fight.getBluePlayers().stream()
.map(FightPlayer::getUserID)
.collect(Collectors.toList())
.containsAll(bluePlayers)
&& fight.getRedPlayers().stream()
.map(FightPlayer::getUserID)
.collect(Collectors.toList())
.containsAll(redPlayers)) {
return true;
List<Game> games = gameModeGames.get(gameMode);
long lifetime = fightRanges.getOrDefault(gameMode, defaultFightRange);
games.removeIf(game -> game.livedMillis() > lifetime);
return games.stream().anyMatch(game -> game.isSame(bluePlayers, redPlayers));
}
@RequiredArgsConstructor
private static class Game {
private long time = System.currentTimeMillis();
private final List<Integer> bluePlayers;
private final List<Integer> redPlayers;
public long livedMillis() {
return System.currentTimeMillis() - time;
}
public boolean isSame(List<Integer> bluePlayers, List<Integer> redPlayers) {
return bluePlayers.containsAll(this.bluePlayers) && redPlayers.containsAll(this.redPlayers);
}
page++;
} while (true);
}
}