42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
package xyz.stachel.zombiesutils.game;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
class GameFile extends File {
|
|
private FileWriter writer;
|
|
|
|
GameFile(@NotNull final String serverNumber) {
|
|
super(new File("zombies", "runs"), formattedTime() + "_" + serverNumber + ".seg2");
|
|
}
|
|
|
|
private static String formattedTime() {
|
|
final LocalDateTime dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
|
|
return dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace(':', '-').replaceFirst("T", "_");
|
|
}
|
|
|
|
void init() throws IOException {
|
|
if (!this.exists()) {
|
|
this.getParentFile().mkdirs();
|
|
this.createNewFile();
|
|
}
|
|
if (this.isFile()) {
|
|
this.setWritable(true);
|
|
}
|
|
this.writer = new FileWriter(this);
|
|
}
|
|
|
|
void addSplit(final long ticks) throws IOException {
|
|
this.writer.append(String.format("%d", ticks));
|
|
}
|
|
|
|
void clean() throws IOException {
|
|
this.writer.close();
|
|
}
|
|
}
|