SteamWar/SpigotCore
Archiviert
13
0

Standalone TeamTeilnahme #175

Zusammengeführt
Lixfel hat 1 Commits von standaloneTeamTeilnahme nach master 2022-03-03 14:37:01 +01:00 zusammengeführt
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 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);
void getReplay(int fightID, Consumer<InputStream> reader);
void setReplay(int fightID, InputStream data);

Datei anzeigen

@ -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<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 getLastFightID = new Statement("SELECT LAST_INSERT_ID() AS FightID");
@Override

Datei anzeigen

@ -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<Team> getEventTeams(int eventID) {
return Collections.emptySet();
}
@Override
public Set<Event> 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;

Datei anzeigen

@ -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<Team> getTeams(int eventID){
return byEvent.select(rs -> {
Set<Team> teams = new HashSet<>();
while(rs.next())
teams.add(Team.get(rs.getInt("TeamID")));
return teams;
}, eventID);
return Provider.impl.getEventTeams(eventID);
}
public static Set<Event> getEvents(int teamID){
return byTeam.select(rs -> {
Set<Event> events = new HashSet<>();
while(rs.next())
events.add(Event.get(rs.getInt("EventID")));
return events;
}, teamID);
return Provider.impl.getTeamEvents(teamID);
}
}