SteamWar/FightSystem
Archiviert
13
1

DB-Replayintegration

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-08-21 21:09:57 +02:00
Ursprung e52885b126
Commit 20f3b609cb
5 geänderte Dateien mit 49 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -30,10 +30,7 @@ import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.fight.IFight;
import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.Shutdown;
import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.record.FileRecorder; import de.steamwar.fightsystem.record.*;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.record.LiveRecorder;
import de.steamwar.fightsystem.record.PacketProcessor;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.EnterHandler; import de.steamwar.fightsystem.utils.EnterHandler;
@ -109,7 +106,6 @@ public class FightSystem extends JavaPlugin {
new RankedPlayerLeftWincondition(); new RankedPlayerLeftWincondition();
new WinconditionPercentTimeout(); new WinconditionPercentTimeout();
//noinspection InstantiationOfUtilityClass
new HellsBells(); new HellsBells();
new NoPlayersOnlineCountdown(); new NoPlayersOnlineCountdown();
@ -160,6 +156,7 @@ public class FightSystem extends JavaPlugin {
} }
}else if(Config.mode == ArenaMode.REPLAY) { }else if(Config.mode == ArenaMode.REPLAY) {
FightWorld.forceLoad(); FightWorld.forceLoad();
FileSource.startReplay();
} }
} }
@ -192,16 +189,17 @@ public class FightSystem extends JavaPlugin {
} }
public static void setSpectateState(FightTeam winFightTeam, String windescription) { public static void setSpectateState(FightTeam winFightTeam, String windescription) {
FightState.setFightState(FightState.SPECTATE); if(!PacketProcessor.isReplaying()){
if(PacketProcessor.isReplaying())
return;
if(winFightTeam != null) { if(winFightTeam != null) {
Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!");
} else { } else {
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
} }
}
FightState.setFightState(FightState.SPECTATE);
if(!Config.test() && !PacketProcessor.isReplaying()){
if(Config.mode == ArenaMode.EVENT) { if(Config.mode == ArenaMode.EVENT) {
if (winFightTeam == null) if (winFightTeam == null)
getEventFight().setErgebnis(0); getEventFight().setErgebnis(0);
@ -211,7 +209,6 @@ public class FightSystem extends JavaPlugin {
getEventFight().setErgebnis(2); getEventFight().setErgebnis(2);
} }
if(!Config.test()){
FightStatistics.saveStats(winFightTeam, windescription); FightStatistics.saveStats(winFightTeam, windescription);
} }
} }

Datei anzeigen

@ -37,7 +37,7 @@ public class FileRecorder extends StateDependent implements Recorder {
} }
public FileRecorder(){ public FileRecorder(){
super(ArenaMode.AntiReplay, FightState.Schem); super(ArenaMode.AntiReplay, FightState.Recording);
} }
@Override @Override

Datei anzeigen

@ -19,17 +19,35 @@
package de.steamwar.fightsystem.record; package de.steamwar.fightsystem.record;
import de.steamwar.fightsystem.Config;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
public class FileSource extends PacketSource { public class FileSource extends PacketSource {
public static void startReplay() {
if(Config.replayserver())
return;
try {
Files.copy(
de.steamwar.sql.Fight.getReplay(Config.ReplayID),
FileRecorder.getFile().toPath(),
StandardCopyOption.REPLACE_EXISTING);
new FileSource(FileRecorder.getFile());
} catch (IOException e) {
throw new SecurityException("Could not start replay", e);
}
}
public FileSource(File fightFile) throws IOException { public FileSource(File fightFile) throws IOException {
super(new DataInputStream(new GZIPInputStream(new FileInputStream(fightFile)))); super(new DataInputStream(new GZIPInputStream(new FileInputStream(fightFile))));
} }

Datei anzeigen

@ -42,6 +42,7 @@ public enum FightState {
public static final Set<FightState> Ingame = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING)); public static final Set<FightState> Ingame = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING));
public static final Set<FightState> TeamFix = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING, SPECTATE)); public static final Set<FightState> TeamFix = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING, SPECTATE));
public static final Set<FightState> Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP))); public static final Set<FightState> Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP)));
public static final Set<FightState> Recording = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, SPECTATE)));
public static final Set<FightState> AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING))); public static final Set<FightState> AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING)));
public static final Set<FightState> AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE))); public static final Set<FightState> AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE)));

Datei anzeigen

@ -19,23 +19,27 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.FileRecorder;
import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.fightsystem.winconditions.Wincondition;
import de.steamwar.sql.Elo; import de.steamwar.sql.Elo;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.nio.file.Files;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.logging.Level; import java.util.logging.Level;
import static de.steamwar.sql.Fight.create; import static de.steamwar.sql.Fight.create;
import static de.steamwar.sql.Fight.setReplay;
public class FightStatistics { public class FightStatistics {
private FightStatistics(){} private FightStatistics(){}
@ -92,6 +96,12 @@ public class FightStatistics {
savePlayerStats(fp, fightId); savePlayerStats(fp, fightId);
for (FightPlayer fp : Fight.getRedTeam().getPlayers()) for (FightPlayer fp : Fight.getRedTeam().getPlayers())
savePlayerStats(fp, fightId); savePlayerStats(fp, fightId);
setReplay(fightId, Files.readAllBytes(FileRecorder.getFile().toPath()));
if(ArenaMode.Event.contains(Config.mode)){
FightSystem.getEventFight().setFight(fightId);
}
}catch(Exception e){ }catch(Exception e){
Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e);
} }