From af8e14f092ff51dad22bba4abef4205a56afbf91 Mon Sep 17 00:00:00 2001 From: szymon Date: Sat, 19 Jun 2021 14:42:22 +0200 Subject: [PATCH] Repaired #42 --- .../net/szum123321/textile_backup/Statics.java | 1 + .../core/create/BackupHelper.java | 8 +++----- .../core/create/MakeBackupRunnable.java | 2 ++ .../mixin/DedicatedServerWatchdogMixin.java | 17 +++++++++++++++++ src/main/resources/textile_backup.mixins.json | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/szum123321/textile_backup/mixin/DedicatedServerWatchdogMixin.java diff --git a/src/main/java/net/szum123321/textile_backup/Statics.java b/src/main/java/net/szum123321/textile_backup/Statics.java index 995a40c..c56212c 100644 --- a/src/main/java/net/szum123321/textile_backup/Statics.java +++ b/src/main/java/net/szum123321/textile_backup/Statics.java @@ -40,6 +40,7 @@ public class Statics { public final static DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss"); public static final AtomicBoolean globalShutdownBackupFlag = new AtomicBoolean(true); + public static boolean disableWatchdog = false; public static AwaitThread restoreAwaitThread = null; public static File untouchableFile; 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 4063861..deb8157 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,8 +20,6 @@ package net.szum123321.textile_backup.core.create; import net.minecraft.network.MessageType; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.util.Formatting; @@ -69,10 +67,9 @@ public class BackupHelper { try { ctx.getServer().save(false, true, true); } catch (Exception e) { - Statics.LOGGER.sendErrorAL(ctx,"An exception occurred when trying to save the world!\n" - + "But don't worry, backup will continue, although data may be not up-to-date." + Statics.LOGGER.sendErrorAL(ctx,"An exception occurred when trying to save the world!" ); - +/* MutableText text = Statics.LOGGER.getPrefixText() .append(new LiteralText("In order for backup to be up-to-date call ").formatted(Formatting.WHITE)) .append( @@ -106,6 +103,7 @@ public class BackupHelper { Statics.LOGGER.sendError(ctx, "If you have access to server console please take a look at it."); Statics.LOGGER.error("Please let me know about this situation, include below error, mod's config, additional mods, where is the server running etc.", e); + */ } } diff --git a/src/main/java/net/szum123321/textile_backup/core/create/MakeBackupRunnable.java b/src/main/java/net/szum123321/textile_backup/core/create/MakeBackupRunnable.java index 3bf1520..5138a37 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/MakeBackupRunnable.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/MakeBackupRunnable.java @@ -43,6 +43,7 @@ public class MakeBackupRunnable implements Runnable { public void run() { try { Utilities.disableWorldSaving(context.getServer()); + Statics.disableWatchdog = true; Statics.LOGGER.sendInfoAL(context, "Starting backup"); @@ -109,6 +110,7 @@ public class MakeBackupRunnable implements Runnable { Statics.LOGGER.sendInfoAL(context, "Done!"); } finally { Utilities.enableWorldSaving(context.getServer()); + Statics.disableWatchdog = false; } } diff --git a/src/main/java/net/szum123321/textile_backup/mixin/DedicatedServerWatchdogMixin.java b/src/main/java/net/szum123321/textile_backup/mixin/DedicatedServerWatchdogMixin.java new file mode 100644 index 0000000..91393b2 --- /dev/null +++ b/src/main/java/net/szum123321/textile_backup/mixin/DedicatedServerWatchdogMixin.java @@ -0,0 +1,17 @@ +package net.szum123321.textile_backup.mixin; + +import net.minecraft.server.dedicated.DedicatedServerWatchdog; +import net.minecraft.util.Util; +import net.szum123321.textile_backup.Statics; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(DedicatedServerWatchdog.class) +public class DedicatedServerWatchdogMixin { + + @ModifyVariable(method = "run()V", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/util/Util;getMeasuringTimeMs()J"), ordinal = 0, name = "l") + private long redirectedCall(long original) { + return Statics.disableWatchdog ? Util.getMeasuringTimeMs() : original; + } +} diff --git a/src/main/resources/textile_backup.mixins.json b/src/main/resources/textile_backup.mixins.json index 9260b26..82c2d00 100644 --- a/src/main/resources/textile_backup.mixins.json +++ b/src/main/resources/textile_backup.mixins.json @@ -3,6 +3,7 @@ "package": "net.szum123321.textile_backup.mixin", "compatibilityLevel": "JAVA_16", "mixins": [ + "DedicatedServerWatchdogMixin", "MinecraftServerMixin", "MinecraftServerSessionAccessor" ],