SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Standalone TeamTeilnahme' (#175) from standaloneTeamTeilnahme into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #175
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2022-03-03 14:37:01 +01:00
Commit 189a209755
4 geänderte Dateien mit 54 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -47,6 +47,10 @@ public interface Provider {
void setEventFightResult(EventFight fight, int winner); void setEventFightResult(EventFight fight, int winner);
void setEventFightFightID(EventFight fight, int fightID); void setEventFightFightID(EventFight fight, int fightID);
boolean hasEventTeam(int teamID, int eventID);
Set<Team> getEventTeams(int eventID);
Set<Event> 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); 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<InputStream> reader); void getReplay(int fightID, Consumer<InputStream> reader);
void setReplay(int fightID, InputStream data); void setReplay(int fightID, InputStream data);

Datei anzeigen

@ -124,6 +124,34 @@ public class SQLProvider implements Provider {
setEventFightFightID.update(fight, fight.getFightID()); 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<Team> getEventTeams(int eventID) {
return eventTeams.select(rs -> {
Set<Team> 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<Event> getTeamEvents(int teamID) {
return eventsTeam.select(rs -> {
Set<Event> 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 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"); private static final Statement getLastFightID = new Statement("SELECT LAST_INSERT_ID() AS FightID");
@Override @Override

Datei anzeigen

@ -19,13 +19,15 @@
package de.steamwar.sql; package de.steamwar.sql;
import com.google.common.collect.Maps;
import de.steamwar.core.WorldEditWrapper; import de.steamwar.core.WorldEditWrapper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; 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.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -86,6 +88,21 @@ public class StandaloneProvider implements Provider {
@Override @Override
public void setEventFightFightID(EventFight fight, int fightID) {} public void setEventFightFightID(EventFight fight, int fightID) {}
@Override
public boolean hasEventTeam(int teamID, int eventID) {
return false;
}
@Override
public Set<Team> getEventTeams(int eventID) {
return Collections.emptySet();
}
@Override
public Set<Event> getTeamEvents(int teamID) {
return Collections.emptySet();
}
@Override @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) { 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; return 0;

Datei anzeigen

@ -19,36 +19,21 @@
package de.steamwar.sql; package de.steamwar.sql;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class TeamTeilnahme { public class TeamTeilnahme {
private 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){ public static boolean nimmtTeil(int teamID, int eventID){
return byEventTeam.select(ResultSet::next, teamID, eventID); return Provider.impl.hasEventTeam(teamID, eventID);
} }
public static Set<Team> getTeams(int eventID){ public static Set<Team> getTeams(int eventID){
return byEvent.select(rs -> { return Provider.impl.getEventTeams(eventID);
Set<Team> teams = new HashSet<>();
while(rs.next())
teams.add(Team.get(rs.getInt("TeamID")));
return teams;
}, eventID);
} }
public static Set<Event> getEvents(int teamID){ public static Set<Event> getEvents(int teamID){
return byTeam.select(rs -> { return Provider.impl.getTeamEvents(teamID);
Set<Event> events = new HashSet<>();
while(rs.next())
events.add(Event.get(rs.getInt("EventID")));
return events;
}, teamID);
} }
} }