summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/worker
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-04-24 13:10:00 +0800
committerkeuin <[email protected]>2020-04-24 13:10:00 +0800
commit59674ed29c6b2c7e8ac98fc4f0f4fd4fd6d437c9 (patch)
tree47730fe93306b41b68f29b86ef5d0860c0d53d42 /src/main/java/com/keuin/kbackupfabric/worker
parent5749fc65909f0ee934d0410406265387157575a1 (diff)
Implemented uniformed console output (log4j) in PrintUtil.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/worker')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java12
-rw-r--r--src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java19
2 files changed, 14 insertions, 17 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java
index 3303f70..675d183 100644
--- a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java
+++ b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java
@@ -8,8 +8,6 @@ import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.world.World;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
@@ -25,7 +23,7 @@ import static com.keuin.kbackupfabric.util.PrintUtil.msgInfo;
*/
public final class BackupWorker implements Runnable {
- private static final Logger LOGGER = LogManager.getLogger();
+ //private static final Logger LOGGER = LogManager.getLogger();
private final CommandContext<ServerCommandSource> context;
private final String backupName;
private final Map<World, Boolean> oldWorldsSavingDisabled;
@@ -56,9 +54,9 @@ public final class BackupWorker implements Runnable {
});
// Force to save all player data and worlds
- LOGGER.info("Saving players ...");
+ PrintUtil.info("Saving players ...");
server.getPlayerManager().saveAllPlayerData();
- LOGGER.info("Saving worlds ...");
+ PrintUtil.info("Saving worlds ...");
server.save(true, true, true);
// Start threaded worker
@@ -85,8 +83,8 @@ public final class BackupWorker implements Runnable {
// Make zip
String levelPath = getLevelPath(server);
String backupFileName = getBackupFileName(backupName);
- LOGGER.debug(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectoryFile.toString()));
- LOGGER.info("Compressing level ...");
+ PrintUtil.debug(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectoryFile.toString()));
+ 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/worker/RestoreWorker.java b/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java
index 54e7beb..58560a1 100644
--- a/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java
+++ b/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java
@@ -1,10 +1,9 @@
package com.keuin.kbackupfabric.worker;
+import com.keuin.kbackupfabric.util.PrintUtil;
import com.keuin.kbackupfabric.util.ZipUtil;
import com.keuin.kbackupfabric.util.ZipUtilException;
import net.minecraft.server.MinecraftServer;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
@@ -17,7 +16,7 @@ import static org.apache.commons.io.FileUtils.forceDelete;
*/
public final class RestoreWorker implements Runnable {
- private static final Logger LOGGER = LogManager.getLogger();
+ //private static final Logger LOGGER = LogManager.getLogger();
private final Thread serverThread;
private final String backupFilePath;
@@ -44,7 +43,7 @@ public final class RestoreWorker implements Runnable {
public void run() {
try {
// Wait server thread die
- LOGGER.info("Waiting for the server thread to exit ...");
+ PrintUtil.info("Waiting for the server thread to exit ...");
while (serverThread.isAlive()) {
try {
serverThread.join();
@@ -52,14 +51,14 @@ public final class RestoreWorker implements Runnable {
}
}
- LOGGER.info("Wait for 5 seconds ...");
+ PrintUtil.info("Wait for 5 seconds ...");
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
}
// Delete old level
- LOGGER.info("Server stopped. Deleting old level ...");
+ PrintUtil.info("Server stopped. Deleting old level ...");
File levelDirFile = new File(levelDirectory);
long startTime = System.currentTimeMillis();
@@ -80,17 +79,17 @@ public final class RestoreWorker implements Runnable {
}
}
if (levelDirFile.exists()) {
- LOGGER.error(String.format("Cannot restore: failed to delete old level %s .", levelDirFile.getName()));
+ PrintUtil.error(String.format("Cannot restore: failed to delete old level %s .", levelDirFile.getName()));
return;
}
// Decompress archive
- LOGGER.info("Decompressing archived level");
+ PrintUtil.info("Decompressing archived level");
ZipUtil.unzip(backupFilePath, levelDirectory, false);
long endTime = System.currentTimeMillis();
- LOGGER.info(String.format("Restore complete! (%.2fs) Please restart the server manually.", (endTime - startTime) / 1000.0));
+ PrintUtil.info(String.format("Restore complete! (%.2fs) Please restart the server manually.", (endTime - startTime) / 1000.0));
} catch (SecurityException | IOException | ZipUtilException e) {
- LOGGER.error("An exception occurred while restoring: " + e.getMessage());
+ PrintUtil.error("An exception occurred while restoring: " + e.getMessage());
}
}
}