summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-04-27 17:42:07 +0800
committerkeuin <[email protected]>2020-04-27 17:42:07 +0800
commit7444c2b1f281b5b147717ba2a2ed6798c66a057b (patch)
tree8d8952b2f3aaf1e497e8667b80fc59b91536c822 /src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java
parent33857f4bc061d8dc01a6d9d10e108da7cd7c6d18 (diff)
Resized the logo to reduce plugin size.1.3.3-dev1.3.2-dev
Refactored code for a better implementation of async and blocking task.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java
index be7734d..ee1a57e 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java
@@ -1,5 +1,7 @@
package com.keuin.kbackupfabric.operation;
+import com.keuin.kbackupfabric.operation.abstracts.InvokableAsyncBlockingOperation;
+import com.keuin.kbackupfabric.util.BackupNameSuggestionProvider;
import com.keuin.kbackupfabric.util.PrintUtil;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.MinecraftServer;
@@ -14,19 +16,30 @@ import static com.keuin.kbackupfabric.util.PrintUtil.msgErr;
import static com.keuin.kbackupfabric.util.PrintUtil.msgInfo;
import static org.apache.commons.io.FileUtils.forceDelete;
-class DeleteOperation extends AbstractConfirmableOperation {
+public class DeleteOperation extends InvokableAsyncBlockingOperation {
//private static final Logger LOGGER = LogManager.getLogger();
private final String backupName;
private final CommandContext<ServerCommandSource> context;
- DeleteOperation(CommandContext<ServerCommandSource> context, String backupName) {
+ public DeleteOperation(CommandContext<ServerCommandSource> context, String backupName) {
+ super("BackupDeletingWorker");
this.backupName = backupName;
this.context = context;
}
@Override
- public boolean confirm() {
+ public String toString() {
+ return String.format("deletion of %s", backupName);
+ }
+
+ @Override
+ protected void async() {
+ delete();
+ BackupNameSuggestionProvider.updateCandidateList();
+ }
+
+ private void delete() {
MinecraftServer server = context.getSource().getMinecraftServer();
String backupFileName = getBackupFileName(backupName);
PrintUtil.info("Deleting backup " + backupName);
@@ -37,7 +50,7 @@ class DeleteOperation extends AbstractConfirmableOperation {
String msg = "Failed to delete file " + backupFileName;
PrintUtil.error(msg);
msgErr(context, msg);
- return false;
+ return;
}
try {
if (!backupFile.delete())
@@ -48,11 +61,5 @@ class DeleteOperation extends AbstractConfirmableOperation {
} while (backupFile.exists());
PrintUtil.info("Deleted backup " + backupName);
msgInfo(context, "Deleted backup " + backupName);
- return true;
- }
-
- @Override
- public String toString() {
- return String.format("deletion of %s", backupName);
}
}