Some improvements to logging, Player data now gets saved. Few other things...
parent
7f82664ae7
commit
445f7a5613
|
@ -29,7 +29,6 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.message.MessageFactory;
|
import org.apache.logging.log4j.message.MessageFactory;
|
||||||
import org.apache.logging.log4j.message.ParameterizedMessageFactory;
|
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
|
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);
|
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) {
|
if(source != null && source.getEntity() instanceof PlayerEntity) {
|
||||||
LiteralText text = new LiteralText(messageFactory.newMessage(msg, args).getFormattedMessage());
|
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);
|
text.formatted(Formatting.RED);
|
||||||
else
|
else
|
||||||
text.formatted(Formatting.WHITE);
|
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) {
|
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) {
|
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) {
|
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) {
|
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) {
|
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);
|
log(level, msg, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,9 @@ package net.szum123321.textile_backup.core.create;
|
||||||
|
|
||||||
import net.minecraft.network.MessageType;
|
import net.minecraft.network.MessageType;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.text.MutableText;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.szum123321.textile_backup.Statics;
|
import net.szum123321.textile_backup.Statics;
|
||||||
import net.szum123321.textile_backup.core.ActionInitiator;
|
import net.szum123321.textile_backup.core.ActionInitiator;
|
||||||
|
@ -59,6 +61,7 @@ public class BackupHelper {
|
||||||
if (ctx.shouldSave()) {
|
if (ctx.shouldSave()) {
|
||||||
Statics.LOGGER.sendInfoAL(ctx, "Saving server...");
|
Statics.LOGGER.sendInfoAL(ctx, "Saving server...");
|
||||||
|
|
||||||
|
ctx.getServer().getPlayerManager().saveAllPlayerData();
|
||||||
ctx.getServer().save(true, true, true);
|
ctx.getServer().save(true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +70,7 @@ public class BackupHelper {
|
||||||
|
|
||||||
private static void notifyPlayers(BackupContext ctx) {
|
private static void notifyPlayers(BackupContext ctx) {
|
||||||
MutableText message = Statics.LOGGER.getPrefixText().shallowCopy();
|
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(
|
ctx.getServer().getPlayerManager().broadcastChatMessage(
|
||||||
message,
|
message,
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
package net.szum123321.textile_backup.core.restore;
|
package net.szum123321.textile_backup.core.restore;
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.szum123321.textile_backup.ConfigHandler;
|
import net.szum123321.textile_backup.ConfigHandler;
|
||||||
import net.szum123321.textile_backup.core.ActionInitiator;
|
import net.szum123321.textile_backup.core.ActionInitiator;
|
||||||
import net.szum123321.textile_backup.core.LivingServer;
|
import net.szum123321.textile_backup.core.LivingServer;
|
||||||
|
@ -40,6 +39,8 @@ public class RestoreBackupRunnable implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Statics.globalShutdownBackupFlag.set(false);
|
||||||
|
|
||||||
Statics.LOGGER.info("Shutting down server...");
|
Statics.LOGGER.info("Shutting down server...");
|
||||||
|
|
||||||
ctx.getServer().stop(false);
|
ctx.getServer().stop(false);
|
||||||
|
|
|
@ -58,6 +58,15 @@ public class RestoreHelper {
|
||||||
else
|
else
|
||||||
Statics.LOGGER.info("Backup restoration was initiated form Server Console");
|
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();
|
MutableText message = Statics.LOGGER.getPrefixText().shallowCopy();
|
||||||
message.append("Warning! The server is going to shut down in " + Statics.CONFIG.restoreDelay + " seconds!");
|
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,
|
MessageType.GAME_INFO,
|
||||||
ctx.getInitiator() == ActionInitiator.Player ? ctx.getCommandSource().getEntity().getUuid() : Util.NIL_UUID
|
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) {
|
public static List<RestoreableFile> getAvailableBackups(MinecraftServer server) {
|
||||||
|
|
Loading…
Reference in New Issue