From 1ea2dc29692676943751f39c99c73b06a106e635 Mon Sep 17 00:00:00 2001 From: szymon Date: Tue, 11 Aug 2020 09:41:46 +0200 Subject: [PATCH] Backup Context now can get MinecraftServer for ServerCommandContext --- .../commands/create/StartBackupCommand.java | 2 -- .../textile_backup/core/create/BackupContext.java | 12 ++++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/commands/create/StartBackupCommand.java b/src/main/java/net/szum123321/textile_backup/commands/create/StartBackupCommand.java index f0f84b4..c5f3df8 100644 --- a/src/main/java/net/szum123321/textile_backup/commands/create/StartBackupCommand.java +++ b/src/main/java/net/szum123321/textile_backup/commands/create/StartBackupCommand.java @@ -41,7 +41,6 @@ public class StartBackupCommand { BackupHelper.create( new BackupContext.Builder() .setCommandSource(ctx.getSource()) - .setServer(ctx.getSource().getMinecraftServer()) .setComment(StringArgumentType.getString(ctx, "comment")) .guessInitiator() .setSave() @@ -58,7 +57,6 @@ public class StartBackupCommand { BackupHelper.create( new BackupContext.Builder() .setCommandSource(source) - .setServer(source.getMinecraftServer()) .guessInitiator() .setSave() .build() diff --git a/src/main/java/net/szum123321/textile_backup/core/create/BackupContext.java b/src/main/java/net/szum123321/textile_backup/core/create/BackupContext.java index cd42b39..efb4678 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/BackupContext.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/BackupContext.java @@ -29,7 +29,7 @@ public class BackupContext { private final boolean save; private final String comment; - protected BackupContext(@NotNull MinecraftServer server, ServerCommandSource commandSource, @NotNull BackupInitiator initiator, boolean save, String comment) { + protected BackupContext(@NotNull MinecraftServer server, ServerCommandSource commandSource, @NotNull BackupInitiator initiator, boolean save, String comment) { this.server = server; this.commandSource = commandSource; this.initiator = initiator; @@ -117,8 +117,12 @@ public class BackupContext { initiator = BackupInitiator.Null; } - if(server == null) - setServer(commandSource.getMinecraftServer()); + if(server == null) { + if(commandSource != null) + setServer(commandSource.getMinecraftServer()); + else + throw new RuntimeException("Both MinecraftServer and ServerCommandSource weren't provided!"); + } return new BackupContext(server, commandSource, initiator, save, comment); } @@ -129,7 +133,7 @@ public class BackupContext { ServerConsole ("Server Console", "from"), Timer ("Timer", "by"), Shutdown ("Server Shutdown", "by"), - Restore ("Backup Restore", "by"), + Restore ("Backup Restoration", "because of"), Null ("Null (That shouldn't have happened)", "form"); private final String name;