summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java2
-rw-r--r--src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java3
-rw-r--r--src/main/java/com/keuin/kbackupfabric/exception/ZipUtilException.java (renamed from src/main/java/com/keuin/kbackupfabric/util/ZipUtilException.java)2
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java3
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java12
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java4
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java58
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java1
8 files changed, 78 insertions, 7 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java b/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java
index 674ac0c..b223e3f 100644
--- a/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java
+++ b/src/main/java/com/keuin/kbackupfabric/KBCommandRegister.java
@@ -10,8 +10,8 @@ import net.minecraft.server.command.ServerCommandSource;
public final class KBCommandRegister {
// First make method to register
public static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
- // register /kb and /kb help for help menu
+ // register /kb and /kb help for help menu
dispatcher.register(CommandManager.literal("kb").executes(KBCommands::kb));
dispatcher.register(CommandManager.literal("kb").then(CommandManager.literal("help").executes(KBCommands::help)));
diff --git a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java
index dea79e7..9e90019 100644
--- a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java
+++ b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java
@@ -36,7 +36,6 @@ public final class KBPluginEvents implements ModInitializer, ServerStartCallback
@Override
public void onStartServer(MinecraftServer server) {
- PrintUtil.debug("Initializing ...");
// Initialize player manager reference
PrintUtil.setPlayerManager(server.getPlayerManager());
@@ -71,5 +70,7 @@ public final class KBPluginEvents implements ModInitializer, ServerStartCallback
}
} catch (IOException | ClassNotFoundException ignored) {
}
+
+ PrintUtil.info("KBackup is a free software. Project home: https://github.com/keuin/KBackup-Fabric");
}
}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtilException.java b/src/main/java/com/keuin/kbackupfabric/exception/ZipUtilException.java
index b31272d..c23ce26 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtilException.java
+++ b/src/main/java/com/keuin/kbackupfabric/exception/ZipUtilException.java
@@ -1,4 +1,4 @@
-package com.keuin.kbackupfabric.util;
+package com.keuin.kbackupfabric.exception;
public class ZipUtilException extends Exception {
public ZipUtilException() {
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java
index 7d3a508..53b05b8 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java
@@ -1,10 +1,10 @@
package com.keuin.kbackupfabric.operation;
+import com.keuin.kbackupfabric.exception.ZipUtilException;
import com.keuin.kbackupfabric.metadata.BackupMetadata;
import com.keuin.kbackupfabric.operation.abstracts.InvokableAsyncBlockingOperation;
import com.keuin.kbackupfabric.util.PrintUtil;
import com.keuin.kbackupfabric.util.ZipUtil;
-import com.keuin.kbackupfabric.util.ZipUtilException;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
@@ -53,6 +53,7 @@ public class BackupOperation extends InvokableAsyncBlockingOperation {
String levelPath = getLevelPath(server);
String backupFileName = getBackupFileName(backupName);
PrintUtil.info(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectoryFile.toString()));
+ msgInfo(context, "Compressing worlds ...");
PrintUtil.info("Compressing level ...");
ZipUtil.makeBackupZip(levelPath, backupSaveDirectoryFile.toString(), backupFileName, backupMetadata);
File backupZipFile = new File(backupSaveDirectoryFile, backupFileName);
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
index cc19627..6754393 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java
@@ -1,9 +1,9 @@
package com.keuin.kbackupfabric.operation;
+import com.keuin.kbackupfabric.exception.ZipUtilException;
import com.keuin.kbackupfabric.operation.abstracts.InvokableBlockingOperation;
import com.keuin.kbackupfabric.util.PrintUtil;
import com.keuin.kbackupfabric.util.ZipUtil;
-import com.keuin.kbackupfabric.util.ZipUtilException;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
@@ -121,6 +121,16 @@ public class RestoreOperation extends InvokableBlockingOperation {
ZipUtil.unzip(backupFilePath, levelDirectory, false);
long endTime = System.currentTimeMillis();
PrintUtil.info(String.format("Restore complete! (%.2fs) Please restart the server manually.", (endTime - startTime) / 1000.0));
+ PrintUtil.info("If you want to restart automatically after restoring, please visit the project manual at: https://github.com/keuin/KBackup-Fabric/blob/master/README.md");
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignored) {
+ }
+
+ //ServerRestartUtil.forkAndRestart();
+ System.exit(111);
+
} catch (SecurityException | IOException | ZipUtilException e) {
PrintUtil.error("An exception occurred while restoring: " + e.getMessage());
}
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java
index de672cd..15b72c9 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java
@@ -13,11 +13,11 @@ public abstract class AbstractBlockingOperation extends AbstractSerializedOperat
protected final boolean operate() {
synchronized (sync) {
if (isBlocking) {
- System.out.println("blocked.");
+// System.out.println("blocked.");
wasBlocked = true;
return false;
} else {
- System.out.println("not blocked.");
+// System.out.println("not blocked.");
wasBlocked = false;
isBlocking = true;
}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java
new file mode 100644
index 0000000..1642e5c
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/util/ServerRestartUtil.java
@@ -0,0 +1,58 @@
+package com.keuin.kbackupfabric.util;
+
+public class ServerRestartUtil {
+
+ public static void forkAndRestart() {
+// Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+// @Override
+// public void run() {
+// // Here we restart the minecraft server
+// StringBuilder cmd = new StringBuilder();
+// cmd.append(System.getProperty("java.home")).append(File.separator).append("bin").append(File.separator).append("java ");
+// for (String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
+// cmd.append(jvmArg + " ");
+// }
+// cmd.append("-cp ").append(ManagementFactory.getRuntimeMXBean().getClassPath()).append(" ");
+// cmd.append(MinecraftServer.class.getName()).append(" ");
+// for (String arg : args) {
+// cmd.append(arg).append(" ");
+// }
+// Runtime.getRuntime().exec(cmd.toString());
+// System.exit(0);
+// }
+// }));
+ }
+
+ private static void startRestartThread() {
+// (new Thread(() -> {
+//
+//
+// // kill threads
+// Set<Thread> threads = Thread.getAllStackTraces().keySet();
+// Thread currentThread = Thread.currentThread();
+// for (Thread t : threads) {
+// if(t != currentThread && t.isAlive()) {
+// t.setUncaughtExceptionHandler((t1, e) -> {
+// // set empty handler
+// });
+// //t.interrupt();
+// try {
+// t.setDaemon(true);
+// } catch (Exception ignored) {
+// }
+//
+// t.stop();
+// }
+// }
+//
+// try {
+// Thread.sleep(5000);
+// } catch (InterruptedException ignored) {
+// }
+//
+// // restart Minecraft server
+// String[] args = new String[]{};
+// MinecraftServer.main(args);
+// })).start();
+ }
+}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
index ee2907e..11b912e 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
@@ -1,5 +1,6 @@
package com.keuin.kbackupfabric.util;
+import com.keuin.kbackupfabric.exception.ZipUtilException;
import com.keuin.kbackupfabric.metadata.BackupMetadata;
import java.io.*;