From afa9b4e533f65f51d9486384a12d53387dfe6d82 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:28:05 +0200 Subject: [PATCH 1/4] Add Replay --- src/de/steamwar/bungeecore/sql/Fight.java | 6 ++--- src/de/steamwar/bungeecore/sql/Replay.java | 31 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/de/steamwar/bungeecore/sql/Replay.java diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 514946d..e17dcbf 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; public class Fight { - private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win, f.Replay IS NOT NULL AS ReplayExists FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); + private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); private final int fightID; private final String gameMode; @@ -22,7 +22,6 @@ public class Fight { private final int redLeader; private final int win; - private final boolean replayExists; private final boolean replayAllowed; private final List bluePlayers = new ArrayList<>(); @@ -37,7 +36,6 @@ public class Fight { redLeader = rs.getInt("RedLeader"); replayAllowed = rs.getBoolean("ReplayAllowed"); win = rs.getInt("Win"); - replayExists = rs.getBoolean("ReplayExists"); } private void initPlayers(List fightPlayers) { @@ -118,6 +116,6 @@ public class Fight { } public boolean replayExists() { - return replayExists && getGameMode() != null; + return Replay.hasReplay(fightID) && getGameMode() != null; } } diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java new file mode 100644 index 0000000..6c0bab2 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/Replay.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.sql; + +import java.sql.ResultSet; + +public class Replay { + + private static final Statement hasReplay = new Statement("SELECT * FROM Replay WHERE id = ?"); + + public static boolean hasReplay(int id) { + return hasReplay.select(ResultSet::next, id); + } +} -- 2.39.2 From 4bdead92b520ef2a02ed3c63d526db7dc48a9ba1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Apr 2022 21:30:52 +0200 Subject: [PATCH 2/4] Update some stuff --- src/de/steamwar/bungeecore/sql/Fight.java | 2 +- src/de/steamwar/bungeecore/sql/Replay.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index e17dcbf..4fd0b7d 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -116,6 +116,6 @@ public class Fight { } public boolean replayExists() { - return Replay.hasReplay(fightID) && getGameMode() != null; + return getGameMode() != null && Replay.hasReplay(fightID); } } diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java index 6c0bab2..188232a 100644 --- a/src/de/steamwar/bungeecore/sql/Replay.java +++ b/src/de/steamwar/bungeecore/sql/Replay.java @@ -23,7 +23,7 @@ import java.sql.ResultSet; public class Replay { - private static final Statement hasReplay = new Statement("SELECT * FROM Replay WHERE id = ?"); + private static final Statement hasReplay = new Statement("SELECT FightID FROM Replay WHERE FightID = ?"); public static boolean hasReplay(int id) { return hasReplay.select(ResultSet::next, id); -- 2.39.2 From 7a48584cbb2d5440b008eb08c8290f0d33b92a2b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Apr 2022 21:36:18 +0200 Subject: [PATCH 3/4] Update some stuff --- src/de/steamwar/bungeecore/sql/Replay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java index 188232a..a4f2651 100644 --- a/src/de/steamwar/bungeecore/sql/Replay.java +++ b/src/de/steamwar/bungeecore/sql/Replay.java @@ -23,7 +23,7 @@ import java.sql.ResultSet; public class Replay { - private static final Statement hasReplay = new Statement("SELECT FightID FROM Replay WHERE FightID = ?"); + private static final Statement hasReplay = new Statement("SELECT 1 FROM Replay WHERE FightID = ?"); public static boolean hasReplay(int id) { return hasReplay.select(ResultSet::next, id); -- 2.39.2 From fa5d4ad983463e412bf5178adfee9e32388fa4d8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Apr 2022 22:08:17 +0200 Subject: [PATCH 4/4] Update some stuff --- src/de/steamwar/bungeecore/sql/Fight.java | 6 +++-- src/de/steamwar/bungeecore/sql/Replay.java | 31 ---------------------- 2 files changed, 4 insertions(+), 33 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/Replay.java diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 4fd0b7d..e13b787 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; public class Fight { - private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); + private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win, (SELECT COUNT(1) FROM Replay WHERE Replay.FightID = f.FightID) as ReplayAvailable FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); private final int fightID; private final String gameMode; @@ -23,6 +23,7 @@ public class Fight { private final int win; private final boolean replayAllowed; + private final boolean replayAvailable; private final List bluePlayers = new ArrayList<>(); private final List redPlayers = new ArrayList<>(); @@ -35,6 +36,7 @@ public class Fight { blueLeader = rs.getInt("BlueLeader"); redLeader = rs.getInt("RedLeader"); replayAllowed = rs.getBoolean("ReplayAllowed"); + replayAvailable = rs.getBoolean("ReplayAvailable"); win = rs.getInt("Win"); } @@ -116,6 +118,6 @@ public class Fight { } public boolean replayExists() { - return getGameMode() != null && Replay.hasReplay(fightID); + return getGameMode() != null && replayAvailable; } } diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java deleted file mode 100644 index a4f2651..0000000 --- a/src/de/steamwar/bungeecore/sql/Replay.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.sql; - -import java.sql.ResultSet; - -public class Replay { - - private static final Statement hasReplay = new Statement("SELECT 1 FROM Replay WHERE FightID = ?"); - - public static boolean hasReplay(int id) { - return hasReplay.select(ResultSet::next, id); - } -} -- 2.39.2