From d06ab7fe5d98c5d3f65e53ed0341fd2aa811dcc0 Mon Sep 17 00:00:00 2001 From: szymon Date: Tue, 11 Aug 2020 09:53:55 +0200 Subject: [PATCH] Shutdown backup starting code moved to SERVER_STOPPED event --- .../textile_backup/TextileBackup.java | 18 ++++++++++++++++-- .../mixin/MinecraftServerMixin.java | 17 +---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/TextileBackup.java b/src/main/java/net/szum123321/textile_backup/TextileBackup.java index 73f2845..56f68b7 100644 --- a/src/main/java/net/szum123321/textile_backup/TextileBackup.java +++ b/src/main/java/net/szum123321/textile_backup/TextileBackup.java @@ -33,6 +33,8 @@ import net.szum123321.textile_backup.commands.permission.WhitelistCommand; import net.szum123321.textile_backup.commands.restore.KillRestoreCommand; import net.szum123321.textile_backup.commands.restore.ListBackupsCommand; import net.szum123321.textile_backup.commands.restore.RestoreBackupCommand; +import net.szum123321.textile_backup.core.create.BackupContext; +import net.szum123321.textile_backup.core.create.BackupHelper; import java.util.Optional; import java.util.concurrent.Executors; @@ -46,7 +48,7 @@ public class TextileBackup implements ModInitializer { Optional errorMessage = Statics.CONFIG.sanitize(); if(errorMessage.isPresent()) { - Statics.LOGGER.fatal("TextileBackup config file has wrong settings! \n {}", errorMessage.get()); + Statics.LOGGER.fatal("TextileBackup config file has wrong settings!\n{}", errorMessage.get()); System.exit(1); } @@ -58,7 +60,19 @@ public class TextileBackup implements ModInitializer { Statics.executorService = Executors.newSingleThreadExecutor(); }); - ServerLifecycleEvents.SERVER_STOPPED.register(ignored -> Statics.executorService.shutdown()); + ServerLifecycleEvents.SERVER_STOPPED.register(server -> { + Statics.executorService.shutdown(); + + if (Statics.CONFIG.shutdownBackup && Statics.globalShutdownBackupFlag.get()) { + BackupHelper.create( + new BackupContext.Builder() + .setServer(server) + .setInitiator(BackupContext.BackupInitiator.Shutdown) + .setComment("shutdown") + .build() + ).run(); + } + }); CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register( LiteralArgumentBuilder.literal("backup") diff --git a/src/main/java/net/szum123321/textile_backup/mixin/MinecraftServerMixin.java b/src/main/java/net/szum123321/textile_backup/mixin/MinecraftServerMixin.java index f532094..32fba19 100644 --- a/src/main/java/net/szum123321/textile_backup/mixin/MinecraftServerMixin.java +++ b/src/main/java/net/szum123321/textile_backup/mixin/MinecraftServerMixin.java @@ -20,9 +20,6 @@ package net.szum123321.textile_backup.mixin; import net.minecraft.server.MinecraftServer; import net.szum123321.textile_backup.core.LivingServer; -import net.szum123321.textile_backup.Statics; -import net.szum123321.textile_backup.core.create.BackupContext; -import net.szum123321.textile_backup.core.create.BackupHelper; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -32,20 +29,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MinecraftServerMixin implements LivingServer { private boolean isAlive = true; - @Inject(method = "shutdown", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/server/MinecraftServer;save(ZZZ)Z")) + @Inject(method = "shutdown", at = @At("TAIL")) public void onFinalWorldSave(CallbackInfo ci) { - if (Statics.CONFIG.shutdownBackup && Statics.globalShutdownBackupFlag.get()) { - Statics.executorService.submit( - BackupHelper.create( - new BackupContext.Builder() - .setServer((MinecraftServer) (Object) this) - .setInitiator(BackupContext.BackupInitiator.Shutdown) - .setComment("shutdown") - .build() - ) - ); - } - isAlive = false; }