forked from SteamWar/SteamWar
Move Replays to File system
This commit is contained in:
@@ -20,15 +20,18 @@
|
||||
package de.steamwar.fightsystem.record;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.sql.Replay;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class FileSource extends PacketSource {
|
||||
|
||||
public static File replayFile(int fightId) {
|
||||
return new File("/mnt/storage/replays", fightId + ".replay");
|
||||
}
|
||||
|
||||
public static void startReplay() {
|
||||
if(Config.replayserver()) {
|
||||
try {
|
||||
@@ -41,7 +44,7 @@ public class FileSource extends PacketSource {
|
||||
|
||||
if(Config.ReplayID > 0) {
|
||||
try {
|
||||
new FileSource(Replay.get(Config.ReplayID).getReplay());
|
||||
new FileSource(replayFile(Config.ReplayID));
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not start replay", e);
|
||||
}
|
||||
@@ -49,7 +52,7 @@ public class FileSource extends PacketSource {
|
||||
}
|
||||
|
||||
public FileSource(File fightFile) throws IOException {
|
||||
super(new GZIPInputStream(new FileInputStream(fightFile)));
|
||||
super(new GZIPInputStream(Files.newInputStream(fightFile.toPath())));
|
||||
new PacketProcessor(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,23 +27,25 @@ import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.record.FileRecorder;
|
||||
import de.steamwar.fightsystem.record.FileSource;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.winconditions.Wincondition;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
import de.steamwar.network.packets.common.FightEndsPacket;
|
||||
import de.steamwar.sql.Replay;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.steamwar.sql.Fight.create;
|
||||
import static de.steamwar.sql.Fight.markReplayAvailable;
|
||||
|
||||
public class FightStatistics {
|
||||
|
||||
@@ -125,7 +127,10 @@ public class FightStatistics {
|
||||
}
|
||||
|
||||
try {
|
||||
Replay.save(fightId, FileRecorder.getFile());
|
||||
if(!FileRecorder.getFile().renameTo(FileSource.replayFile(fightId)))
|
||||
throw new IOException("Failed to move replay");
|
||||
|
||||
markReplayAvailable(fightId);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user