forked from Rashnain/SaveMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveSummary.java
More file actions
50 lines (42 loc) · 1.37 KB
/
SaveSummary.java
File metadata and controls
50 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.github.rashnain.savemod;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
public class SaveSummary {
private static final long ONE_MB = 1048576;
private final String saveFileName;
private final String worldDir;
private final long size;
private long lastPlayed = -1;
public SaveSummary(String saveFileName, String worldDir, long size) {
this.saveFileName = saveFileName;
this.worldDir = worldDir;
this.size = size;
}
public String getSaveFileName() {
return saveFileName;
}
public String getSaveName() {
return saveFileName.substring(20, saveFileName.length() - 4);
}
public String getWorldDir() {
return worldDir;
}
public long getLastPlayed() {
if (lastPlayed == -1) {
Date date;
try {
date = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss").parse(saveFileName);
} catch (ParseException e) {
SaveMod.LOGGER.error("Could not parse save date from '{}' : {}", saveFileName, e);
date = Date.from(Instant.EPOCH);
}
lastPlayed = date.getTime();
}
return lastPlayed;
}
public String getSizeInMB() {
return size < ONE_MB ? "< 1" : String.valueOf(size / ONE_MB);
}
}