From d4f00682a60e26336af6db7ba27dc1ca74dee0ee Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Tue, 2 Aug 2022 18:14:38 +0200 Subject: [PATCH] Fix web-app api throwing an error and add full errors to the StateDumper --- .../bluemap/common/api/WebAppImpl.java | 42 ++++++++++--------- .../bluemap/core/debug/StateDumper.java | 6 ++- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/WebAppImpl.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/WebAppImpl.java index 3ee68451..d15b0bce 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/WebAppImpl.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/WebAppImpl.java @@ -14,7 +14,7 @@ import java.util.stream.Stream; public class WebAppImpl implements WebApp { - private static final String IMAGE_ROOT_PATH = "images"; + private static final Path IMAGE_ROOT_PATH = Path.of("data", "images"); private final Plugin plugin; @@ -43,9 +43,10 @@ public String createImage(BufferedImage image, String path) throws IOException { Path webRoot = getWebRoot().toAbsolutePath(); String separator = webRoot.getFileSystem().getSeparator(); - Path webDataRoot = webRoot.resolve("data"); - Path imagePath = webDataRoot.resolve(Path.of(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath(); + Path imageRootFolder = webRoot.resolve(IMAGE_ROOT_PATH); + Path imagePath = imageRootFolder.resolve(Path.of(path.replace("/", separator) + ".png")).toAbsolutePath(); + Files.createDirectories(imagePath.getParent()); Files.deleteIfExists(imagePath); Files.createFile(imagePath); @@ -64,24 +65,27 @@ public Map availableImages() throws IOException { Map availableImagesMap = new HashMap<>(); - try (Stream fileStream = Files.walk(imageRootPath)){ - fileStream - .filter(p -> !Files.isDirectory(p)) - .filter(p -> p.getFileName().toString().endsWith(".png")) - .map(Path::toAbsolutePath) - .forEach(p -> { - try { - String key = imageRootPath.relativize(p).toString(); - key = key - .substring(0, key.length() - 4) //remove .png - .replace(separator, "/"); + if (Files.exists(imageRootPath)) { + try (Stream fileStream = Files.walk(imageRootPath)) { + fileStream + .filter(p -> !Files.isDirectory(p)) + .filter(p -> p.getFileName().toString().endsWith(".png")) + .map(Path::toAbsolutePath) + .forEach(p -> { + try { + String key = imageRootPath.relativize(p).toString(); + key = key + .substring(0, key.length() - 4) //remove .png + .replace(separator, "/"); - String value = webRoot.relativize(p).toString() - .replace(separator, "/"); + String value = webRoot.relativize(p).toString() + .replace(separator, "/"); - availableImagesMap.put(key, value); - } catch (IllegalArgumentException ignore) {} - }); + availableImagesMap.put(key, value); + } catch (IllegalArgumentException ignore) { + } + }); + } } return availableImagesMap; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java index dedc672e..7551a021 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java @@ -32,6 +32,8 @@ import org.spongepowered.configurate.serialize.SerializationException; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -168,7 +170,9 @@ private void dumpInstance(Object instance, ConfigurationOptions options, Configu } } catch (Exception ex) { - node.set("Error: " + ex); + StringWriter stringWriter = new StringWriter(); + ex.printStackTrace(new PrintWriter(stringWriter)); + node.set("Error: " + ex + " >> " + stringWriter); } }