Skip to content

Commit d4f0068

Browse files
committed
Fix web-app api throwing an error and add full errors to the StateDumper
1 parent 38f23f2 commit d4f0068

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.stream.Stream;
1515

1616
public class WebAppImpl implements WebApp {
17-
private static final String IMAGE_ROOT_PATH = "images";
17+
private static final Path IMAGE_ROOT_PATH = Path.of("data", "images");
1818

1919
private final Plugin plugin;
2020

@@ -43,9 +43,10 @@ public String createImage(BufferedImage image, String path) throws IOException {
4343
Path webRoot = getWebRoot().toAbsolutePath();
4444
String separator = webRoot.getFileSystem().getSeparator();
4545

46-
Path webDataRoot = webRoot.resolve("data");
47-
Path imagePath = webDataRoot.resolve(Path.of(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
46+
Path imageRootFolder = webRoot.resolve(IMAGE_ROOT_PATH);
47+
Path imagePath = imageRootFolder.resolve(Path.of(path.replace("/", separator) + ".png")).toAbsolutePath();
4848

49+
Files.createDirectories(imagePath.getParent());
4950
Files.deleteIfExists(imagePath);
5051
Files.createFile(imagePath);
5152

@@ -64,24 +65,27 @@ public Map<String, String> availableImages() throws IOException {
6465

6566
Map<String, String> availableImagesMap = new HashMap<>();
6667

67-
try (Stream<Path> fileStream = Files.walk(imageRootPath)){
68-
fileStream
69-
.filter(p -> !Files.isDirectory(p))
70-
.filter(p -> p.getFileName().toString().endsWith(".png"))
71-
.map(Path::toAbsolutePath)
72-
.forEach(p -> {
73-
try {
74-
String key = imageRootPath.relativize(p).toString();
75-
key = key
76-
.substring(0, key.length() - 4) //remove .png
77-
.replace(separator, "/");
78-
79-
String value = webRoot.relativize(p).toString()
80-
.replace(separator, "/");
81-
82-
availableImagesMap.put(key, value);
83-
} catch (IllegalArgumentException ignore) {}
84-
});
68+
if (Files.exists(imageRootPath)) {
69+
try (Stream<Path> fileStream = Files.walk(imageRootPath)) {
70+
fileStream
71+
.filter(p -> !Files.isDirectory(p))
72+
.filter(p -> p.getFileName().toString().endsWith(".png"))
73+
.map(Path::toAbsolutePath)
74+
.forEach(p -> {
75+
try {
76+
String key = imageRootPath.relativize(p).toString();
77+
key = key
78+
.substring(0, key.length() - 4) //remove .png
79+
.replace(separator, "/");
80+
81+
String value = webRoot.relativize(p).toString()
82+
.replace(separator, "/");
83+
84+
availableImagesMap.put(key, value);
85+
} catch (IllegalArgumentException ignore) {
86+
}
87+
});
88+
}
8589
}
8690

8791
return availableImagesMap;

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.spongepowered.configurate.serialize.SerializationException;
3333

3434
import java.io.IOException;
35+
import java.io.PrintWriter;
36+
import java.io.StringWriter;
3537
import java.lang.reflect.Field;
3638
import java.lang.reflect.Method;
3739
import java.lang.reflect.Modifier;
@@ -168,7 +170,9 @@ private void dumpInstance(Object instance, ConfigurationOptions options, Configu
168170
}
169171

170172
} catch (Exception ex) {
171-
node.set("Error: " + ex);
173+
StringWriter stringWriter = new StringWriter();
174+
ex.printStackTrace(new PrintWriter(stringWriter));
175+
node.set("Error: " + ex + " >> " + stringWriter);
172176
}
173177
}
174178

0 commit comments

Comments
 (0)