From afa9b4e533f65f51d9486384a12d53387dfe6d82 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:28:05 +0200 Subject: [PATCH] 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 514946d6..e17dcbfd 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 00000000..6c0bab2c --- /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); + } +}