mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Add BackupProfile#restoreBackup
This commit is contained in:
parent
8715a27a93
commit
d0dbb495b0
@ -62,4 +62,11 @@ public interface BackupProfile {
|
|||||||
*/
|
*/
|
||||||
@NotNull CompletableFuture<Backup> createBackup();
|
@NotNull CompletableFuture<Backup> createBackup();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore a backup
|
||||||
|
*
|
||||||
|
* @return Backup to restore
|
||||||
|
*/
|
||||||
|
@NotNull CompletableFuture<Void> restoreBackup(@NotNull final Backup backup);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,8 @@ public class NullBackupProfile implements BackupProfile {
|
|||||||
throw new UnsupportedOperationException("Cannot create backup of an unowned plot");
|
throw new UnsupportedOperationException("Cannot create backup of an unowned plot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @NotNull public CompletableFuture<Void> restoreBackup(@NotNull final Backup backup) {
|
||||||
|
return CompletableFuture.completedFuture(null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.backup;
|
package com.plotsquared.core.backup;
|
||||||
|
|
||||||
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
|
import com.plotsquared.core.plot.schematic.Schematic;
|
||||||
import com.plotsquared.core.util.SchematicHandler;
|
import com.plotsquared.core.util.SchematicHandler;
|
||||||
|
import com.plotsquared.core.util.task.RunnableVal;
|
||||||
|
import com.plotsquared.core.util.task.TaskManager;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -111,4 +115,34 @@ public class PlayerBackupProfile implements BackupProfile {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @NotNull public CompletableFuture<Void> restoreBackup(@NotNull final Backup backup) {
|
||||||
|
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||||
|
if (backup.getFile() == null || !Files.exists(backup.getFile())) {
|
||||||
|
future.completeExceptionally(new IllegalArgumentException("The specific backup does not exist"));
|
||||||
|
} else {
|
||||||
|
TaskManager.runTaskAsync(() -> {
|
||||||
|
Schematic schematic = null;
|
||||||
|
try {
|
||||||
|
schematic = SchematicHandler.manager.getSchematic(backup.getFile().toFile());
|
||||||
|
} catch (SchematicHandler.UnsupportedFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (schematic == null) {
|
||||||
|
future.completeExceptionally(new IllegalArgumentException("The backup is non-existent or not in the correct format"));
|
||||||
|
} else {
|
||||||
|
SchematicHandler.manager.paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
|
||||||
|
@Override public void run(Boolean value) {
|
||||||
|
if (value) {
|
||||||
|
future.complete(null);
|
||||||
|
} else {
|
||||||
|
future.completeExceptionally(new RuntimeException(Captions.SCHEMATIC_PASTE_FAILED.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user