2727import de .bluecolored .bluemap .api .BlueMapAPI ;
2828import de .bluecolored .bluemap .api .BlueMapMap ;
2929import de .bluecolored .bluemap .api .BlueMapWorld ;
30- import de .bluecolored .bluemap .core .map .BmMap ;
3130import de .bluecolored .bluemap .common .api .marker .MarkerAPIImpl ;
3231import de .bluecolored .bluemap .common .api .render .RenderAPIImpl ;
3332import de .bluecolored .bluemap .common .plugin .Plugin ;
3433import de .bluecolored .bluemap .core .BlueMap ;
3534import de .bluecolored .bluemap .core .logger .Logger ;
35+ import de .bluecolored .bluemap .core .map .BmMap ;
3636import de .bluecolored .bluemap .core .world .World ;
3737import org .apache .commons .io .FileUtils ;
3838
3939import javax .imageio .ImageIO ;
4040import java .awt .image .BufferedImage ;
4141import java .io .File ;
4242import java .io .IOException ;
43- import java .nio .file .FileSystems ;
43+ import java .nio .file .Files ;
4444import java .nio .file .Path ;
4545import java .nio .file .Paths ;
4646import java .util .*;
4747import java .util .concurrent .ExecutionException ;
48+ import java .util .stream .Stream ;
4849
4950public 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