Skip to content

Commit c728170

Browse files
committed
Implement API v1.7.0
1 parent 27545f3 commit c728170

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/BlueMapAPIImpl.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,25 @@
2727
import de.bluecolored.bluemap.api.BlueMapAPI;
2828
import de.bluecolored.bluemap.api.BlueMapMap;
2929
import de.bluecolored.bluemap.api.BlueMapWorld;
30-
import de.bluecolored.bluemap.core.map.BmMap;
3130
import de.bluecolored.bluemap.common.api.marker.MarkerAPIImpl;
3231
import de.bluecolored.bluemap.common.api.render.RenderAPIImpl;
3332
import de.bluecolored.bluemap.common.plugin.Plugin;
3433
import de.bluecolored.bluemap.core.BlueMap;
3534
import de.bluecolored.bluemap.core.logger.Logger;
35+
import de.bluecolored.bluemap.core.map.BmMap;
3636
import de.bluecolored.bluemap.core.world.World;
3737
import org.apache.commons.io.FileUtils;
3838

3939
import javax.imageio.ImageIO;
4040
import java.awt.image.BufferedImage;
4141
import java.io.File;
4242
import java.io.IOException;
43-
import java.nio.file.FileSystems;
43+
import java.nio.file.Files;
4444
import java.nio.file.Path;
4545
import java.nio.file.Paths;
4646
import java.util.*;
4747
import java.util.concurrent.ExecutionException;
48+
import java.util.stream.Stream;
4849

4950
public class BlueMapAPIImpl extends BlueMapAPI {
5051

@@ -97,9 +98,10 @@ public Collection<BlueMapWorld> getWorlds() {
9798
@Override
9899
public String createImage(BufferedImage image, String path) throws IOException {
99100
path = path.replaceAll("[^a-zA-Z0-9_.\\-/]", "_");
100-
String separator = FileSystems.getDefault().getSeparator();
101101

102102
Path webRoot = plugin.getRenderConfig().getWebRoot().toPath().toAbsolutePath();
103+
String separator = webRoot.getFileSystem().getSeparator();
104+
103105
Path webDataRoot = webRoot.resolve("data");
104106
Path imagePath = webDataRoot.resolve(Paths.get(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
105107

@@ -113,6 +115,43 @@ public String createImage(BufferedImage image, String path) throws IOException {
113115
return webRoot.relativize(imagePath).toString().replace(separator, "/");
114116
}
115117

118+
@Override
119+
public Map<String, String> availableImages() throws IOException {
120+
Path webRoot = plugin.getRenderConfig().getWebRoot().toPath().toAbsolutePath();
121+
String separator = webRoot.getFileSystem().getSeparator();
122+
123+
Path imageRootPath = webRoot.resolve("data").resolve(IMAGE_ROOT_PATH).toAbsolutePath();
124+
125+
Map<String, String> availableImagesMap = new HashMap<>();
126+
127+
try (Stream<Path> fileStream = Files.walk(imageRootPath)){
128+
fileStream
129+
.filter(p -> !Files.isDirectory(p))
130+
.filter(p -> p.getFileName().toString().endsWith(".png"))
131+
.map(Path::toAbsolutePath)
132+
.forEach(p -> {
133+
try {
134+
String key = imageRootPath.relativize(p).toString();
135+
key = key
136+
.substring(0, key.length() - 4) //remove .png
137+
.replace(separator, "/");
138+
139+
String value = webRoot.relativize(p).toString()
140+
.replace(separator, "/");
141+
142+
availableImagesMap.put(key, value);
143+
} catch (IllegalArgumentException ignore) {}
144+
});
145+
}
146+
147+
return availableImagesMap;
148+
}
149+
150+
@Override
151+
public Path getWebRoot() {
152+
return plugin.getRenderConfig().getWebRoot().toPath();
153+
}
154+
116155
@Override
117156
public String getBlueMapVersion() {
118157
return BlueMap.VERSION;

0 commit comments

Comments
 (0)