diff --git a/build.gradle.kts b/build.gradle.kts index d1d9606..71e6eec 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,8 @@ repositories { dependencies { api ("com.flowpowered:flow-math:1.0.3") - implementation ("com.google.code.gson:gson:2.8.0") + api ("com.google.code.gson:gson:2.8.0") + compileOnly ("org.jetbrains:annotations:23.0.0") } diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java index bb60312..869704d 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java @@ -24,6 +24,8 @@ */ package de.bluecolored.bluemap.api; +import de.bluecolored.bluemap.api.debug.DebugDump; + import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -72,24 +74,28 @@ public abstract class BlueMapAPI { * Getter for the {@link RenderManager}. * @return the {@link RenderManager} */ + @DebugDump public abstract RenderManager getRenderManager(); /** * Getter for the {@link WebApp}. * @return the {@link WebApp} */ + @DebugDump public abstract WebApp getWebApp(); /** * Getter for all {@link BlueMapMap}s loaded by BlueMap. * @return an unmodifiable collection of all loaded {@link BlueMapMap}s */ + @DebugDump public abstract Collection getMaps(); /** * Getter for all {@link BlueMapWorld}s loaded by BlueMap. * @return an unmodifiable collection of all loaded {@link BlueMapWorld}s */ + @DebugDump public abstract Collection getWorlds(); /** @@ -122,12 +128,14 @@ public abstract class BlueMapAPI { * Getter for the installed BlueMap version * @return the version-string */ + @DebugDump public abstract String getBlueMapVersion(); /** * Getter for the installed BlueMapAPI version * @return the version-string */ + @DebugDump public String getAPIVersion() { return VERSION; } diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java index 9f9337d..d9b0ae5 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java @@ -27,6 +27,7 @@ import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3i; +import de.bluecolored.bluemap.api.debug.DebugDump; import de.bluecolored.bluemap.api.marker.MarkerSet; import java.util.Map; @@ -42,18 +43,21 @@ public interface BlueMapMap { * Returns this maps id, this is equal to the id configured in bluemap's config for this map. * @return the id of this map */ + @DebugDump String getId(); /** * Returns this maps display-name, this is equal to the name configured in bluemap's config for this map. * @return the name of this map */ + @DebugDump String getName(); /** * Getter for the {@link BlueMapWorld} of this map. * @return the {@link BlueMapWorld} of this map */ + @DebugDump BlueMapWorld getWorld(); /** @@ -61,12 +65,14 @@ public interface BlueMapMap { * Changing this map will change the {@link MarkerSet}s and markers displayed on the web-app for this map. * @return a {@link Map} of {@link MarkerSet}s. */ + @DebugDump Map getMarkerSets(); /** * Getter for the size of all tiles on this map in blocks. * @return the tile-size in blocks */ + @DebugDump Vector2i getTileSize(); /** @@ -74,6 +80,7 @@ public interface BlueMapMap { * E.g. an offset of (2|-1) would mean that the tile (0|0) has block (2|0|-1) at it's min-corner. * @return the tile-offset in blocks */ + @DebugDump Vector2i getTileOffset(); /** diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java index a0b002d..5385ef5 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java @@ -24,6 +24,8 @@ */ package de.bluecolored.bluemap.api; +import de.bluecolored.bluemap.api.debug.DebugDump; + import java.nio.file.Path; import java.util.Collection; @@ -36,18 +38,21 @@ public interface BlueMapWorld { * Getter for the id of this world. * @return the id of this world */ + @DebugDump String getId(); /** * Getter for the {@link Path} of this world's save-files (folder). This matches the folder configured in bluemap's config for this map ( world: ). * @return the save-folder of this world. */ + @DebugDump Path getSaveFolder(); /** * Getter for all {@link BlueMapMap}s for this world * @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world */ + @DebugDump Collection getMaps(); } diff --git a/src/main/java/de/bluecolored/bluemap/api/RenderManager.java b/src/main/java/de/bluecolored/bluemap/api/RenderManager.java index fb8f6e1..8b1769c 100644 --- a/src/main/java/de/bluecolored/bluemap/api/RenderManager.java +++ b/src/main/java/de/bluecolored/bluemap/api/RenderManager.java @@ -25,6 +25,7 @@ package de.bluecolored.bluemap.api; import com.flowpowered.math.vector.Vector2i; +import de.bluecolored.bluemap.api.debug.DebugDump; import java.io.IOException; import java.util.Collection; @@ -74,18 +75,21 @@ default boolean scheduleMapUpdateTask(BlueMapMap map) { * Getter for the current size of the render-queue. * @return the current size of the render-queue */ + @DebugDump int renderQueueSize(); /** * Getter for the current count of render threads. * @return the count of render threads */ + @DebugDump int renderThreadCount(); /** * Whether this {@link RenderManager} is currently running or stopped. * @return true if this renderer is running */ + @DebugDump boolean isRunning(); /** diff --git a/src/main/java/de/bluecolored/bluemap/api/WebApp.java b/src/main/java/de/bluecolored/bluemap/api/WebApp.java index 2e86f20..4cf0f39 100644 --- a/src/main/java/de/bluecolored/bluemap/api/WebApp.java +++ b/src/main/java/de/bluecolored/bluemap/api/WebApp.java @@ -1,5 +1,30 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package de.bluecolored.bluemap.api; +import de.bluecolored.bluemap.api.debug.DebugDump; import de.bluecolored.bluemap.api.marker.Marker; import de.bluecolored.bluemap.api.marker.POIMarker; import com.flowpowered.math.vector.Vector2i; @@ -16,6 +41,7 @@ public interface WebApp { * Getter for the configured web-root folder * @return The {@link Path} of the web-root folder */ + @DebugDump Path getWebRoot(); /** @@ -50,6 +76,7 @@ public interface WebApp { * * @throws IOException If an {@link IOException} is thrown while reading the images */ + @DebugDump Map availableImages() throws IOException; } diff --git a/src/main/java/de/bluecolored/bluemap/api/debug/DebugDump.java b/src/main/java/de/bluecolored/bluemap/api/debug/DebugDump.java new file mode 100644 index 0000000..28163b5 --- /dev/null +++ b/src/main/java/de/bluecolored/bluemap/api/debug/DebugDump.java @@ -0,0 +1,46 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package de.bluecolored.bluemap.api.debug; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a class, field or method to be included in detail in a possible state-dump. + * E.g. triggered by /bluemap debug dump + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ + ElementType.METHOD, + ElementType.FIELD, + ElementType.TYPE +}) +public @interface DebugDump { + + String value() default ""; + +} diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/DistanceRangedMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/DistanceRangedMarker.java index 0a7e145..9abf0f6 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/DistanceRangedMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/DistanceRangedMarker.java @@ -25,7 +25,9 @@ package de.bluecolored.bluemap.api.marker; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; +@DebugDump public abstract class DistanceRangedMarker extends Marker { private double minDistance, maxDistance; diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/ExtrudeMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/ExtrudeMarker.java index 793bc90..a3123f0 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/ExtrudeMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/ExtrudeMarker.java @@ -26,11 +26,15 @@ import com.flowpowered.math.vector.Vector2d; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; import de.bluecolored.bluemap.api.math.Color; +import de.bluecolored.bluemap.api.math.Shape; import java.util.Objects; +@DebugDump public class ExtrudeMarker extends ObjectMarker { + private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1); private Shape shape; private float shapeMinY, shapeMaxY; @@ -39,6 +43,14 @@ public class ExtrudeMarker extends ObjectMarker { private Color lineColor = new Color(255, 0, 0, 1f); private Color fillColor = new Color(200, 0, 0, 0.3f); + /** + * Empty constructor for deserialization. + */ + @SuppressWarnings("unused") + private ExtrudeMarker() { + this("", DEFAULT_SHAPE, 0, 0); + } + /** * Creates a new {@link ExtrudeMarker}. *

(The position of the marker will be the center of the shape (it's bounding box))

diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/HtmlMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/HtmlMarker.java index 1248b45..75e42df 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/HtmlMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/HtmlMarker.java @@ -27,17 +27,27 @@ import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; import java.util.Objects; /** * A marker that is a html-element placed somewhere on the map. */ +@DebugDump public class HtmlMarker extends DistanceRangedMarker { private Vector2i anchor; private String html; + /** + * Empty constructor for deserialization. + */ + @SuppressWarnings("unused") + private HtmlMarker() { + this("", Vector3d.ZERO, ""); + } + /** * Creates a new {@link HtmlMarker}. * diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/LineMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/LineMarker.java index 33f2437..67c4d33 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/LineMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/LineMarker.java @@ -25,17 +25,29 @@ package de.bluecolored.bluemap.api.marker; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; import de.bluecolored.bluemap.api.math.Color; +import de.bluecolored.bluemap.api.math.Line; import java.util.Objects; +@DebugDump public class LineMarker extends ObjectMarker { + private static final Line DEFAULT_LINE = new Line(Vector3d.ZERO, Vector3d.ONE); private Line line; private boolean depthTest = true; private int lineWidth = 2; private Color lineColor = new Color(255, 0, 0, 1f); + /** + * Empty constructor for deserialization. + */ + @SuppressWarnings("unused") + private LineMarker() { + this("", DEFAULT_LINE); + } + /** * Creates a new {@link LineMarker}. *

(The position of the marker will be the center of the line (it's bounding box))

diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/Marker.java b/src/main/java/de/bluecolored/bluemap/api/marker/Marker.java index 6205f1f..0d090ab 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/Marker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/Marker.java @@ -25,6 +25,7 @@ package de.bluecolored.bluemap.api.marker; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; import java.util.Objects; @@ -37,6 +38,7 @@ * @see ExtrudeMarker * @see LineMarker */ +@DebugDump public abstract class Marker { private final String type; diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/MarkerGson.java b/src/main/java/de/bluecolored/bluemap/api/marker/MarkerGson.java new file mode 100644 index 0000000..ccde185 --- /dev/null +++ b/src/main/java/de/bluecolored/bluemap/api/marker/MarkerGson.java @@ -0,0 +1,360 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package de.bluecolored.bluemap.api.marker; + +import com.flowpowered.math.vector.Vector2d; +import com.flowpowered.math.vector.Vector2i; +import com.flowpowered.math.vector.Vector3d; +import com.flowpowered.math.vector.Vector3i; +import com.google.gson.*; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import de.bluecolored.bluemap.api.math.Color; +import de.bluecolored.bluemap.api.math.Line; +import de.bluecolored.bluemap.api.math.Shape; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public final class MarkerGson { + + public static final Gson INSTANCE = new GsonBuilder() + .registerTypeAdapter(Marker.class, new MarkerDeserializer()) + .registerTypeAdapter(Line.class, new LineAdapter()) + .registerTypeAdapter(Shape.class, new ShapeAdapter()) + .registerTypeAdapter(Color.class, new ColorAdapter()) + .registerTypeAdapter(Vector2d.class, new Vector2dAdapter()) + .registerTypeAdapter(Vector3d.class, new Vector3dAdapter()) + .registerTypeAdapter(Vector2i.class, new Vector2iAdapter()) + .registerTypeAdapter(Vector3i.class, new Vector3iAdapter()) + .setLenient() + .disableHtmlEscaping() + .create(); + + /* This class can not be instantiated. */ + private MarkerGson() {} + + static class MarkerDeserializer implements JsonDeserializer { + + private static final Map> MARKER_TYPES = Map.of( + "html", HtmlMarker.class, + "poi", POIMarker.class, + "shape", ShapeMarker.class, + "extrude", ExtrudeMarker.class, + "line", LineMarker.class + ); + + @Override + public Marker deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + String markerType = jsonElement.getAsJsonObject().get("type").getAsString(); + Class markerClass = MARKER_TYPES.get(markerType); + if (markerClass == null) throw new JsonParseException("Unknown marker type: " + markerType); + return jsonDeserializationContext.deserialize(jsonElement, markerClass); + } + + } + + static class LineAdapter extends TypeAdapter { + private static final Vector3dAdapter VEC3D_ADAPTER = new Vector3dAdapter(); + + @Override + public void write(JsonWriter out, Line value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginArray(); + for (Vector3d point : value.getPoints()) { + VEC3D_ADAPTER.write(out, point); + } + out.endArray(); + } + + @Override + public Line read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } + + List points = new LinkedList<>(); + + in.beginArray(); + while (in.peek() != JsonToken.END_ARRAY) { + Vector3d point = VEC3D_ADAPTER.read(in); + if (point == null) continue; + points.add(point); + } + in.endArray(); + + return new Line(points.toArray(Vector3d[]::new)); + } + + } + + static class ShapeAdapter extends TypeAdapter { + private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter(); + + @Override + public void write(JsonWriter out, Shape value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginArray(); + for (Vector2d point : value.getPoints()) { + VEC2D_ADAPTER.write(out, point); + } + out.endArray(); + } + + @Override + public Shape read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } + + List points = new LinkedList<>(); + + in.beginArray(); + while (in.peek() != JsonToken.END_ARRAY) { + Vector2d point = VEC2D_ADAPTER.read(in); + if (point == null) continue; + points.add(point); + } + in.endArray(); + + return new Shape(points.toArray(Vector2d[]::new)); + } + + } + + static class ColorAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Color value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginObject(); + out.name("r"); out.value(value.getRed()); + out.name("g"); out.value(value.getGreen()); + out.name("b"); out.value(value.getBlue()); + out.name("a"); out.value(value.getAlpha()); + out.endObject(); + } + + @Override + public Color read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } + + in.beginObject(); + int r = 0, g = 0, b = 0; + float a = 1; + while (in.peek() != JsonToken.END_OBJECT) { + switch (in.nextName()) { + case "r" : r = in.nextInt(); break; + case "g" : g = in.nextInt(); break; + case "b" : b = in.nextInt(); break; + case "a" : a = (float) in.nextDouble(); break; + default : in.skipValue(); break; + } + } + in.endObject(); + + return new Color(r, g, b, a); + } + + } + + static class Vector2dAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Vector2d value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginObject(); + out.name("x"); out.value(value.getX()); + out.name("y"); out.value(value.getY()); + out.endObject(); + } + + @Override + public Vector2d read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } + + in.beginObject(); + double x = 0, y = 0; + while (in.peek() != JsonToken.END_OBJECT) { + switch (in.nextName()) { + case "x" : x = in.nextDouble(); break; + case "y" : y = in.nextDouble(); break; + default : in.skipValue(); break; + } + } + in.endObject(); + + return new Vector2d(x, y); + } + + } + + static class Vector3dAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Vector3d value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginObject(); + out.name("x"); out.value(value.getX()); + out.name("y"); out.value(value.getY()); + out.name("z"); out.value(value.getZ()); + out.endObject(); + } + + @Override + public Vector3d read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } + + in.beginObject(); + double x = 0, y = 0, z = 0; + while (in.peek() != JsonToken.END_OBJECT) { + switch (in.nextName()) { + case "x" : x = in.nextDouble(); break; + case "y" : y = in.nextDouble(); break; + case "z" : z = in.nextDouble(); break; + default : in.skipValue(); break; + } + } + in.endObject(); + + return new Vector3d(x, y, z); + } + + } + + static class Vector2iAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Vector2i value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginObject(); + out.name("x"); out.value(value.getX()); + out.name("y"); out.value(value.getY()); + out.endObject(); + } + + @Override + public Vector2i read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } + + in.beginObject(); + int x = 0, y = 0; + while (in.peek() != JsonToken.END_OBJECT) { + switch (in.nextName()) { + case "x" : x = in.nextInt(); break; + case "y" : y = in.nextInt(); break; + default : in.skipValue(); break; + } + } + in.endObject(); + + return new Vector2i(x, y); + } + + } + + static class Vector3iAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Vector3i value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginObject(); + out.name("x"); out.value(value.getX()); + out.name("y"); out.value(value.getY()); + out.name("z"); out.value(value.getZ()); + out.endObject(); + } + + @Override + public Vector3i read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } + + in.beginObject(); + int x = 0, y = 0, z = 0; + while (in.peek() != JsonToken.END_OBJECT) { + switch (in.nextName()) { + case "x" : x = in.nextInt(); break; + case "y" : y = in.nextInt(); break; + case "z" : z = in.nextInt(); break; + default : in.skipValue(); break; + } + } + in.endObject(); + + return new Vector3i(x, y, z); + } + + } + +} diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/MarkerSet.java b/src/main/java/de/bluecolored/bluemap/api/marker/MarkerSet.java index c174020..c3642a4 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/MarkerSet.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/MarkerSet.java @@ -24,18 +24,29 @@ */ package de.bluecolored.bluemap.api.marker; +import de.bluecolored.bluemap.api.debug.DebugDump; + import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * A set of {@link Marker}s that are displayed on the maps in the web-app. */ +@DebugDump public class MarkerSet { private String label; private boolean toggleable, defaultHidden; private final Map markers; + /** + * Empty constructor for deserialization. + */ + @SuppressWarnings("unused") + private MarkerSet() { + this(""); + } + /** * Creates a new {@link MarkerSet}. * diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/ObjectMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/ObjectMarker.java index cea4857..cdacb11 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/ObjectMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/ObjectMarker.java @@ -25,11 +25,13 @@ package de.bluecolored.bluemap.api.marker; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; +@DebugDump public abstract class ObjectMarker extends DistanceRangedMarker { private String detail; @@ -41,8 +43,6 @@ public abstract class ObjectMarker extends DistanceRangedMarker { public ObjectMarker(String type, String label, Vector3d position) { super(type, label, position); this.detail = Objects.requireNonNull(label, "label must not be null"); - this.link = null; - this.newTab = false; } /** diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/POIMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/POIMarker.java index 94fe97e..1738a5d 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/POIMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/POIMarker.java @@ -27,14 +27,24 @@ import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3d; import de.bluecolored.bluemap.api.WebApp; +import de.bluecolored.bluemap.api.debug.DebugDump; import java.util.Objects; +@DebugDump public class POIMarker extends DistanceRangedMarker { private String icon; private Vector2i anchor; + /** + * Empty constructor for deserialization. + */ + @SuppressWarnings("unused") + private POIMarker() { + this("", Vector3d.ZERO); + } + /** * Creates a new {@link POIMarker} with the standard icon. * diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/ShapeMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/ShapeMarker.java index eed2d9a..cc86c18 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/ShapeMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/ShapeMarker.java @@ -27,11 +27,15 @@ import com.flowpowered.math.vector.Vector2d; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; import de.bluecolored.bluemap.api.math.Color; +import de.bluecolored.bluemap.api.math.Shape; import java.util.Objects; +@DebugDump public class ShapeMarker extends ObjectMarker { + private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1); private Shape shape; private float shapeY; @@ -40,6 +44,14 @@ public class ShapeMarker extends ObjectMarker { private Color lineColor = new Color(255, 0, 0, 1f); private Color fillColor = new Color(200, 0, 0, 0.3f); + /** + * Empty constructor for deserialization. + */ + @SuppressWarnings("unused") + private ShapeMarker() { + this("shape", DEFAULT_SHAPE, 0); + } + /** * Creates a new {@link ShapeMarker}. *

(The position of the marker will be the center of the shape (it's bounding box))

diff --git a/src/main/java/de/bluecolored/bluemap/api/math/Color.java b/src/main/java/de/bluecolored/bluemap/api/math/Color.java index 60883b9..c8d4bc5 100644 --- a/src/main/java/de/bluecolored/bluemap/api/math/Color.java +++ b/src/main/java/de/bluecolored/bluemap/api/math/Color.java @@ -1,7 +1,34 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package de.bluecolored.bluemap.api.math; +import de.bluecolored.bluemap.api.debug.DebugDump; + import java.util.Objects; +@DebugDump public class Color { private final int r, g, b; diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/Line.java b/src/main/java/de/bluecolored/bluemap/api/math/Line.java similarity index 96% rename from src/main/java/de/bluecolored/bluemap/api/marker/Line.java rename to src/main/java/de/bluecolored/bluemap/api/math/Line.java index 5c65daa..f5bea52 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/Line.java +++ b/src/main/java/de/bluecolored/bluemap/api/math/Line.java @@ -22,9 +22,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.api.marker; +package de.bluecolored.bluemap.api.math; import com.flowpowered.math.vector.Vector3d; +import de.bluecolored.bluemap.api.debug.DebugDump; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -32,6 +33,7 @@ /** * A line consisting of 2 or more {@link Vector3d}-points. */ +@DebugDump public class Line { private final Vector3d[] points; diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/Shape.java b/src/main/java/de/bluecolored/bluemap/api/math/Shape.java similarity index 97% rename from src/main/java/de/bluecolored/bluemap/api/marker/Shape.java rename to src/main/java/de/bluecolored/bluemap/api/math/Shape.java index 3173ea0..613edd6 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/Shape.java +++ b/src/main/java/de/bluecolored/bluemap/api/math/Shape.java @@ -22,20 +22,24 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.api.marker; +package de.bluecolored.bluemap.api.math; import com.flowpowered.math.vector.Vector2d; +import de.bluecolored.bluemap.api.debug.DebugDump; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; /** * A shape consisting of 3 or more {@link Vector2d}-points on a plane. */ +@DebugDump public class Shape { private final Vector2d[] points; - private Vector2d min = null; - private Vector2d max = null; + + @Nullable + private Vector2d min = null, max = null; public Shape(Vector2d... points) { if (points.length < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!");