fixed configuration file not saving correctly

This commit is contained in:
2025-06-15 18:55:17 +02:00
parent fce9449b7e
commit ccf383cdb5

View File

@ -24,7 +24,7 @@ public class PlayTimer extends Appliance {
public static final int PLAYTIME_MINUTES = 30; public static final int PLAYTIME_MINUTES = 30;
private final Map<String, Integer> joinTickets = new HashMap<>(); private final Map<String, Integer> joinTickets = new HashMap<>();
private final Path saveFile = Paths.get(Main.instance().getDataFolder() + "playtime.json"); private final Path saveFile = Paths.get(Main.instance().getDataFolder().getAbsolutePath() + "/playtime.json");
public PlayTimer() { public PlayTimer() {
this.load(); this.load();
@ -51,9 +51,7 @@ public class PlayTimer extends Appliance {
try { try {
Files.createDirectories(this.saveFile.getParent()); Files.createDirectories(this.saveFile.getParent());
try (Writer writer = Files.newBufferedWriter(this.saveFile)) { try (Writer writer = Files.newBufferedWriter(this.saveFile)) {
new Gson().toJson(Map.of( new Gson().toJson(Map.of("tickets", this.joinTickets), writer);
"tickets", this.joinTickets
), writer);
} }
} catch (IOException e) { } catch (IOException e) {
Main.logger().warning("Failed to save playtime for teams: " + e.getMessage()); Main.logger().warning("Failed to save playtime for teams: " + e.getMessage());
@ -66,6 +64,7 @@ public class PlayTimer extends Appliance {
} }
public void setTickets(VaroTeam team, int amount) { public void setTickets(VaroTeam team, int amount) {
this.joinTickets.put(team.name, amount); this.joinTickets.put(team.name, amount);
this.save();
} }
public int getTickets(VaroTeam team) { public int getTickets(VaroTeam team) {