summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-04-24 13:43:20 +0800
committerkeuin <[email protected]>2020-04-24 13:43:20 +0800
commitea01faf3947814fe7ecaa3705e5fbf0f171f7e48 (patch)
tree1cb406b0d0897da70414aa5f96e8b1dd1eac40fb
parent59674ed29c6b2c7e8ac98fc4f0f4fd4fd6d437c9 (diff)
Added hint at the "/kb" output in the first run after restoring from a backup.1.3.0-dev
Warning: Backup in this version is not compatible with older version!
-rw-r--r--README.md3
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java2
-rw-r--r--src/main/java/com/keuin/kbackupfabric/KBCommands.java24
-rw-r--r--src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java6
-rw-r--r--src/main/java/com/keuin/kbackupfabric/metadata/BackupMetadata.java (renamed from src/main/java/com/keuin/kbackupfabric/data/BackupMetadata.java)5
-rw-r--r--src/main/java/com/keuin/kbackupfabric/metadata/MetadataHolder.java22
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java9
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java5
-rw-r--r--src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java2
10 files changed, 70 insertions, 10 deletions
diff --git a/README.md b/README.md
index e3daa47..5441653 100644
--- a/README.md
+++ b/README.md
@@ -19,9 +19,8 @@ commands:
To-Do List:
-- Restoration of player data may not be correct.
-- Optimize log output, normal output and op broadcast output.
- More thorough test.
- Enhance ZipUtil for hashing sub-files and generating incremental diff-table. (A:Add, M:Modification, D:Deletion)
- Optimize help menu. (colored command help menu)
+- Add op login hint in the next start after restoring.
- Implement incremental backup.
diff --git a/gradle.properties b/gradle.properties
index 16593c4..aba6679 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,7 +6,7 @@ minecraft_version=1.14.4
yarn_mappings=1.14.4+build.16
loader_version=0.8.2+build.194
# Mod Properties
-mod_version=1.2.0-dev
+mod_version=1.3.0-dev
maven_group=com.keuin.kbackupfabric
archives_base_name=kbackup-fabric
# Dependencies
diff --git a/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java b/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java
index 79029bf..674ac0c 100644
--- a/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java
+++ b/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java
@@ -12,7 +12,7 @@ public final class KBCommandRegister {
public static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
// register /kb and /kb help for help menu
- dispatcher.register(CommandManager.literal("kb").executes(KBCommands::help));
+ dispatcher.register(CommandManager.literal("kb").executes(KBCommands::kb));
dispatcher.register(CommandManager.literal("kb").then(CommandManager.literal("help").executes(KBCommands::help)));
// register /kb list for showing the backup list. OP is required.
diff --git a/src/main/java/com/keuin/kbackupfabric/KBCommands.java b/src/main/java/com/keuin/kbackupfabric/KBCommands.java
index dbe5252..f2671ad 100644
--- a/src/main/java/com/keuin/kbackupfabric/KBCommands.java
+++ b/src/main/java/com/keuin/kbackupfabric/KBCommands.java
@@ -1,6 +1,7 @@
package com.keuin.kbackupfabric;
-import com.keuin.kbackupfabric.data.BackupMetadata;
+import com.keuin.kbackupfabric.metadata.BackupMetadata;
+import com.keuin.kbackupfabric.metadata.MetadataHolder;
import com.keuin.kbackupfabric.operation.AbstractConfirmableOperation;
import com.keuin.kbackupfabric.util.BackupFilesystemUtil;
import com.keuin.kbackupfabric.util.BackupNameTimeFormatter;
@@ -48,6 +49,27 @@ public final class KBCommands {
return SUCCESS;
}
+ /**
+ * Print the help menu. (May show extra info during the first run after restoring)
+ *
+ * @param context the context.
+ * @return stat code.
+ */
+ public static int kb(CommandContext<ServerCommandSource> context) {
+ int statCode = list(context);
+ if (MetadataHolder.hasMetadata()) {
+ // Output metadata info
+ msgStress(context, "Restored from backup " + MetadataHolder.getMetadata().getBackupName());
+ }
+ return statCode;
+ }
+
+ /**
+ * List all existing backups.
+ *
+ * @param context the context.
+ * @return stat code.
+ */
public static int list(CommandContext<ServerCommandSource> context) {
msgInfo(context, "Available backups: (file is not checked, manipulation may affect this plugin)");
MinecraftServer server = context.getSource().getMinecraftServer();
diff --git a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java
index 1f39266..f3a3b07 100644
--- a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java
+++ b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java
@@ -1,6 +1,7 @@
package com.keuin.kbackupfabric;
-import com.keuin.kbackupfabric.data.BackupMetadata;
+import com.keuin.kbackupfabric.metadata.BackupMetadata;
+import com.keuin.kbackupfabric.metadata.MetadataHolder;
import com.keuin.kbackupfabric.util.BackupFilesystemUtil;
import com.keuin.kbackupfabric.util.BackupNameSuggestionProvider;
import com.keuin.kbackupfabric.util.PrintUtil;
@@ -46,7 +47,7 @@ public final class KBPluginEvents implements ModInitializer, ServerStartCallback
File metadataFile = new File(levelDirectory, BackupMetadata.metadataFileName);
if (metadataFile.exists()) {
// Metadata exists. Deserialize.
- BackupMetadata metadata = null;
+ BackupMetadata metadata;
FileInputStream fileInputStream = new FileInputStream(metadataFile);
ObjectInputStream in = new ObjectInputStream(fileInputStream);
metadata = (BackupMetadata) in.readObject();
@@ -54,6 +55,7 @@ public final class KBPluginEvents implements ModInitializer, ServerStartCallback
fileInputStream.close();
// Print metadata
+ MetadataHolder.setMetadata(metadata);
PrintUtil.info("Recovered from previous backup:");
PrintUtil.info("Backup Name: " + metadata.getBackupName());
PrintUtil.info("Create Time: " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date(metadata.getBackupTime())));
diff --git a/src/main/java/com/keuin/kbackupfabric/data/BackupMetadata.java b/src/main/java/com/keuin/kbackupfabric/metadata/BackupMetadata.java
index 48670c6..b8cb852 100644
--- a/src/main/java/com/keuin/kbackupfabric/data/BackupMetadata.java
+++ b/src/main/java/com/keuin/kbackupfabric/metadata/BackupMetadata.java
@@ -1,7 +1,10 @@
-package com.keuin.kbackupfabric.data;
+package com.keuin.kbackupfabric.metadata;
import java.io.Serializable;
+/**
+ * WARNING: DO NOT modify this class, or the plugin will be incompatible with backups created by older versions.
+ */
public class BackupMetadata implements Serializable {
public static final String metadataFileName = "kbackup_metadata";
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/com/keuin/kbackupfabric/metadata/MetadataHolder.java b/src/main/java/com/keuin/kbackupfabric/metadata/MetadataHolder.java
new file mode 100644
index 0000000..4180a19
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/metadata/MetadataHolder.java
@@ -0,0 +1,22 @@
+package com.keuin.kbackupfabric.metadata;
+
+/**
+ * In the first startup after restoring from a previous backup, the metadata is stored in this class.
+ * The setMetadata can only be called when startup
+ */
+public class MetadataHolder {
+ private static BackupMetadata metadata = null;
+
+ public static BackupMetadata getMetadata() {
+ return metadata;
+ }
+
+ public static void setMetadata(BackupMetadata metadata) {
+ if (MetadataHolder.metadata == null)
+ MetadataHolder.metadata = metadata;
+ }
+
+ public static boolean hasMetadata() {
+ return MetadataHolder.metadata != null;
+ }
+}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java
index ca00ad4..11995e7 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java
@@ -15,11 +15,16 @@ public final class PrintUtil {
private static final Object syncMessage = new Object();
private static final Style infoStyle = new Style().setColor(Formatting.WHITE);
+ private static final Style stressStyle = new Style().setColor(Formatting.AQUA).setBold(true);
private static final Style warnStyle = new Style().setColor(Formatting.YELLOW);
private static final Style errorStyle = new Style().setColor(Formatting.DARK_RED);
private static final Logger LOGGER = LogManager.getLogger();
+ public static CommandContext<ServerCommandSource> msgStress(CommandContext<ServerCommandSource> context, String messageText) {
+ return msgStress(context, messageText, false);
+ }
+
public static CommandContext<ServerCommandSource> msgInfo(CommandContext<ServerCommandSource> context, String messageText) {
return msgInfo(context, messageText, false);
}
@@ -32,6 +37,10 @@ public final class PrintUtil {
return msgErr(context, messageText, false);
}
+ public static CommandContext<ServerCommandSource> msgStress(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) {
+ return message(context, messageText, broadcastToOps, stressStyle);
+ }
+
public static CommandContext<ServerCommandSource> msgInfo(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps) {
return message(context, messageText, broadcastToOps, infoStyle);
}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
index e819afc..ee2907e 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
@@ -1,6 +1,6 @@
package com.keuin.kbackupfabric.util;
-import com.keuin.kbackupfabric.data.BackupMetadata;
+import com.keuin.kbackupfabric.metadata.BackupMetadata;
import java.io.*;
import java.util.Enumeration;
@@ -21,6 +21,9 @@ public final class ZipUtil {
return;
}
+ if (file.getName().equals(BackupMetadata.metadataFileName))
+ return; // Reject
+
// 如果是文件,则直接压缩该文件
if (file.isFile()) {
int count, bufferLen = 1024;
diff --git a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java
index 675d183..e972b4d 100644
--- a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java
+++ b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java
@@ -1,6 +1,6 @@
package com.keuin.kbackupfabric.worker;
-import com.keuin.kbackupfabric.data.BackupMetadata;
+import com.keuin.kbackupfabric.metadata.BackupMetadata;
import com.keuin.kbackupfabric.util.PrintUtil;
import com.keuin.kbackupfabric.util.ZipUtil;
import com.keuin.kbackupfabric.util.ZipUtilException;