Added executor service shutdown
parent
944713beb5
commit
e4f5eb1c88
|
@ -23,6 +23,7 @@ import io.github.cottonmc.cotton.config.ConfigManager;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.szum123321.textile_backup.commands.BlacklistCommand;
|
import net.szum123321.textile_backup.commands.BlacklistCommand;
|
||||||
|
@ -60,6 +61,8 @@ public class TextileBackup implements ModInitializer {
|
||||||
if(TextileBackup.config.backupInterval > 0)
|
if(TextileBackup.config.backupInterval > 0)
|
||||||
ServerTickEvents.END_SERVER_TICK.register(scheduler::tick);
|
ServerTickEvents.END_SERVER_TICK.register(scheduler::tick);
|
||||||
|
|
||||||
|
ServerLifecycleEvents.SERVER_STOPPED.register(ignored -> executorService.shutdown());
|
||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(
|
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(
|
||||||
LiteralArgumentBuilder.<ServerCommandSource>literal("backup")
|
LiteralArgumentBuilder.<ServerCommandSource>literal("backup")
|
||||||
.requires((ctx) -> {
|
.requires((ctx) -> {
|
||||||
|
|
|
@ -19,42 +19,18 @@
|
||||||
package net.szum123321.textile_backup.mixin;
|
package net.szum123321.textile_backup.mixin;
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.PlayerManager;
|
|
||||||
import net.szum123321.textile_backup.TextileBackup;
|
import net.szum123321.textile_backup.TextileBackup;
|
||||||
import net.szum123321.textile_backup.core.BackupHelper;
|
import net.szum123321.textile_backup.core.BackupHelper;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.util.function.BooleanSupplier;
|
|
||||||
|
|
||||||
@Mixin(MinecraftServer.class)
|
@Mixin(MinecraftServer.class)
|
||||||
public abstract class MinecraftServerMixin {
|
public abstract class MinecraftServerMixin {
|
||||||
/*
|
|
||||||
@Shadow private long timeReference;
|
|
||||||
|
|
||||||
@Shadow public abstract PlayerManager getPlayerManager();
|
|
||||||
|
|
||||||
private long lastBackup = 0;
|
|
||||||
|
|
||||||
@Inject(method = "tick", at = @At("HEAD"))
|
|
||||||
public void tick(BooleanSupplier shouldKeepTicking, CallbackInfo ci){
|
|
||||||
if(timeReference - lastBackup >= TextileBackup.config.backupInterval * 1000){
|
|
||||||
if(getPlayerManager().getCurrentPlayerCount() == 0 && !TextileBackup.config.doBackupsOnEmptyServer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lastBackup = timeReference;
|
|
||||||
|
|
||||||
BackupHelper.create((MinecraftServer)(Object)this, null, true, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@Inject(method = "shutdown", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/server/MinecraftServer;save(ZZZ)Z"))
|
@Inject(method = "shutdown", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/server/MinecraftServer;save(ZZZ)Z"))
|
||||||
public void onShutdown(CallbackInfo ci){
|
public void onShutdown(CallbackInfo ci){
|
||||||
if(TextileBackup.config.shutdownBackup) {
|
if(TextileBackup.config.shutdownBackup)
|
||||||
BackupHelper.create((MinecraftServer) (Object) this, null, false, "shutdown").run();
|
TextileBackup.executorService.submit(BackupHelper.create((MinecraftServer) (Object) this, null, false, "shutdown"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue