From c943520418152be24c4b5ceb497bed9989f8bebb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jul 2020 18:48:24 +0200 Subject: [PATCH] Implementing Elo database connection --- SpigotCore_Main/src/de/steamwar/sql/Elo.java | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/Elo.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/Elo.java b/SpigotCore_Main/src/de/steamwar/sql/Elo.java new file mode 100644 index 0000000..b28ca8a --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/Elo.java @@ -0,0 +1,23 @@ +package de.steamwar.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class Elo { + private Elo(){} + + public static int getElo(int userId, String gameMode){ + ResultSet rs = SQL.select("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ?", userId, gameMode); + try{ + if(!rs.next()) + return 1000; + return rs.getInt("Elo"); + }catch(SQLException e){ + throw new SecurityException("Could not get elo", e); + } + } + + public static void setElo(int userId, String gameMode, int elo){ + SQL.update("INSERT INTO Elo (UserID, GameMode, Elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)", userId, gameMode, elo); + } +}