From d8cb25f59d4fe54cbda24b699760a19f35bec9b7 Mon Sep 17 00:00:00 2001 From: Andrzej Bansleben <64475360+jedrek0429@users.noreply.github.com> Date: Sat, 30 Mar 2024 12:30:04 +0100 Subject: [PATCH] Add `resume` command (#32) --- .../pl3x/map/core/command/CommandHandler.java | 2 + .../core/command/commands/PauseCommand.java | 11 ++-- .../core/command/commands/ResumeCommand.java | 61 +++++++++++++++++++ .../net/pl3x/map/core/configuration/Lang.java | 13 +++- core/src/main/resources/locale/lang-pl.yml | 8 ++- 5 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/net/pl3x/map/core/command/commands/ResumeCommand.java diff --git a/core/src/main/java/net/pl3x/map/core/command/CommandHandler.java b/core/src/main/java/net/pl3x/map/core/command/CommandHandler.java index 43065c88f..bab0efe0b 100644 --- a/core/src/main/java/net/pl3x/map/core/command/CommandHandler.java +++ b/core/src/main/java/net/pl3x/map/core/command/CommandHandler.java @@ -37,6 +37,7 @@ import net.pl3x.map.core.command.commands.HelpCommand; import net.pl3x.map.core.command.commands.HideCommand; import net.pl3x.map.core.command.commands.PauseCommand; +import net.pl3x.map.core.command.commands.ResumeCommand; import net.pl3x.map.core.command.commands.RadiusRenderCommand; import net.pl3x.map.core.command.commands.ReloadCommand; import net.pl3x.map.core.command.commands.ResetMapCommand; @@ -106,6 +107,7 @@ default void registerSubcommands() { new HelpCommand(this), new HideCommand(this), new PauseCommand(this), + new ResumeCommand(this), new RadiusRenderCommand(this), new ReloadCommand(this), new ResetMapCommand(this), diff --git a/core/src/main/java/net/pl3x/map/core/command/commands/PauseCommand.java b/core/src/main/java/net/pl3x/map/core/command/commands/PauseCommand.java index c9d2b5cd3..241f5a783 100644 --- a/core/src/main/java/net/pl3x/map/core/command/commands/PauseCommand.java +++ b/core/src/main/java/net/pl3x/map/core/command/commands/PauseCommand.java @@ -51,14 +51,11 @@ private void execute(@NotNull CommandContext<@NotNull Sender> context) { RegionProcessor processor = Pl3xMap.api().getRegionProcessor(); - boolean paused = !processor.isPaused(); - - processor.setPaused(paused); - - if (paused) { - sender.sendMessage(Lang.COMMAND_PAUSE_PAUSED); + if (processor.isPaused()) { + sender.sendMessage(Lang.COMMAND_PAUSE_ALREADY_PAUSED); } else { - sender.sendMessage(Lang.COMMAND_PAUSE_UNPAUSED); + processor.setPaused(true); + sender.sendMessage(Lang.COMMAND_PAUSE_PAUSED); } } } diff --git a/core/src/main/java/net/pl3x/map/core/command/commands/ResumeCommand.java b/core/src/main/java/net/pl3x/map/core/command/commands/ResumeCommand.java new file mode 100644 index 000000000..430b0aba4 --- /dev/null +++ b/core/src/main/java/net/pl3x/map/core/command/commands/ResumeCommand.java @@ -0,0 +1,61 @@ +/* + * MIT License + * + * Copyright (c) 2020-2023 William Blake Galbreath + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.pl3x.map.core.command.commands; + +import cloud.commandframework.context.CommandContext; +import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys; +import net.pl3x.map.core.Pl3xMap; +import net.pl3x.map.core.command.CommandHandler; +import net.pl3x.map.core.command.Pl3xMapCommand; +import net.pl3x.map.core.command.Sender; +import net.pl3x.map.core.configuration.Lang; +import net.pl3x.map.core.renderer.task.RegionProcessor; +import org.jetbrains.annotations.NotNull; + +public class ResumeCommand extends Pl3xMapCommand { + public ResumeCommand(@NotNull CommandHandler handler) { + super(handler); + } + + @Override + public void register() { + getHandler().registerSubcommand(builder -> builder.literal("resume") + .meta(MinecraftExtrasMetaKeys.DESCRIPTION, Lang.parse(Lang.COMMAND_RESUME_DESCRIPTION)) + .permission("pl3xmap.command.resume") + .handler(this::execute)); + } + + private void execute(@NotNull CommandContext<@NotNull Sender> context) { + Sender sender = context.getSender(); + + RegionProcessor processor = Pl3xMap.api().getRegionProcessor(); + + if (!processor.isPaused()) { + sender.sendMessage(Lang.COMMAND_RESUME_ALREADY_RESUMED); + } else { + processor.setPaused(false); + sender.sendMessage(Lang.COMMAND_RESUME_RESUMED); + } + } +} diff --git a/core/src/main/java/net/pl3x/map/core/configuration/Lang.java b/core/src/main/java/net/pl3x/map/core/configuration/Lang.java index 025d6b68f..ff7f22833 100644 --- a/core/src/main/java/net/pl3x/map/core/configuration/Lang.java +++ b/core/src/main/java/net/pl3x/map/core/configuration/Lang.java @@ -93,11 +93,18 @@ public final class Lang extends AbstractConfig { public static String COMMAND_HIDE_SUCCESS = " is now hidden from the map"; @Key("command.pause.description") - public static String COMMAND_PAUSE_DESCRIPTION = "Toggle the pause state of renderers"; + public static String COMMAND_PAUSE_DESCRIPTION = "Pause renderers"; @Key("command.pause.paused") public static String COMMAND_PAUSE_PAUSED = "Renderers are now paused"; - @Key("command.pause.unpaused") - public static String COMMAND_PAUSE_UNPAUSED = "Renderers are now unpaused"; + @Key("command.pause.already-paused") + public static String COMMAND_PAUSE_ALREADY_PAUSED = "Renderers are already paused"; + + @Key("command.resume.description") + public static String COMMAND_RESUME_DESCRIPTION = "Resume renderers"; + @Key("command.resume.resumed") + public static String COMMAND_RESUME_RESUMED = "Renderers have now resumed"; + @Key("command.resume.already-resumed") + public static String COMMAND_RESUME_ALREADY_RESUMED = "Renderers have already resumed"; @Key("command.radiusrender.description") public static String COMMAND_RADIUSRENDER_DESCRIPTION = "Render a section of a world"; diff --git a/core/src/main/resources/locale/lang-pl.yml b/core/src/main/resources/locale/lang-pl.yml index 7c392120e..a0125b896 100644 --- a/core/src/main/resources/locale/lang-pl.yml +++ b/core/src/main/resources/locale/lang-pl.yml @@ -29,9 +29,13 @@ command: already-hidden: jest już ukryty na mapie success: jest teraz ukryty na mapie pause: - description: Przełącz stan wstrzymania renderowania + description: Wstrzymaj renderery paused: Renderery są teraz wstrzymane - unpaused: Renderery są teraz wznawiane + already-paused: Renderery już są wstrzymane + resume: + description: Wznów renderery + resumed: Renderery są teraz wznowione + already-resumed: Renderery już są wznowione radiusrender: description: Renderuj sekcję świata starting: Rozpoczęcie renderowania promienia. Sprawdź /map status