From aff6adc7e83021281533fe36fd04eb9b600aeefb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 24 Feb 2022 22:22:20 +0100 Subject: [PATCH] Standalone TeamTeilnahme --- .../src/de/steamwar/sql/Provider.java | 4 +++ .../src/de/steamwar/sql/SQLProvider.java | 28 +++++++++++++++++++ .../de/steamwar/sql/StandaloneProvider.java | 21 ++++++++++++-- .../src/de/steamwar/sql/TeamTeilnahme.java | 21 ++------------ 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Provider.java b/SpigotCore_Main/src/de/steamwar/sql/Provider.java index 3cdadcf..56737f5 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Provider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Provider.java @@ -47,6 +47,10 @@ public interface Provider { void setEventFightResult(EventFight fight, int winner); void setEventFightFightID(EventFight fight, int fightID); + boolean hasEventTeam(int teamID, int eventID); + Set getEventTeams(int eventID); + Set getTeamEvents(int teamID); + int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock); void getReplay(int fightID, Consumer reader); void setReplay(int fightID, InputStream data); diff --git a/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java b/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java index 999186a..e5aad72 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java @@ -124,6 +124,34 @@ public class SQLProvider implements Provider { setEventFightFightID.update(fight, fight.getFightID()); } + private static final Statement hasEventTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?"); + @Override + public boolean hasEventTeam(int teamID, int eventID) { + return hasEventTeam.select(ResultSet::next, teamID, eventID); + } + + private static final Statement eventTeams = new Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?"); + @Override + public Set getEventTeams(int eventID) { + return eventTeams.select(rs -> { + Set teams = new HashSet<>(); + while(rs.next()) + teams.add(Team.get(rs.getInt("TeamID"))); + return teams; + }, eventID); + } + + private static final Statement eventsTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?"); + @Override + public Set getTeamEvents(int teamID) { + return eventsTeam.select(rs -> { + Set events = new HashSet<>(); + while(rs.next()) + events.add(Event.get(rs.getInt("EventID"))); + return events; + }, teamID); + } + private static final Statement createFight = new Statement("INSERT INTO Fight (GameMode, Server, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition, ReplayLock) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); private static final Statement getLastFightID = new Statement("SELECT LAST_INSERT_ID() AS FightID"); @Override diff --git a/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java b/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java index 722a1a0..9c422f3 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java @@ -19,13 +19,15 @@ package de.steamwar.sql; -import com.google.common.collect.Maps; import de.steamwar.core.WorldEditWrapper; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import java.io.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.sql.Timestamp; @@ -86,6 +88,21 @@ public class StandaloneProvider implements Provider { @Override public void setEventFightFightID(EventFight fight, int fightID) {} + @Override + public boolean hasEventTeam(int teamID, int eventID) { + return false; + } + + @Override + public Set getEventTeams(int eventID) { + return Collections.emptySet(); + } + + @Override + public Set getTeamEvents(int teamID) { + return Collections.emptySet(); + } + @Override public int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock) { return 0; diff --git a/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java index 4a3dd5e..d10320a 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java +++ b/SpigotCore_Main/src/de/steamwar/sql/TeamTeilnahme.java @@ -19,36 +19,21 @@ package de.steamwar.sql; -import java.sql.ResultSet; -import java.util.HashSet; import java.util.Set; public class TeamTeilnahme { private TeamTeilnahme(){} - private static final Statement byEventTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?"); - private static final Statement byEvent = new Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?"); - private static final Statement byTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?"); public static boolean nimmtTeil(int teamID, int eventID){ - return byEventTeam.select(ResultSet::next, teamID, eventID); + return Provider.impl.hasEventTeam(teamID, eventID); } public static Set getTeams(int eventID){ - return byEvent.select(rs -> { - Set teams = new HashSet<>(); - while(rs.next()) - teams.add(Team.get(rs.getInt("TeamID"))); - return teams; - }, eventID); + return Provider.impl.getEventTeams(eventID); } public static Set getEvents(int teamID){ - return byTeam.select(rs -> { - Set events = new HashSet<>(); - while(rs.next()) - events.add(Event.get(rs.getInt("EventID"))); - return events; - }, teamID); + return Provider.impl.getTeamEvents(teamID); } }