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 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.

View file

@ -102,10 +102,14 @@ public class PlayerBackupProfile implements BackupProfile {
}
}
@Override public void destroy() throws IOException {
Files.delete(this.getBackupDirectory());
// Invalidate backup cache
@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() {

View file

@ -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);