Destroy backups when the plot is uncalimed

This commit is contained in:
Alexander Söderberg 2020-05-10 21:31:16 +02:00
parent e0c9a802d8
commit 658361f825
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
3 changed files with 15 additions and 6 deletions

View File

@ -27,7 +27,6 @@ package com.plotsquared.core.backup;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -44,7 +43,7 @@ public interface BackupProfile {
/** /**
* Remove all backups stored for this profile * Remove all backups stored for this profile
*/ */
void destroy() throws IOException; void destroy();
/** /**
* Get the directory containing the backups for this profile. * Get the directory containing the backups for this profile.

View File

@ -102,10 +102,14 @@ public class PlayerBackupProfile implements BackupProfile {
} }
} }
@Override public void destroy() throws IOException { @Override public void destroy() {
Files.delete(this.getBackupDirectory()); this.listBackups().whenCompleteAsync((backups, error) -> {
// Invalidate backup cache if (error != null) {
error.printStackTrace();
}
backups.forEach(Backup::delete);
this.backupCache = null; this.backupCache = null;
});
} }
@NotNull public Path getBackupDirectory() { @NotNull public Path getBackupDirectory() {

View File

@ -93,6 +93,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -1358,6 +1359,11 @@ public class Plot {
for (PlotPlayer pp : players) { for (PlotPlayer pp : players) {
PlotListener.plotExit(pp, current); PlotListener.plotExit(pp, current);
} }
// Destroy all backups when the plot is unclaimed
Objects.requireNonNull(PlotSquared.imp()).getBackupManager()
.getProfile(current).destroy();
getArea().removePlot(getId()); getArea().removePlot(getId());
DBFunc.delete(current); DBFunc.delete(current);
current.setOwnerAbs(null); current.setOwnerAbs(null);