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,8 +80,12 @@ public class FightEndsHandler implements SpigotHandler {
} }
} }
if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { try {
return; 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 blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem());
@ -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; return false;
do { }
List<Fight> fightsPage = Fight.getPage(page, 32); List<Game> games = gameModeGames.get(gameMode);
if (fightsPage.isEmpty()) { long lifetime = fightRanges.getOrDefault(gameMode, defaultFightRange);
return false; games.removeIf(game -> game.livedMillis() > lifetime);
} return games.stream().anyMatch(game -> game.isSame(bluePlayers, redPlayers));
for (Fight fight : fightsPage) { }
if (!gameMode.equals(fight.getGameMode().getSchemType())) continue;
if (fight.getStartTime().getTime() < time) return false; @RequiredArgsConstructor
if (fight.getBluePlayers().stream() private static class Game {
.map(FightPlayer::getUserID) private long time = System.currentTimeMillis();
.collect(Collectors.toList()) private final List<Integer> bluePlayers;
.containsAll(bluePlayers) private final List<Integer> redPlayers;
&& fight.getRedPlayers().stream()
.map(FightPlayer::getUserID) public long livedMillis() {
.collect(Collectors.toList()) return System.currentTimeMillis() - time;
.containsAll(redPlayers)) { }
return true;
} public boolean isSame(List<Integer> bluePlayers, List<Integer> redPlayers) {
} return bluePlayers.containsAll(this.bluePlayers) && redPlayers.containsAll(this.redPlayers);
page++; }
} while (true);
} }
} }