Added newBackupContextBuilder function to BackupContext.Builder and simplified StartBackupCommand
This commit is contained in:
parent
06f80a9175
commit
eba22e8464
@ -76,7 +76,8 @@ public class TextileBackup implements ModInitializer {
|
||||
|
||||
if (Statics.CONFIG.shutdownBackup && Statics.globalShutdownBackupFlag.get()) {
|
||||
BackupHelper.create(
|
||||
new BackupContext.Builder()
|
||||
BackupContext.Builder
|
||||
.newBackupContextBuilder()
|
||||
.setServer(server)
|
||||
.setInitiator(ActionInitiator.Shutdown)
|
||||
.setComment("shutdown")
|
||||
|
@ -20,48 +20,41 @@ package net.szum123321.textile_backup.commands.create;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.szum123321.textile_backup.Statics;
|
||||
import net.szum123321.textile_backup.core.create.BackupContext;
|
||||
import net.szum123321.textile_backup.core.create.BackupHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StartBackupCommand {
|
||||
public static LiteralArgumentBuilder<ServerCommandSource> register() {
|
||||
return CommandManager.literal("start")
|
||||
.then(CommandManager.argument("comment", StringArgumentType.string())
|
||||
.executes(StartBackupCommand::executeWithComment)
|
||||
).executes(ctx -> execute(ctx.getSource()));
|
||||
.executes(ctx -> execute(ctx.getSource(), StringArgumentType.getString(ctx, "comment")))
|
||||
).executes(ctx -> execute(ctx.getSource(), null));
|
||||
}
|
||||
|
||||
private static int executeWithComment(CommandContext<ServerCommandSource> ctx) {
|
||||
if(!Statics.executorService.isShutdown())
|
||||
private static int execute(ServerCommandSource source, @Nullable String comment) {
|
||||
if(!Statics.executorService.isShutdown()) {
|
||||
try {
|
||||
Statics.executorService.submit(
|
||||
BackupHelper.create(
|
||||
new BackupContext.Builder()
|
||||
.setCommandSource(ctx.getSource())
|
||||
.setComment(StringArgumentType.getString(ctx, "comment"))
|
||||
.guessInitiator()
|
||||
.saveServer()
|
||||
.build()
|
||||
)
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int execute(ServerCommandSource source){
|
||||
if(!Statics.executorService.isShutdown())
|
||||
Statics.executorService.submit(
|
||||
BackupHelper.create(
|
||||
new BackupContext.Builder()
|
||||
BackupContext.Builder
|
||||
.newBackupContextBuilder()
|
||||
.setCommandSource(source)
|
||||
.setComment(comment)
|
||||
.guessInitiator()
|
||||
.saveServer()
|
||||
.build()
|
||||
)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
Statics.LOGGER.error("Something went wrong while executing command!", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ public class BackupScheduler {
|
||||
if(nextBackup <= now) {
|
||||
Statics.executorService.submit(
|
||||
BackupHelper.create(
|
||||
new BackupContext.Builder()
|
||||
BackupContext.Builder
|
||||
.newBackupContextBuilder()
|
||||
.setServer(server)
|
||||
.setInitiator(ActionInitiator.Timer)
|
||||
.saveServer()
|
||||
@ -59,7 +60,8 @@ public class BackupScheduler {
|
||||
if(scheduled && nextBackup <= now) {
|
||||
Statics.executorService.submit(
|
||||
BackupHelper.create(
|
||||
new BackupContext.Builder()
|
||||
BackupContext.Builder
|
||||
.newBackupContextBuilder()
|
||||
.setServer(server)
|
||||
.setInitiator(ActionInitiator.Timer)
|
||||
.saveServer()
|
||||
|
Loading…
Reference in New Issue
Block a user