From cbc1dd6505038fb5e7de1a6194c99e0bce6d97a2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 10:55:29 +0200 Subject: [PATCH 01/13] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 8 ++++---- src/de/steamwar/bungeecore/sql/UserElo.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 0dda622..b563a7f 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -23,10 +23,7 @@ import com.google.common.io.ByteArrayDataInput; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.comms.SpigotHandler; import de.steamwar.bungeecore.comms.packets.FightEndsPacket; -import de.steamwar.bungeecore.sql.SchemElo; -import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SchematicType; -import de.steamwar.bungeecore.sql.UserElo; +import de.steamwar.bungeecore.sql.*; import net.md_5.bungee.api.config.ServerInfo; import java.util.List; @@ -66,6 +63,8 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } + // TODO: Implement hourly unranked when against same team maybe half hourly + int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); @@ -84,6 +83,7 @@ public class FightEndsHandler implements SpigotHandler { double winTeamExpectation = 1 / (1 + Math.pow(10, (eloTeamEnemy - eloTeamOwn) / 600f)); for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); + int fights = UserElo.getFightsOfSeason(player, gameMode); UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation))); } } diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 6740966..efa0078 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -56,7 +56,7 @@ public class UserElo { }, userID, gameMode, Season.getSeason())); } - private static int getFightsOfSeason(int userID, String gameMode) { + public static int getFightsOfSeason(int userID, String gameMode) { return fightsOfSeason.select(rs -> { if (rs.next()) return rs.getInt("Fights"); From bbd2b1950b22473d9ad671f15529415c84f30560 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:05:41 +0200 Subject: [PATCH 02/13] Update FightEndsHandler --- .../steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index b563a7f..b0f5962 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -84,7 +84,8 @@ public class FightEndsHandler implements SpigotHandler { for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); int fights = UserElo.getFightsOfSeason(player, gameMode); - UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation))); + double multiplier = Math.max(1.2 - (fights / 200.0), 0.8); + UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation) * multiplier)); } } } From 895ac9843b63dde7caaa2c743578ac7d629b4ed6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:19:56 +0200 Subject: [PATCH 03/13] Update FightEndsHandler --- .../comms/handlers/FightEndsHandler.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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); + } } From a26e3994a3871fbaf1da8b81ed1925bd13222766 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:23:08 +0200 Subject: [PATCH 04/13] Fix FightEndsHandler --- src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 47e3f89..f90996f 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -104,7 +104,7 @@ public class FightEndsHandler implements SpigotHandler { return false; } for (Fight fight : fightsPage) { - if (!fight.getGameMode().getSchemType().equals(gameMode)) continue; + 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)) { if (fight.getRedPlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(redPlayers)) { From 8ce2b9ab71e354f0a140ec2301da9c0be584a71e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 13:11:48 +0200 Subject: [PATCH 05/13] Fix FightEndsHandler.fightRange --- src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index f90996f..62c7a87 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -34,7 +34,7 @@ import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { private int K = 20; - private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 30 /* Minutes */; + private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; @Override public void handle(ByteArrayDataInput in, ServerInfo info) { From b5528a6c602bb74956c2f11a2ee7a1b44cb1270b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 13:26:05 +0200 Subject: [PATCH 06/13] Update some stuff --- .../comms/handlers/FightEndsHandler.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 62c7a87..9b28bed 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -82,19 +82,26 @@ public class FightEndsHandler implements SpigotHandler { } private void calculateEloOfTeam(int schemId, int eloSchemOwn, int eloSchemEnemy, int eloTeamOwn, int eloTeamEnemy, double result, List players, String gameMode, boolean noPlayerRank) { - double winSchemExpectation = 1 / (1 + Math.pow(10, (eloSchemEnemy - eloSchemOwn) / 600f)); + double winSchemExpectation = calsWinExpectation(eloSchemOwn, eloSchemEnemy); SchemElo.setElo(schemId, (int) Math.round(eloSchemOwn + K * (result - winSchemExpectation))); if (noPlayerRank) return; - double winTeamExpectation = 1 / (1 + Math.pow(10, (eloTeamEnemy - eloTeamOwn) / 600f)); + double winTeamExpectation = calsWinExpectation(eloTeamOwn, eloTeamEnemy); for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); int fights = UserElo.getFightsOfSeason(player, gameMode); - double multiplier = Math.max(1.2 - (fights / 200.0), 0.8); - UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation) * multiplier)); + UserElo.setElo(player, gameMode, (int) Math.round(playerElo + getK(fights) * (result - winTeamExpectation))); } } + private double calsWinExpectation(int eloOwn, int eloEnemy) { + return 1 / (1 + Math.pow(10, (eloEnemy - eloOwn) / 600f)); + } + + private double getK(int fights) { + return K * Math.max(1.2 - (fights / 200.0), 0.8); + } + private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { long time = Timestamp.from(Instant.now()).getTime() - fightRange; int page = 0; From 200c8eb17e5cfef89c0faa73db60bc9ecd1867bb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 15:13:22 +0200 Subject: [PATCH 07/13] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 9b28bed..9e58dcc 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -28,13 +28,19 @@ 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.stream.Collectors; public class FightEndsHandler implements SpigotHandler { private int K = 20; - private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; + private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; + private Map fightRanges = new HashMap<>(); + { + fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 10L /* Minutes */); + } @Override public void handle(ByteArrayDataInput in, ServerInfo info) { @@ -103,7 +109,7 @@ public class FightEndsHandler implements SpigotHandler { } private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { - long time = Timestamp.from(Instant.now()).getTime() - fightRange; + long time = Timestamp.from(Instant.now()).getTime() - fightRanges.getOrDefault(gameMode, defaultFightRange); int page = 0; do { List fightsPage = Fight.getPage(page, 32); From 738189593dd8b97a8b142d0862896755b9295338 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 15:31:45 +0200 Subject: [PATCH 08/13] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 9e58dcc..4f0f2c3 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -31,6 +31,7 @@ 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; public class FightEndsHandler implements SpigotHandler { @@ -38,6 +39,7 @@ public class FightEndsHandler implements SpigotHandler { private int K = 20; private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; private Map fightRanges = new HashMap<>(); + { fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 10L /* Minutes */); } @@ -73,6 +75,13 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } + Set teamsIds = fightEndsPacket.getBluePlayers().stream().map(SteamwarUser::get).map(SteamwarUser::getTeam).collect(Collectors.toSet()); + for (int redPlayer : fightEndsPacket.getRedPlayers()) { + if (teamsIds.contains(SteamwarUser.get(redPlayer).getTeam())) { + return; + } + } + if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { return; } From c4523521f70b6c02f0bf5086d8755734d3036433 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 15:57:42 +0200 Subject: [PATCH 09/13] Update some stuff --- src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 4f0f2c3..cda7737 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -114,7 +114,7 @@ public class FightEndsHandler implements SpigotHandler { } private double getK(int fights) { - return K * Math.max(1.2 - (fights / 200.0), 0.8); + return K * Math.max(1.3 - (fights / 200.0), 0.8); } private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { From c2219dec4e53cbce621181288b97c401806bb9b6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 4 Apr 2022 18:23:18 +0200 Subject: [PATCH 10/13] Update stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index cda7737..7392d04 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -128,10 +128,15 @@ public class FightEndsHandler implements SpigotHandler { 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)) { - if (fight.getRedPlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(redPlayers)) { - return true; - } + 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; } } page++; From 350ac8b66fc5179deabec9ecca815ca62f0d161a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 4 Apr 2022 20:00:21 +0200 Subject: [PATCH 11/13] Update some stuff --- .../comms/handlers/FightEndsHandler.java | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 7392d04..f86eacf 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -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> gameModeGames = new HashMap<>(); + private int K = 20; private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; private Map fightRanges = new HashMap<>(); @@ -82,8 +80,12 @@ public class FightEndsHandler implements SpigotHandler { } } - if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { - return; + 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()); @@ -118,28 +120,27 @@ public class FightEndsHandler implements SpigotHandler { } private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { - long time = Timestamp.from(Instant.now()).getTime() - fightRanges.getOrDefault(gameMode, defaultFightRange); - int page = 0; - do { - List fightsPage = Fight.getPage(page, 32); - if (fightsPage.isEmpty()) { - 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; - } - } - page++; - } while (true); + if (!gameModeGames.containsKey(gameMode)) { + return false; + } + List 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 bluePlayers; + private final List redPlayers; + + public long livedMillis() { + return System.currentTimeMillis() - time; + } + + public boolean isSame(List bluePlayers, List redPlayers) { + return bluePlayers.containsAll(this.bluePlayers) && redPlayers.containsAll(this.redPlayers); + } } } From 9a0b3a41b909c87a061b56f43e3b86933cdd4ea1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 6 Apr 2022 16:59:11 +0200 Subject: [PATCH 12/13] Update some stuff --- .../comms/handlers/FightEndsHandler.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index f86eacf..03fae60 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -32,14 +32,18 @@ import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { - private Map> gameModeGames = new HashMap<>(); + private Map> gameModeGames = new HashMap<>(); private int K = 20; + private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; private Map fightRanges = new HashMap<>(); + private long defaultFightCount = 1; + private Map fightCounts = new HashMap<>(); { - fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 10L /* Minutes */); + fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 30L /* Minutes */); + fightCounts.put("miniwargear", 3L); } @Override @@ -73,6 +77,8 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } + // Die nächsten Zeilen filtern ein Fight innerhalb eines Teams nicht gewertet wird, bzw auch wenn nur Teile beider Teams im + // gleichen Team sind dieser ungewertet ist. Set teamsIds = fightEndsPacket.getBluePlayers().stream().map(SteamwarUser::get).map(SteamwarUser::getTeam).collect(Collectors.toSet()); for (int redPlayer : fightEndsPacket.getRedPlayers()) { if (teamsIds.contains(SteamwarUser.get(redPlayer).getTeam())) { @@ -85,7 +91,7 @@ public class FightEndsHandler implements SpigotHandler { return; } } finally { - gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new ArrayList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers())); + gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new LinkedList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers())); } int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); @@ -126,7 +132,7 @@ public class FightEndsHandler implements SpigotHandler { List 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)); + return games.stream().filter(game -> game.isSame(bluePlayers, redPlayers)).count() > fightCounts.getOrDefault(gameMode, defaultFightCount); } @RequiredArgsConstructor From 169d26852c9b902193caa4f231af982fff114769 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 6 Apr 2022 17:01:33 +0200 Subject: [PATCH 13/13] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 03fae60..b9a7492 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -129,9 +129,16 @@ public class FightEndsHandler implements SpigotHandler { if (!gameModeGames.containsKey(gameMode)) { return false; } - List games = gameModeGames.get(gameMode); + LinkedList games = gameModeGames.get(gameMode); long lifetime = fightRanges.getOrDefault(gameMode, defaultFightRange); - games.removeIf(game -> game.livedMillis() > lifetime); + while (!games.isEmpty()) { + Game game = games.getFirst(); + if (game.livedMillis() > lifetime) { + games.removeFirst(); + } else { + break; + } + } return games.stream().filter(game -> game.isSame(bluePlayers, redPlayers)).count() > fightCounts.getOrDefault(gameMode, defaultFightCount); }