diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java index 2d056e973..01e177ef2 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java @@ -30,14 +30,14 @@ public abstract class AbstractCommand * @param text The text to display in the success message. * @return 1, indicating that the command was successful. */ - protected int sendSuccessResponse(CommandContext commandContext, String text) + protected int sendSuccessResponse(CommandContext commandContext, String text, boolean notifyAdmins) { #if MC_VER >= MC_1_20_1 - commandContext.getSource().sendSuccess(() -> Component.literal(text), false); + commandContext.getSource().sendSuccess(() -> Component.literal(text), notifyAdmins); #elif MC_VER >= MC_1_19_2 - commandContext.getSource().sendSuccess(Component.literal(text), false); + commandContext.getSource().sendSuccess(Component.literal(text), notifyAdmins); #else - commandContext.getSource().sendSuccess(new TranslatableComponent(text), false); + commandContext.getSource().sendSuccess(new TranslatableComponent(text), notifyAdmins); #endif return 1; } @@ -61,25 +61,6 @@ public abstract class AbstractCommand return 1; } - /** - * Sends a failure response to the player with the given text. - * - * @param commandContext The command context to send the response to. - * @param text The text to display in the failure message. - * @return 1, indicating that the command was successful. - */ - protected int sendSystemMessage(CommandContext commandContext, String text) - { - #if MC_VER >= MC_1_20_1 - commandContext.getSource().sendSystemMessage(Component.literal(text)); - #elif MC_VER >= MC_1_19_2 - commandContext.getSource().sendSystemMessage(Component.literal(text)); - #else - commandContext.getSource().sendSuccess(new TranslatableComponent(text), false); - #endif - return 1; - } - /** * Gets the server player from a command context. * diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/ConfigCommand.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/ConfigCommand.java index 39815693d..dcfe122d9 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/ConfigCommand.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/ConfigCommand.java @@ -63,12 +63,13 @@ public class ConfigCommand extends AbstractCommand "§o" + configEntry.getComment().trim() + "§r\n" + "§7Config file name: §f" + configEntry.name + "§7, category: §f" + configEntry.category + "\n" + "\n" + - "Current value of " + configEntry.getChatCommandName() + " is §n" + configEntry.get() + "§r" + "Current value of " + configEntry.getChatCommandName() + " is §n" + configEntry.get() + "§r", + false )); ToIntBiFunction, Object> updateConfigValue = (commandContext, value) -> { configEntry.set(value); - return this.sendSuccessResponse(commandContext, "Changed the value of ["+configEntry.getChatCommandName()+"] to ["+value+"]"); + return this.sendSuccessResponse(commandContext, "Changed the value of [" + configEntry.getChatCommandName() + "] to [" + value + "]", true); }; // Enum type needs a special case since enums aren't represented by existing argument type diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/DebugCommand.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/DebugCommand.java index fd67ec8f8..88b1c8311 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/DebugCommand.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/DebugCommand.java @@ -18,7 +18,7 @@ public class DebugCommand extends AbstractCommand .executes(c -> { List lines = new ArrayList<>(); F3Screen.addStringToDisplay(lines); - return this.sendSuccessResponse(c, String.join("\n", lines)); + return this.sendSuccessResponse(c, String.join("\n", lines), false); }); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java index 76f0ff207..32a698306 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java @@ -12,6 +12,7 @@ import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerLevel; +import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; @@ -47,19 +48,21 @@ public class PregenCommand extends AbstractCommand private int pregenStatus(CommandContext c) { - if (this.pregenManager.getRunningPregen() != null) + String statusString = this.pregenManager.getStatusString(); + //noinspection ReplaceNullCheck + if (statusString != null) { - return this.sendSuccessResponse(c, "Pregen is running"); + return this.sendSuccessResponse(c, statusString, false); } else { - return this.sendSuccessResponse(c, "Pregen is not running"); + return this.sendSuccessResponse(c, "Pregen is not running", false); } } private int pregenStart(CommandContext c) throws CommandSyntaxException { - this.sendSuccessResponse(c, "Starting pregen"); + this.sendSuccessResponse(c, "Starting pregen. Progress will be in the server console.", true); ServerLevel level = DimensionArgument.getDimension(c, "dimension"); ColumnPos origin = ColumnPosArgument.getColumnPos(c, "origin"); @@ -68,18 +71,22 @@ public class PregenCommand extends AbstractCommand CompletableFuture future = this.pregenManager.startPregen( ServerLevelWrapper.getWrapper(level), new DhBlockPos2D(#if MC_VER >= MC_1_19_2 origin.x(), origin.z() #else origin.x, origin.z #endif), - chunkRadius, - update -> this.sendSystemMessage(c, update) + chunkRadius ); future.whenComplete((result, throwable) -> { - if (throwable != null) + if (throwable instanceof CancellationException) + { + this.sendSuccessResponse(c, "Pregen is cancelled", true); + return; + } + else if (throwable != null) { this.sendFailureResponse(c, "Pregen failed: " + throwable.getMessage() + "\n Check the logs for more details."); return; } - this.sendSuccessResponse(c, "Pregen is complete"); + this.sendSuccessResponse(c, "Pregen is complete", true); }); return 1; @@ -88,11 +95,12 @@ public class PregenCommand extends AbstractCommand private int pregenStop(CommandContext c) { CompletableFuture runningPregen = this.pregenManager.getRunningPregen(); - if (runningPregen != null) + if (runningPregen == null) { - runningPregen.cancel(true); + return this.sendFailureResponse(c, "Pregen is not running"); } + runningPregen.cancel(true); return 1; } diff --git a/coreSubProjects b/coreSubProjects index cc2b7f607..9adcfd814 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit cc2b7f60785811ff33a882a0780f41c0c165693b +Subproject commit 9adcfd8143b6055168828e144624fa0db7b26b45