summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util/backup
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/backup')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/BackupType.java22
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/builder/BackupFileNameBuilder.java3
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/formatter/BackupFileNameFormatter.java3
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/formatter/ObjectTreeBackupFileNameFormatter.java5
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/formatter/PrimitiveZipBackupFileNameFormatter.java5
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/suggestion/BackupMethodSuggestionProvider.java36
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/suggestion/BackupNameSuggestionProvider.java (renamed from src/main/java/com/keuin/kbackupfabric/util/backup/BackupNameSuggestionProvider.java)3
7 files changed, 59 insertions, 18 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/BackupType.java b/src/main/java/com/keuin/kbackupfabric/util/backup/BackupType.java
index 95a32ae..d02ce77 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/BackupType.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/BackupType.java
@@ -4,18 +4,30 @@ package com.keuin.kbackupfabric.util.backup;
* Representing the backup type.
* Should only be used in BackupFileNameBuilder and BackupFileNameFormatter
*/
+@Deprecated
public enum BackupType {
- PRIMITIVE_ZIP_BACKUP("Primitive Zip Backup"),
- OBJECT_TREE_BACKUP("Object Tree Backup");
+ PRIMITIVE_ZIP_BACKUP("Primitive Zip Backup", "zip"),
+ OBJECT_TREE_BACKUP("Object Tree Backup", "incremental");
- private final String name;
- BackupType(String name) {
+ private final String friendlyName; // e.g. Primitive Zip Backup
+ private final String name; // e.g. zip
+
+ BackupType(String friendlyName, String name) {
+ this.friendlyName = friendlyName;
this.name = name;
}
+ /**
+ * Get name used in command.
+ * @return name (such as "zip", "incremental").
+ */
+ public String getName() {
+ return name;
+ }
+
@Override
public String toString() {
- return name;
+ return friendlyName;
}
}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/builder/BackupFileNameBuilder.java b/src/main/java/com/keuin/kbackupfabric/util/backup/builder/BackupFileNameBuilder.java
index 16c598b..f57302c 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/builder/BackupFileNameBuilder.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/builder/BackupFileNameBuilder.java
@@ -1,6 +1,5 @@
package com.keuin.kbackupfabric.util.backup.builder;
-import com.sun.istack.internal.NotNull;
import java.time.LocalDateTime;
@@ -20,6 +19,6 @@ public interface BackupFileNameBuilder {
* @param backupName the custom name of this backup. Note that this should be a valid file name in current file system.
* @return the backup file name string.
*/
- String build(@NotNull LocalDateTime time, @NotNull String backupName);
+ String build(LocalDateTime time, String backupName);
}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/BackupFileNameFormatter.java b/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/BackupFileNameFormatter.java
index eae3639..a437629 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/BackupFileNameFormatter.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/BackupFileNameFormatter.java
@@ -1,7 +1,6 @@
package com.keuin.kbackupfabric.util.backup.formatter;
import com.keuin.kbackupfabric.util.backup.BackupNameTimeFormatter;
-import com.sun.istack.internal.NotNull;
import java.time.LocalDateTime;
import java.util.regex.Matcher;
@@ -9,7 +8,7 @@ import java.util.regex.Pattern;
public interface BackupFileNameFormatter {
- BackupFileName format(@NotNull String fileName);
+ BackupFileName format(String fileName);
class BackupFileName {
public final LocalDateTime time;
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/ObjectTreeBackupFileNameFormatter.java b/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/ObjectTreeBackupFileNameFormatter.java
index e5503a9..08805b2 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/ObjectTreeBackupFileNameFormatter.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/ObjectTreeBackupFileNameFormatter.java
@@ -2,8 +2,6 @@ package com.keuin.kbackupfabric.util.backup.formatter;
import com.keuin.kbackupfabric.util.backup.BackupFilesystemUtil;
import com.keuin.kbackupfabric.util.backup.BackupNameTimeFormatter;
-import com.sun.istack.internal.NotNull;
-import com.sun.istack.internal.Nullable;
import org.spongepowered.asm.mixin.Overwrite;
import java.time.LocalDateTime;
@@ -19,13 +17,12 @@ public class ObjectTreeBackupFileNameFormatter implements BackupFileNameFormatte
}
@Override
- public BackupFileNameFormatter.BackupFileName format(@NotNull String fileName) {
+ public BackupFileNameFormatter.BackupFileName format(String fileName) {
LocalDateTime time = getTime(fileName);
String name = getBackupName(fileName);
return new BackupFileNameFormatter.BackupFileName(time,name);
}
- @Nullable
private LocalDateTime getTime(String fileName) {
Matcher matcher = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}").matcher(fileName);
if (matcher.find()) {
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/PrimitiveZipBackupFileNameFormatter.java b/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/PrimitiveZipBackupFileNameFormatter.java
index 40450eb..2d50d17 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/PrimitiveZipBackupFileNameFormatter.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/formatter/PrimitiveZipBackupFileNameFormatter.java
@@ -2,8 +2,6 @@ package com.keuin.kbackupfabric.util.backup.formatter;
import com.keuin.kbackupfabric.util.backup.BackupFilesystemUtil;
import com.keuin.kbackupfabric.util.backup.BackupNameTimeFormatter;
-import com.sun.istack.internal.NotNull;
-import com.sun.istack.internal.Nullable;
import java.time.LocalDateTime;
import java.util.regex.Matcher;
@@ -18,13 +16,12 @@ public class PrimitiveZipBackupFileNameFormatter implements BackupFileNameFormat
}
@Override
- public BackupFileNameFormatter.BackupFileName format(@NotNull String fileName) {
+ public BackupFileNameFormatter.BackupFileName format(String fileName) {
LocalDateTime time = getTime(fileName);
String name = getBackupName(fileName);
return new BackupFileNameFormatter.BackupFileName(time,name);
}
- @Nullable
private LocalDateTime getTime(String fileName) {
Matcher matcher = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}").matcher(fileName);
if (matcher.find()) {
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/suggestion/BackupMethodSuggestionProvider.java b/src/main/java/com/keuin/kbackupfabric/util/backup/suggestion/BackupMethodSuggestionProvider.java
new file mode 100644
index 0000000..320d9bf
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/suggestion/BackupMethodSuggestionProvider.java
@@ -0,0 +1,36 @@
+package com.keuin.kbackupfabric.util.backup.suggestion;
+
+import com.keuin.kbackupfabric.util.backup.BackupType;
+import com.mojang.brigadier.suggestion.SuggestionProvider;
+import com.mojang.brigadier.suggestion.Suggestions;
+import com.mojang.brigadier.suggestion.SuggestionsBuilder;
+import net.minecraft.server.command.ServerCommandSource;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.CompletableFuture;
+
+public class BackupMethodSuggestionProvider {
+
+ private static final List<String> suggestions = Arrays.asList(
+ BackupType.OBJECT_TREE_BACKUP.getName(),
+ BackupType.PRIMITIVE_ZIP_BACKUP.getName()
+ ); // All backup methods
+
+ public static SuggestionProvider<ServerCommandSource> getProvider() {
+ return (context, builder) -> getCompletableFuture(builder);
+ }
+
+ private static CompletableFuture<Suggestions> getCompletableFuture(SuggestionsBuilder builder) {
+ String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
+ for (String string : suggestions) { // Iterate through the supplied list
+ if (string.toLowerCase(Locale.ROOT).startsWith(remaining)) {
+ builder.suggest(string); // Add every single entry to suggestions list.
+ }
+ }
+ return builder.buildFuture(); // Create the CompletableFuture containing all the suggestions
+ }
+
+}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/BackupNameSuggestionProvider.java b/src/main/java/com/keuin/kbackupfabric/util/backup/suggestion/BackupNameSuggestionProvider.java
index 4639e99..f6f4056 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/BackupNameSuggestionProvider.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/suggestion/BackupNameSuggestionProvider.java
@@ -1,5 +1,6 @@
-package com.keuin.kbackupfabric.util.backup;
+package com.keuin.kbackupfabric.util.backup.suggestion;
+import com.keuin.kbackupfabric.util.backup.BackupFilesystemUtil;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;