From cbc1dd6505038fb5e7de1a6194c99e0bce6d97a2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 10:55:29 +0200 Subject: [PATCH 01/33] 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/33] 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/33] 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/33] 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 afa9b4e533f65f51d9486384a12d53387dfe6d82 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:28:05 +0200 Subject: [PATCH 05/33] Add Replay --- src/de/steamwar/bungeecore/sql/Fight.java | 6 ++--- src/de/steamwar/bungeecore/sql/Replay.java | 31 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/de/steamwar/bungeecore/sql/Replay.java diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 514946d..e17dcbf 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; public class Fight { - private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win, f.Replay IS NOT NULL AS ReplayExists FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); + private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); private final int fightID; private final String gameMode; @@ -22,7 +22,6 @@ public class Fight { private final int redLeader; private final int win; - private final boolean replayExists; private final boolean replayAllowed; private final List bluePlayers = new ArrayList<>(); @@ -37,7 +36,6 @@ public class Fight { redLeader = rs.getInt("RedLeader"); replayAllowed = rs.getBoolean("ReplayAllowed"); win = rs.getInt("Win"); - replayExists = rs.getBoolean("ReplayExists"); } private void initPlayers(List fightPlayers) { @@ -118,6 +116,6 @@ public class Fight { } public boolean replayExists() { - return replayExists && getGameMode() != null; + return Replay.hasReplay(fightID) && getGameMode() != null; } } diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java new file mode 100644 index 0000000..6c0bab2 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/Replay.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.sql; + +import java.sql.ResultSet; + +public class Replay { + + private static final Statement hasReplay = new Statement("SELECT * FROM Replay WHERE id = ?"); + + public static boolean hasReplay(int id) { + return hasReplay.select(ResultSet::next, id); + } +} From 8ce2b9ab71e354f0a140ec2301da9c0be584a71e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 13:11:48 +0200 Subject: [PATCH 06/33] 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 07/33] 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 08/33] 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 09/33] 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 10/33] 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 11/33] 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 12/33] 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 39926d8767b4986956384bb30a1cc22239dd8349 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 4 Apr 2022 22:59:30 +0200 Subject: [PATCH 13/33] :art: Yeet --- .../bot/util/DiscordTicketMessage.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java index ea6cea3..21ebded 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.bot.util; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; +import de.steamwar.bungeecore.bot.config.DiscordTicketType; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.EmbedBuilder; @@ -32,6 +33,7 @@ import net.dv8tion.jda.api.interactions.components.Button; import java.awt.*; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @UtilityClass public class DiscordTicketMessage { @@ -49,16 +51,26 @@ public class DiscordTicketMessage { builder.setTitle("Steamwar-Tickets"); builder.setColor(Color.RED); - List