From 0d7ebc224c34222a6d6a5c24409c7c5258a3d234 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 16:45:00 +0100 Subject: [PATCH] Update FightEndsHandler Update UserElo --- .../steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- src/de/steamwar/bungeecore/sql/UserElo.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index d54d2390..ee752877 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -85,7 +85,7 @@ public class FightEndsHandler implements SpigotHandler { private void calculateEloOfTeam(List team, String gameMode, double factor) { for (int player : team) { - int playerElo = UserElo.getElo(player, gameMode).orElse(ELO_DEFAULT); + int playerElo = UserElo.getEloOrDefault(player, gameMode); UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * factor)); } } diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index ff49289e..a216673d 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -41,6 +41,10 @@ public class UserElo { private static final Statement maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); private static final Statement fightsOfSeason = new Statement("SELECT COUNT(*) AS Fights FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode = ? AND UNIX_TIMESTAMP(StartTime) + Duration >= UNIX_TIMESTAMP(?)"); + public static int getEloOrDefault(int userID, String gameMode) { + return getElo(userID, gameMode).orElse(ELO_DEFAULT); + } + public static Optional getElo(int userID, String gameMode) { return gameModeUserEloCache.computeIfAbsent(gameMode, gm -> { return new HashMap<>();