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