SteamWar/BungeeCore
Archiviert
13
2

Update FightEndsHandler
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-04-01 12:19:56 +02:00
Ursprung bbd2b1950b
Commit 895ac9843b

Datei anzeigen

@ -26,11 +26,15 @@ import de.steamwar.bungeecore.comms.packets.FightEndsPacket;
import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.sql.*;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class FightEndsHandler implements SpigotHandler { public class FightEndsHandler implements SpigotHandler {
private int K = 20; private int K = 20;
private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 30 /* Minutes */;
@Override @Override
public void handle(ByteArrayDataInput in, ServerInfo info) { public void handle(ByteArrayDataInput in, ServerInfo info) {
@ -63,7 +67,9 @@ public class FightEndsHandler implements SpigotHandler {
blueResult = 0; 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 blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem());
int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); 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)); UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation) * multiplier));
} }
} }
private boolean teamComboExistedAlready(List<Integer> bluePlayers, List<Integer> redPlayers, String gameMode) {
long time = Timestamp.from(Instant.now()).getTime() - fightRange;
int page = 0;
do {
List<Fight> 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);
}
} }