From 081530c52e29f6e7db5798f51956756a47f7233d Mon Sep 17 00:00:00 2001 From: Mehrad Nayyeri Date: Sun, 5 Mar 2023 10:28:39 +0330 Subject: [PATCH] Fixed a bug where backups would use the same icon --- .../rollback/util/backup/BackupManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/ir/mehradn/rollback/util/backup/BackupManager.java b/src/main/java/ir/mehradn/rollback/util/backup/BackupManager.java index 8e0e145..10438ab 100644 --- a/src/main/java/ir/mehradn/rollback/util/backup/BackupManager.java +++ b/src/main/java/ir/mehradn/rollback/util/backup/BackupManager.java @@ -135,6 +135,7 @@ public boolean createRollbackBackup(MinecraftServer server) { while (array.size() >= RollbackConfig.getMaxBackupsPerWorld()) deleteBackup(worldName, 0); + deleteNonexistentIcons(worldName); Rollback.LOGGER.debug("Saving the world..."); boolean f = server.saveAll(true, true, true); @@ -205,8 +206,9 @@ public boolean deleteBackup(String worldName, int index) { Rollback.LOGGER.debug("Deleting the files..."); try { - Files.deleteIfExists(this.rollbackDirectory.resolve(backup.iconPath)); Files.deleteIfExists(this.rollbackDirectory.resolve(backup.backupPath)); + if (backup.iconPath != null) + Files.deleteIfExists(this.rollbackDirectory.resolve(backup.iconPath)); } catch (IOException e) { showError("rollback.deleteBackup.failed", "Failed to delete the files!", e); return false; @@ -275,6 +277,18 @@ public void deleteAllBackupsFor(String worldName) { saveMetadata(); } + private void deleteNonexistentIcons(String worldName) { + JsonArray array = getWorldObject(worldName).getAsJsonArray("backups"); + for (JsonElement elm : array) { + JsonObject obj = elm.getAsJsonObject(); + if (!obj.has("icon_file")) + continue; + String iconPath = obj.get("icon_file").getAsString(); + if (!Files.isRegularFile(this.rollbackDirectory.resolve(iconPath))) + obj.remove("icon_file"); + } + } + /* public void cleanUp() { List worldNames;