From e26692fdd23fc22147faffaf1fca670b0dcb1872 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 11:12:30 +0100 Subject: [PATCH] Add UserElo.getFightsOfSeason Add Season.getSeasonStart --- src/de/steamwar/bungeecore/sql/Season.java | 5 +++++ src/de/steamwar/bungeecore/sql/UserElo.java | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/Season.java b/src/de/steamwar/bungeecore/sql/Season.java index b1d6bdc..86dd01c 100644 --- a/src/de/steamwar/bungeecore/sql/Season.java +++ b/src/de/steamwar/bungeecore/sql/Season.java @@ -30,6 +30,11 @@ public class Season { return (calendar.get(Calendar.YEAR) * 3 + yearIndex); } + public static String getSeasonStart() { + Calendar calendar = Calendar.getInstance(); + return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) / 3 * 3 + 1) + "-1"; + } + public static String convertSeasonToString(int season){ if (season == -1) return ""; int yearSeason = season % 3; diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index cdfeced..9c5fe89 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -45,6 +45,7 @@ public class UserElo { private static final Statement setElo = new Statement("UPDATE UserELo SET Elo = ? WHERE Season = ? AND UserID = ? AND GameMode = ?"); private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?"); 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(?)"); private static void clearCacheIfNeeded(int season) { int currentSeason = Season.getSeason(); @@ -55,7 +56,6 @@ public class UserElo { clearCache(); cachedSeason = currentSeason; } - return; } public static Optional getElo(int userID, String gameMode) { @@ -81,6 +81,14 @@ public class UserElo { }, userID, gameMode, season); } + public static int getFightsOfSeason(int userID, String gameMode) { + return fightsOfSeason.select(rs -> { + if (rs.next()) + return rs.getInt("Fights"); + return 0; + }, userID, gameMode, Season.getSeasonStart()); + } + public static int getMaxElo(String gameMode) { return getMaxElo(Season.getSeason(), gameMode); }