Some improvements to logging, Player data now gets saved. Few other things...

This commit is contained in:
szymon 2020-12-05 23:14:35 +01:00
parent 7f82664ae7
commit 445f7a5613
4 changed files with 26 additions and 15 deletions

View File

@ -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);
}

View File

@ -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,

View File

@ -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);

View File

@ -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<RestoreableFile> getAvailableBackups(MinecraftServer server) {