From 530171c2e32cd28eb0caa4a646ec59e522b9ad07 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 10:12:03 +0100 Subject: [PATCH] Update UserElo --- .../bungeecore/comms/handlers/FightEndsHandler.java | 4 ++-- src/de/steamwar/bungeecore/sql/UserElo.java | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index bf65892b..d98ddd3d 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -73,11 +73,11 @@ public class FightEndsHandler implements SpigotHandler { if (blueSchemOwner != 0 && redSchemOwner != 0) { for (int bluePlayer : fightEndsPacket.getBluePlayers()) { - int playerElo = UserElo.getElo(bluePlayer, fightEndsPacket.getGameMode()); + int playerElo = UserElo.getElo(bluePlayer, fightEndsPacket.getGameMode()).orElse(1000); UserElo.setElo(bluePlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (blueResult - blueWinExpectation))); } for (int redPlayer : fightEndsPacket.getRedPlayers()) { - int playerElo = UserElo.getElo(redPlayer, fightEndsPacket.getGameMode()); + int playerElo = UserElo.getElo(redPlayer, fightEndsPacket.getGameMode()).orElse(1000); UserElo.setElo(redPlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (1 - blueResult - redWinExpectation))); } } diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 1d45f44f..c2c4be75 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -19,6 +19,8 @@ package de.steamwar.bungeecore.sql; +import java.util.Optional; + public class UserElo { private UserElo() { } @@ -27,15 +29,15 @@ 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 = ?"); - public static int getElo(int userID, String gameMode) { + public static Optional getElo(int userID, String gameMode) { return getElo(Season.getSeason(), userID, gameMode); } - public static int getElo(int season, int userID, String gameMode) { + public static Optional getElo(int season, int userID, String gameMode) { return elo.select(rs -> { if (rs.next()) - return rs.getInt("Elo"); - return 1000; + return Optional.of(rs.getInt("Elo")); + return Optional.empty(); }, userID, gameMode, season); }