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