Skip to content

Commit

Permalink
Add resume command (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrek0429 authored Mar 30, 2024
1 parent 6d011ee commit d8cb25f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
13 changes: 10 additions & 3 deletions core/src/main/java/net/pl3x/map/core/configuration/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,18 @@ public final class Lang extends AbstractConfig {
public static String COMMAND_HIDE_SUCCESS = "<grey><player> <green>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 = "<green>Renderers are now paused";
@Key("command.pause.unpaused")
public static String COMMAND_PAUSE_UNPAUSED = "<green>Renderers are now unpaused";
@Key("command.pause.already-paused")
public static String COMMAND_PAUSE_ALREADY_PAUSED = "<grey>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 = "<green>Renderers have now resumed";
@Key("command.resume.already-resumed")
public static String COMMAND_RESUME_ALREADY_RESUMED = "<grey>Renderers have already resumed";

@Key("command.radiusrender.description")
public static String COMMAND_RADIUSRENDER_DESCRIPTION = "Render a section of a world";
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/resources/locale/lang-pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ command:
already-hidden: <grey><player> <red>jest już ukryty na mapie
success: <grey><player> <green>jest teraz ukryty na mapie
pause:
description: Przełącz stan wstrzymania renderowania
description: Wstrzymaj renderery
paused: <green>Renderery są teraz wstrzymane
unpaused: <green>Renderery są teraz wznawiane
already-paused: <grey>Renderery już są wstrzymane
resume:
description: Wznów renderery
resumed: <green>Renderery są teraz wznowione
already-resumed: <grey>Renderery już są wznowione
radiusrender:
description: Renderuj sekcję świata
starting: <green>Rozpoczęcie renderowania promienia. Sprawdź <grey>/map status</grey>
Expand Down

0 comments on commit d8cb25f

Please sign in to comment.