Upload via Git Manager GUI - StatsStorage.java

This commit is contained in:
2026-04-01 10:14:30 +00:00
parent 92d6b22924
commit 873480557f

View File

@@ -1,37 +1,37 @@
package net.viper.status.stats; package net.viper.status.stats;
import java.io.*; import java.io.*;
public class StatsStorage { public class StatsStorage {
private final File file; private final File file;
public StatsStorage(File pluginFolder) { public StatsStorage(File pluginFolder) {
if (!pluginFolder.exists()) pluginFolder.mkdirs(); if (!pluginFolder.exists()) pluginFolder.mkdirs();
this.file = new File(pluginFolder, "stats.dat"); this.file = new File(pluginFolder, "stats.dat");
} }
public void save(StatsManager manager) { public void save(StatsManager manager) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
for (PlayerStats ps : manager.all()) { for (PlayerStats ps : manager.all()) {
bw.write(ps.toLine()); bw.write(ps.toLine());
bw.newLine(); bw.newLine();
} }
bw.flush(); bw.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void load(StatsManager manager) { public void load(StatsManager manager) {
if (!file.exists()) return; if (!file.exists()) return;
try (BufferedReader br = new BufferedReader(new FileReader(file))) { try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
PlayerStats ps = PlayerStats.fromLine(line); PlayerStats ps = PlayerStats.fromLine(line);
if (ps != null) manager.put(ps); if (ps != null) manager.put(ps);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }