Skip to content

Commit

Permalink
Add -m option to cli, which allows to filter the maps that should be …
Browse files Browse the repository at this point in the history
…loaded and rendered
  • Loading branch information
TBlueF committed Jan 23, 2024
1 parent 6a10fac commit 61f883b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,14 +64,16 @@
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 {

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");
Expand All @@ -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<>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 61f883b

Please sign in to comment.