From 21a2be5a431b94aeadb640d9ceced0620728699e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jan 2020 08:45:01 +0100 Subject: [PATCH] Adding statistics backend --- .../src/de/steamwar/sql/Fight.java | 24 +++++++++++++++++++ .../src/de/steamwar/sql/FightPlayer.java | 11 +++++++++ 2 files changed, 35 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/Fight.java create mode 100644 SpigotCore_Main/src/de/steamwar/sql/FightPlayer.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/Fight.java b/SpigotCore_Main/src/de/steamwar/sql/Fight.java new file mode 100644 index 0000000..54c2213 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/Fight.java @@ -0,0 +1,24 @@ +package de.steamwar.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; + +public class Fight { + private Fight(){} + + public static int create(String gamemode, String arena, Timestamp starttime, int duration, int blueleader, int redleader, int blueschem, int redschem, int win, String wincondition){ + SQL.update("INSERT INTO Fight (GameMode, Arena, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition) VALUES (" + + "'" + SQL.disarmString(gamemode) + "', '" + SQL.disarmString(arena) + "', '" + starttime.toString() + "', " + duration + ", " + blueleader + ", " + redleader + ", " + blueschem + ", " + redschem + ", " + win + ", '" + SQL.disarmString(wincondition) + "'" + + ")"); + ResultSet rs = SQL.select("SELECT LAST_INSERT_ID() AS FightID"); + try{ + if(!rs.next()) + throw new SecurityException("No last insert id"); + + return rs.getInt("FightID"); + } catch (SQLException e) { + throw new SecurityException(e); + } + } +} diff --git a/SpigotCore_Main/src/de/steamwar/sql/FightPlayer.java b/SpigotCore_Main/src/de/steamwar/sql/FightPlayer.java new file mode 100644 index 0000000..e5a98b2 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/FightPlayer.java @@ -0,0 +1,11 @@ +package de.steamwar.sql; + +public class FightPlayer { + private FightPlayer(){} + + public static void create(int fightID, int userID, String kit, int kills, boolean isOut){ + SQL.update("INSERT INTO FightPlayer (FightID, UserID, Kit, Kills, IsOut) VALUES (" + + fightID + ", " + userID + ", '" + SQL.disarmString(kit) + "', " + kills + ", " + SQL.booleanToInt(isOut) + + ")"); + } +}