Shutdown backup starting code moved to SERVER_STOPPED event
This commit is contained in:
parent
67fe75667b
commit
d06ab7fe5d
@ -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<String> 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.<ServerCommandSource>literal("backup")
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user