mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-22 10:35:16 +01:00
Add -m option to cli, which allows to filter the maps that should be loaded and rendered
This commit is contained in:
parent
6a10fac624
commit
61f883b134
@ -63,6 +63,7 @@
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -180,20 +181,29 @@ public synchronized void createOrUpdateWebApp(boolean force) throws Configuratio
|
||||
}
|
||||
|
||||
public synchronized Map<String, World> getWorlds() throws InterruptedException {
|
||||
if (worlds == null) loadWorldsAndMaps();
|
||||
return getWorlds(mapId -> true);
|
||||
}
|
||||
|
||||
public synchronized Map<String, World> getWorlds(Predicate<String> mapFilter) throws InterruptedException {
|
||||
if (worlds == null) loadWorldsAndMaps(mapFilter);
|
||||
return worlds;
|
||||
}
|
||||
|
||||
public synchronized Map<String, BmMap> getMaps() throws InterruptedException {
|
||||
if (maps == null) loadWorldsAndMaps();
|
||||
return getMaps(mapId -> true);
|
||||
}
|
||||
|
||||
public synchronized Map<String, BmMap> getMaps(Predicate<String> mapFilter) throws InterruptedException {
|
||||
if (maps == null) loadWorldsAndMaps(mapFilter);
|
||||
return maps;
|
||||
}
|
||||
|
||||
private synchronized void loadWorldsAndMaps() throws InterruptedException {
|
||||
private synchronized void loadWorldsAndMaps(Predicate<String> mapFilter) throws InterruptedException {
|
||||
maps = new HashMap<>();
|
||||
worlds = new HashMap<>();
|
||||
|
||||
for (var entry : configs.getMapConfigs().entrySet()) {
|
||||
if (!mapFilter.test(entry.getKey())) continue;
|
||||
try {
|
||||
loadMapConfig(entry.getKey(), entry.getValue());
|
||||
} catch (ConfigurationException ex) {
|
||||
|
@ -51,6 +51,7 @@
|
||||
import de.bluecolored.bluemap.core.util.FileHelper;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.apache.commons.lang3.time.DurationFormatUtils;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -63,6 +64,7 @@
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class BlueMapCLI implements ServerInterface {
|
||||
@ -70,7 +72,8 @@ public class BlueMapCLI implements ServerInterface {
|
||||
private MinecraftVersion minecraftVersion = MinecraftVersion.LATEST_SUPPORTED;
|
||||
private Path configFolder;
|
||||
|
||||
public void renderMaps(BlueMapService blueMap, boolean watch, boolean forceRender, boolean forceGenerateWebapp) throws ConfigurationException, IOException, InterruptedException {
|
||||
public void renderMaps(BlueMapService blueMap, boolean watch, boolean forceRender, boolean forceGenerateWebapp,
|
||||
@Nullable String mapsToRender) throws ConfigurationException, IOException, InterruptedException {
|
||||
|
||||
//metrics report
|
||||
if (blueMap.getConfigs().getCoreConfig().isMetrics()) Metrics.sendReportAsync("cli");
|
||||
@ -85,7 +88,12 @@ public void renderMaps(BlueMapService blueMap, boolean watch, boolean forceRende
|
||||
RenderManager renderManager = new RenderManager();
|
||||
|
||||
//load maps
|
||||
Map<String, BmMap> maps = blueMap.getMaps();
|
||||
Predicate<String> mapFilter = mapId -> true;
|
||||
if (mapsToRender != null) {
|
||||
Set<String> mapsToRenderSet = Set.of(mapsToRender.split(","));
|
||||
mapFilter = mapsToRenderSet::contains;
|
||||
}
|
||||
Map<String, BmMap> maps = blueMap.getMaps(mapFilter);
|
||||
|
||||
//watcher
|
||||
List<RegionFileWatchService> regionFileWatchServices = new ArrayList<>();
|
||||
@ -362,7 +370,8 @@ public static void main(String[] args) {
|
||||
boolean watch = cmd.hasOption("u");
|
||||
boolean force = cmd.hasOption("f");
|
||||
boolean generateWebappFiles = cmd.hasOption("g");
|
||||
cli.renderMaps(blueMap, watch, force, generateWebappFiles);
|
||||
String mapsToRender = cmd.getOptionValue("m", null);
|
||||
cli.renderMaps(blueMap, watch, force, generateWebappFiles, mapsToRender);
|
||||
} else {
|
||||
if (cmd.hasOption("g")) {
|
||||
noActions = false;
|
||||
@ -458,6 +467,7 @@ private static Options createOptions() {
|
||||
|
||||
options.addOption("r", "render", false, "Renders the maps configured in the 'render.conf' file");
|
||||
options.addOption("f", "force-render", false, "Forces rendering everything, instead of only rendering chunks that have been modified since the last render");
|
||||
options.addOption("m", "maps", true, "A comma-separated list of map-id's that should be rendered. Example: 'world,nether'");
|
||||
|
||||
options.addOption("u", "watch", false, "Watches for file-changes after rendering and updates the map");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user