From 445f7a5613d3d1f548d7a2d09629a44366ce2768 Mon Sep 17 00:00:00 2001 From: szymon Date: Sat, 5 Dec 2020 23:14:35 +0100 Subject: [PATCH] Some improvements to logging, Player data now gets saved. Few other things... --- .../textile_backup/core/CustomLogger.java | 17 +++++++++++------ .../core/create/BackupHelper.java | 5 ++++- .../core/restore/RestoreBackupRunnable.java | 3 ++- .../core/restore/RestoreHelper.java | 16 +++++++++------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/core/CustomLogger.java b/src/main/java/net/szum123321/textile_backup/core/CustomLogger.java index 1d899f4..35d1a6b 100644 --- a/src/main/java/net/szum123321/textile_backup/core/CustomLogger.java +++ b/src/main/java/net/szum123321/textile_backup/core/CustomLogger.java @@ -29,7 +29,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.message.ParameterizedMessageFactory; -import org.apache.logging.log4j.spi.StandardLevel; /* This is practically just a copy-pate of Cotton's ModLogger with a few changes @@ -82,11 +81,13 @@ public class CustomLogger { log(Level.FATAL, msg, data); } - boolean sendToPlayer(Level level, ServerCommandSource source, String msg, Object... args) { + boolean sendFeedback(Level level, ServerCommandSource source, String msg, Object... args) { if(source != null && source.getEntity() instanceof PlayerEntity) { LiteralText text = new LiteralText(messageFactory.newMessage(msg, args).getFormattedMessage()); - if(level.intLevel() < StandardLevel.WARN.intLevel()) + if(level.intLevel() == Level.TRACE.intLevel()) + text.formatted(Formatting.GREEN); + else if(level.intLevel() <= Level.WARN.intLevel()) text.formatted(Formatting.RED); else text.formatted(Formatting.WHITE); @@ -101,8 +102,12 @@ public class CustomLogger { } } + public void sendHint(ServerCommandSource source, String msg, Object... args) { + sendFeedback(Level.TRACE, source, msg, args); + } + public void sendInfo(ServerCommandSource source, String msg, Object... args) { - sendToPlayer(Level.INFO, source, msg, args); + sendFeedback(Level.INFO, source, msg, args); } public void sendInfo(BackupContext context, String msg, Object... args) { @@ -110,7 +115,7 @@ public class CustomLogger { } public void sendError(ServerCommandSource source, String msg, Object... args) { - sendToPlayer(Level.ERROR, source, msg, args); + sendFeedback(Level.ERROR, source, msg, args); } public void sendError(BackupContext context, String msg, Object... args) { @@ -118,7 +123,7 @@ public class CustomLogger { } public void sendToPlayerAndLog(Level level, ServerCommandSource source, String msg, Object... args) { - if(sendToPlayer(level, source, msg, args)) + if(sendFeedback(level, source, msg, args)) log(level, msg, args); } diff --git a/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java b/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java index 5696786..bae4a1d 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java @@ -20,7 +20,9 @@ package net.szum123321.textile_backup.core.create; import net.minecraft.network.MessageType; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; +import net.minecraft.util.Formatting; import net.minecraft.util.Util; import net.szum123321.textile_backup.Statics; import net.szum123321.textile_backup.core.ActionInitiator; @@ -59,6 +61,7 @@ public class BackupHelper { if (ctx.shouldSave()) { Statics.LOGGER.sendInfoAL(ctx, "Saving server..."); + ctx.getServer().getPlayerManager().saveAllPlayerData(); ctx.getServer().save(true, true, true); } @@ -67,7 +70,7 @@ public class BackupHelper { private static void notifyPlayers(BackupContext ctx) { MutableText message = Statics.LOGGER.getPrefixText().shallowCopy(); - message.append("Warning! Server backup will begin shortly. You may experience some lag."); + message.append(new LiteralText("Warning! Server backup will begin shortly. You may experience some lag.").formatted(Formatting.WHITE)); ctx.getServer().getPlayerManager().broadcastChatMessage( message, diff --git a/src/main/java/net/szum123321/textile_backup/core/restore/RestoreBackupRunnable.java b/src/main/java/net/szum123321/textile_backup/core/restore/RestoreBackupRunnable.java index 2318106..7e2b39a 100644 --- a/src/main/java/net/szum123321/textile_backup/core/restore/RestoreBackupRunnable.java +++ b/src/main/java/net/szum123321/textile_backup/core/restore/RestoreBackupRunnable.java @@ -18,7 +18,6 @@ package net.szum123321.textile_backup.core.restore; -import net.minecraft.server.MinecraftServer; import net.szum123321.textile_backup.ConfigHandler; import net.szum123321.textile_backup.core.ActionInitiator; import net.szum123321.textile_backup.core.LivingServer; @@ -40,6 +39,8 @@ public class RestoreBackupRunnable implements Runnable { @Override public void run() { + Statics.globalShutdownBackupFlag.set(false); + Statics.LOGGER.info("Shutting down server..."); ctx.getServer().stop(false); diff --git a/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java b/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java index 2c1db5d..d7a14e3 100644 --- a/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java +++ b/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java @@ -58,6 +58,15 @@ public class RestoreHelper { else Statics.LOGGER.info("Backup restoration was initiated form Server Console"); + notifyPlayer(ctx); + + return new AwaitThread( + Statics.CONFIG.restoreDelay, + new RestoreBackupRunnable(ctx) + ); + } + + private static void notifyPlayer(RestoreContext ctx) { MutableText message = Statics.LOGGER.getPrefixText().shallowCopy(); message.append("Warning! The server is going to shut down in " + Statics.CONFIG.restoreDelay + " seconds!"); @@ -66,13 +75,6 @@ public class RestoreHelper { MessageType.GAME_INFO, ctx.getInitiator() == ActionInitiator.Player ? ctx.getCommandSource().getEntity().getUuid() : Util.NIL_UUID ); - - Statics.globalShutdownBackupFlag.set(false); - - return new AwaitThread( - Statics.CONFIG.restoreDelay, - new RestoreBackupRunnable(ctx) - ); } public static List getAvailableBackups(MinecraftServer server) {