new version 1.3.3
This commit is contained in:
parent
2d5c5eea48
commit
d9eb747c1b
37 changed files with 1021 additions and 471 deletions
|
|
@ -9,11 +9,13 @@ import java.util.List;
|
|||
public class GhostData {
|
||||
|
||||
private final String playerName;
|
||||
private final String playerUUID;
|
||||
private final int score;
|
||||
private final List<GhostFrame> frames;
|
||||
|
||||
public GhostData(@NotNull String playerName, int score, @NotNull List<GhostFrame> frames) {
|
||||
public GhostData(@NotNull String playerName, @NotNull String playerUUID, int score, @NotNull List<GhostFrame> frames) {
|
||||
this.playerName = playerName;
|
||||
this.playerUUID = playerUUID;
|
||||
this.score = score;
|
||||
this.frames = new ArrayList<>(frames);
|
||||
}
|
||||
|
|
@ -22,6 +24,10 @@ public class GhostData {
|
|||
return playerName;
|
||||
}
|
||||
|
||||
public String getPlayerUUID() {
|
||||
return playerUUID;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
|
@ -33,6 +39,7 @@ public class GhostData {
|
|||
public void saveToFile(@NotNull File file) throws IOException {
|
||||
try (DataOutputStream out = new DataOutputStream(new FileOutputStream(file))) {
|
||||
out.writeUTF(playerName);
|
||||
out.writeUTF(playerUUID);
|
||||
out.writeInt(score);
|
||||
out.writeInt(frames.size());
|
||||
|
||||
|
|
@ -50,6 +57,7 @@ public class GhostData {
|
|||
public static GhostData loadFromFile(@NotNull File file) throws IOException {
|
||||
try (DataInputStream in = new DataInputStream(new FileInputStream(file))) {
|
||||
String playerName = in.readUTF();
|
||||
String playerUUID = in.readUTF();
|
||||
int score = in.readInt();
|
||||
int frameCount = in.readInt();
|
||||
|
||||
|
|
@ -65,7 +73,7 @@ public class GhostData {
|
|||
frames.add(new GhostFrame(timestamp, x, y, z, yaw, pitch));
|
||||
}
|
||||
|
||||
return new GhostData(playerName, score, frames);
|
||||
return new GhostData(playerName, playerUUID, score, frames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,15 +61,18 @@ public class GhostManager {
|
|||
ghosts.add(data);
|
||||
ghosts.sort((a, b) -> Integer.compare(b.getScore(), a.getScore()));
|
||||
|
||||
// Remove old ghosts beyond MAX limit
|
||||
while (ghosts.size() > MAX_GHOSTS_PER_MODE) {
|
||||
GhostData removed = ghosts.remove(ghosts.size() - 1);
|
||||
File file = new File(modeFolder, removed.getPlayerName() + ".ghost");
|
||||
// Use UUID for filename to avoid collisions and path traversal
|
||||
File file = new File(modeFolder, removed.getPlayerUUID() + ".ghost");
|
||||
file.delete();
|
||||
}
|
||||
|
||||
ghostsByMode.put(mode, ghosts);
|
||||
|
||||
File file = new File(modeFolder, data.getPlayerName() + ".ghost");
|
||||
// Use UUID for filename instead of player name
|
||||
File file = new File(modeFolder, data.getPlayerUUID() + ".ghost");
|
||||
try {
|
||||
data.saveToFile(file);
|
||||
} catch (IOException e) {
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ public class GhostRecorder {
|
|||
lastLocation = currentLocation.clone();
|
||||
}
|
||||
|
||||
public GhostData stopRecording(String playerName, int score) {
|
||||
public GhostData stopRecording(String playerName, String playerUUID, int score) {
|
||||
recording = false;
|
||||
return new GhostData(playerName, score, frames);
|
||||
return new GhostData(playerName, playerUUID, score, frames);
|
||||
}
|
||||
|
||||
public boolean isRecording() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue