Add purge command

This commit is contained in:
Blue (Lukas Rieger) 2020-08-30 22:25:38 +02:00
parent 2e3aa2204c
commit a5817d0897

View File

@ -24,12 +24,15 @@
*/ */
package de.bluecolored.bluemap.common.plugin.commands; package de.bluecolored.bluemap.common.plugin.commands;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.apache.commons.io.FileUtils;
import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i; import com.flowpowered.math.vector.Vector3i;
@ -150,6 +153,13 @@ public void init() {
.executes(this::renderCommand))))) // /bluemap render <world|map> <x> <z> <radius> .executes(this::renderCommand))))) // /bluemap render <world|map> <x> <z> <radius>
.build(); .build();
LiteralCommandNode<S> purgeCommand =
literal("purge")
.requires(requirements("bluemap.render"))
.then(argument("map", StringArgumentType.string()).suggests(new MapSuggestionProvider<>(plugin))
.executes(this::purgeCommand))
.build();
LiteralCommandNode<S> prioRenderCommand = LiteralCommandNode<S> prioRenderCommand =
literal("prioritize") literal("prioritize")
.requires(requirements("bluemap.render")) .requires(requirements("bluemap.render"))
@ -211,6 +221,7 @@ public void init() {
baseCommand.addChild(pauseCommand); baseCommand.addChild(pauseCommand);
baseCommand.addChild(resumeCommand); baseCommand.addChild(resumeCommand);
baseCommand.addChild(renderCommand); baseCommand.addChild(renderCommand);
baseCommand.addChild(purgeCommand);
renderCommand.addChild(prioRenderCommand); renderCommand.addChild(prioRenderCommand);
renderCommand.addChild(cancelRenderCommand); renderCommand.addChild(cancelRenderCommand);
baseCommand.addChild(worldsCommand); baseCommand.addChild(worldsCommand);
@ -476,6 +487,31 @@ public int renderCommand(CommandContext<S> context) {
return 1; return 1;
} }
public int purgeCommand(CommandContext<S> context) {
CommandSource source = commandSourceInterface.apply(context.getSource());
// parse map argument
String mapId = context.getArgument("map", String.class);
new Thread(() -> {
try {
File mapFolder = new File(plugin.getRenderConfig().getWebRoot(), "data" + File.separator + mapId);
if (!mapFolder.exists() || !mapFolder.isDirectory()) {
source.sendMessage(Text.of(TextColor.RED, "There is no map-data to purge for the map-id '" + mapId + "'!"));
return;
}
FileUtils.deleteDirectory(mapFolder);
source.sendMessage(Text.of(TextColor.GREEN, "Map '" + mapId + "' has been successfully purged!"));
} catch (IOException | IllegalArgumentException e) {
source.sendMessage(Text.of(TextColor.RED, "There was an error trying to purge '" + mapId + "', see console for details."));
Logger.global.logError("Failed to purge map '" + mapId + "'!", e);
}
}).start();
return 1;
}
public int prioritizeRenderTaskCommand(CommandContext<S> context) { public int prioritizeRenderTaskCommand(CommandContext<S> context) {
CommandSource source = commandSourceInterface.apply(context.getSource()); CommandSource source = commandSourceInterface.apply(context.getSource());