diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index b0f5962..47e3f89 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -26,11 +26,15 @@ import de.steamwar.bungeecore.comms.packets.FightEndsPacket; import de.steamwar.bungeecore.sql.*; import net.md_5.bungee.api.config.ServerInfo; +import java.sql.Timestamp; +import java.time.Instant; import java.util.List; +import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { private int K = 20; + private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 30 /* Minutes */; @Override public void handle(ByteArrayDataInput in, ServerInfo info) { @@ -63,7 +67,9 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } - // TODO: Implement hourly unranked when against same team maybe half hourly + if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { + return; + } int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); @@ -88,4 +94,25 @@ public class FightEndsHandler implements SpigotHandler { UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation) * multiplier)); } } + + private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { + long time = Timestamp.from(Instant.now()).getTime() - fightRange; + int page = 0; + do { + List fightsPage = Fight.getPage(page, 32); + if (fightsPage.isEmpty()) { + return false; + } + for (Fight fight : fightsPage) { + if (!fight.getGameMode().getSchemType().equals(gameMode)) continue; + if (fight.getStartTime().getTime() < time) return false; + if (fight.getBluePlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(bluePlayers)) { + if (fight.getRedPlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(redPlayers)) { + return true; + } + } + } + page++; + } while (true); + } }