Commit 50d27268 by Jonathan Thomas

Fixing auto save issues where files cannot be renamed. Maybe anti-virus issues,…

Fixing auto save issues where files cannot be renamed. Maybe anti-virus issues, or launcher permissions. However, it does appear that we can write files (just not rename them).
parent 49d42059
Pipeline #12157 passed with stage
in 1 minute 53 seconds
......@@ -4,6 +4,12 @@ All notable changes to **CreatureChat** are documented in this file. The format
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Simplified saving of chat data (no more renaming files)
- Send message to all ops when saving chat data errors (first auto-save happens at 1 minute after launching)
## [1.0.2] - 2024-05-07
### Added
......
......@@ -480,19 +480,14 @@ public class ChatDataManager {
// Save chat data to file
public void saveChatData(MinecraftServer server) {
File saveFile = new File(server.getSavePath(WorldSavePath.ROOT).toFile(), "chatdata.json");
File tempFile = new File(saveFile.getAbsolutePath() + ".tmp");
LOGGER.info("Saving chat data to " + saveFile.getAbsolutePath());
try (Writer writer = new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8)) {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(saveFile), StandardCharsets.UTF_8)) {
GSON.toJson(this.entityChatDataMap, writer);
if (saveFile.exists()) {
saveFile.delete();
}
if (!tempFile.renameTo(saveFile)) {
throw new IOException("Failed to rename temporary chat data file to " + saveFile.getName());
}
} catch (Exception e) {
LOGGER.error("Error saving chat data", e);
String errorMessage = "Error saving chat data to file system. No chat history will be saved. Check file permissions. " + e.getMessage();
LOGGER.error(errorMessage, e);
ServerPackets.sendMessageToAllOps(server, errorMessage);
}
}
......
......@@ -14,7 +14,7 @@ public class ChatDataSaverScheduler {
public void startAutoSaveTask(MinecraftServer server, long interval, TimeUnit timeUnit) {
ChatDataAutoSaver saverTask = new ChatDataAutoSaver(server);
scheduler.scheduleAtFixedRate(saverTask, interval, interval, timeUnit);
scheduler.scheduleAtFixedRate(saverTask, 1, interval, timeUnit);
}
public void stopAutoSaveTask() {
......
......@@ -325,4 +325,14 @@ public class ServerPackets {
.withUnderline(true));
player.sendMessage(text, false);
}
// Send a clickable message to ALL Ops
public static void sendMessageToAllOps(MinecraftServer server, String message) {
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
// Check if the player is an operator
if (server.getPlayerManager().isOperator(player.getGameProfile())) {
ServerPackets.SendClickableError(player, message, "http://discord.creaturechat.com");
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment