From 658361f825c1eb9e1fde940428a36072105e5dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 10 May 2020 21:31:16 +0200 Subject: [PATCH] Destroy backups when the plot is uncalimed --- .../com/plotsquared/core/backup/BackupProfile.java | 3 +-- .../plotsquared/core/backup/PlayerBackupProfile.java | 12 ++++++++---- .../main/java/com/plotsquared/core/plot/Plot.java | 6 ++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java index 663d684f6..4d35519c4 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java +++ b/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java @@ -27,7 +27,6 @@ package com.plotsquared.core.backup; import org.jetbrains.annotations.NotNull; -import java.io.IOException; import java.nio.file.Path; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -44,7 +43,7 @@ public interface BackupProfile { /** * Remove all backups stored for this profile */ - void destroy() throws IOException; + void destroy(); /** * Get the directory containing the backups for this profile. diff --git a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java index 4bbc0a76b..8853f3dff 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java +++ b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java @@ -102,10 +102,14 @@ public class PlayerBackupProfile implements BackupProfile { } } - @Override public void destroy() throws IOException { - Files.delete(this.getBackupDirectory()); - // Invalidate backup cache - this.backupCache = null; + @Override public void destroy() { + this.listBackups().whenCompleteAsync((backups, error) -> { + if (error != null) { + error.printStackTrace(); + } + backups.forEach(Backup::delete); + this.backupCache = null; + }); } @NotNull public Path getBackupDirectory() { diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 975c9becf..0a25e4cdd 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -93,6 +93,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -1358,6 +1359,11 @@ public class Plot { for (PlotPlayer pp : players) { PlotListener.plotExit(pp, current); } + + // Destroy all backups when the plot is unclaimed + Objects.requireNonNull(PlotSquared.imp()).getBackupManager() + .getProfile(current).destroy(); + getArea().removePlot(getId()); DBFunc.delete(current); current.setOwnerAbs(null);