From 859ddc0a3aa5f5b81c19315a815a54648d56f9c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 10 Jul 2021 17:46:30 +0200 Subject: [PATCH] Fix Region.backup size Signed-off-by: yoyosource --- .../steamwar/bausystem/features/backup/BackupCommand.java | 1 - .../src/de/steamwar/bausystem/region/Region.java | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index 37263776..e674fe3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -28,7 +28,6 @@ import de.steamwar.bausystem.region.tags.Tag; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.Collections; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 91e7c806..7b428f2b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -466,6 +466,14 @@ public class Region { final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); //noinspection ResultOfMethodCallIgnored definedBackupFolder.mkdirs(); + + File[] currentBackups = definedBackupFolder.listFiles(); + if (currentBackups.length >= 20) { + List files = new ArrayList<>(Arrays.asList(currentBackups)); + files.sort(Comparator.comparingLong(File::lastModified)); + while (files.size() >= 20) files.remove(0).delete(); + } + final File backupFile = new File(definedBackupFolder, LocalDateTime.now().format(formatter) + ".schem"); //noinspection unchecked return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.backup(minPoint, maxPoint, backupFile), 15));