More API v2 changes :)

This commit is contained in:
Lukas Rieger (Blue) 2022-07-24 00:45:49 +02:00
parent 6e9415ee33
commit 06359955b5
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
20 changed files with 569 additions and 7 deletions

View File

@ -21,7 +21,8 @@ repositories {
dependencies { dependencies {
api ("com.flowpowered:flow-math:1.0.3") 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") compileOnly ("org.jetbrains:annotations:23.0.0")
} }

View File

@ -24,6 +24,8 @@
*/ */
package de.bluecolored.bluemap.api; package de.bluecolored.bluemap.api;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
@ -72,24 +74,28 @@ public abstract class BlueMapAPI {
* Getter for the {@link RenderManager}. * Getter for the {@link RenderManager}.
* @return the {@link RenderManager} * @return the {@link RenderManager}
*/ */
@DebugDump
public abstract RenderManager getRenderManager(); public abstract RenderManager getRenderManager();
/** /**
* Getter for the {@link WebApp}. * Getter for the {@link WebApp}.
* @return the {@link WebApp} * @return the {@link WebApp}
*/ */
@DebugDump
public abstract WebApp getWebApp(); public abstract WebApp getWebApp();
/** /**
* Getter for all {@link BlueMapMap}s loaded by BlueMap. * Getter for all {@link BlueMapMap}s loaded by BlueMap.
* @return an unmodifiable collection of all loaded {@link BlueMapMap}s * @return an unmodifiable collection of all loaded {@link BlueMapMap}s
*/ */
@DebugDump
public abstract Collection<BlueMapMap> getMaps(); public abstract Collection<BlueMapMap> getMaps();
/** /**
* Getter for all {@link BlueMapWorld}s loaded by BlueMap. * Getter for all {@link BlueMapWorld}s loaded by BlueMap.
* @return an unmodifiable collection of all loaded {@link BlueMapWorld}s * @return an unmodifiable collection of all loaded {@link BlueMapWorld}s
*/ */
@DebugDump
public abstract Collection<BlueMapWorld> getWorlds(); public abstract Collection<BlueMapWorld> getWorlds();
/** /**
@ -122,12 +128,14 @@ public abstract class BlueMapAPI {
* Getter for the installed BlueMap version * Getter for the installed BlueMap version
* @return the version-string * @return the version-string
*/ */
@DebugDump
public abstract String getBlueMapVersion(); public abstract String getBlueMapVersion();
/** /**
* Getter for the installed BlueMapAPI version * Getter for the installed BlueMapAPI version
* @return the version-string * @return the version-string
*/ */
@DebugDump
public String getAPIVersion() { public String getAPIVersion() {
return VERSION; return VERSION;
} }

View File

@ -27,6 +27,7 @@
import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i; import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.marker.MarkerSet; import de.bluecolored.bluemap.api.marker.MarkerSet;
import java.util.Map; 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. * Returns this maps id, this is equal to the id configured in bluemap's config for this map.
* @return the id of this map * @return the id of this map
*/ */
@DebugDump
String getId(); String getId();
/** /**
* Returns this maps display-name, this is equal to the name configured in bluemap's config for this map. * 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 * @return the name of this map
*/ */
@DebugDump
String getName(); String getName();
/** /**
* Getter for the {@link BlueMapWorld} of this map. * Getter for the {@link BlueMapWorld} of this map.
* @return the {@link BlueMapWorld} of this map * @return the {@link BlueMapWorld} of this map
*/ */
@DebugDump
BlueMapWorld getWorld(); 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. * 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. * @return a {@link Map} of {@link MarkerSet}s.
*/ */
@DebugDump
Map<String, MarkerSet> getMarkerSets(); Map<String, MarkerSet> getMarkerSets();
/** /**
* Getter for the size of all tiles on this map in blocks. * Getter for the size of all tiles on this map in blocks.
* @return the tile-size in blocks * @return the tile-size in blocks
*/ */
@DebugDump
Vector2i getTileSize(); 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. * 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 * @return the tile-offset in blocks
*/ */
@DebugDump
Vector2i getTileOffset(); Vector2i getTileOffset();
/** /**

View File

@ -24,6 +24,8 @@
*/ */
package de.bluecolored.bluemap.api; package de.bluecolored.bluemap.api;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
@ -36,18 +38,21 @@ public interface BlueMapWorld {
* Getter for the id of this world. * Getter for the id of this world.
* @return the id of this world * @return the id of this world
*/ */
@DebugDump
String getId(); 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 ( <code>world:</code> ). * Getter for the {@link Path} of this world's save-files (folder). This matches the folder configured in bluemap's config for this map ( <code>world:</code> ).
* @return the save-folder of this world. * @return the save-folder of this world.
*/ */
@DebugDump
Path getSaveFolder(); Path getSaveFolder();
/** /**
* Getter for all {@link BlueMapMap}s for this world * Getter for all {@link BlueMapMap}s for this world
* @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world * @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world
*/ */
@DebugDump
Collection<BlueMapMap> getMaps(); Collection<BlueMapMap> getMaps();
} }

View File

@ -25,6 +25,7 @@
package de.bluecolored.bluemap.api; package de.bluecolored.bluemap.api;
import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector2i;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
@ -74,18 +75,21 @@ default boolean scheduleMapUpdateTask(BlueMapMap map) {
* Getter for the current size of the render-queue. * Getter for the current size of the render-queue.
* @return the current size of the render-queue * @return the current size of the render-queue
*/ */
@DebugDump
int renderQueueSize(); int renderQueueSize();
/** /**
* Getter for the current count of render threads. * Getter for the current count of render threads.
* @return the count of render threads * @return the count of render threads
*/ */
@DebugDump
int renderThreadCount(); int renderThreadCount();
/** /**
* Whether this {@link RenderManager} is currently running or stopped. * Whether this {@link RenderManager} is currently running or stopped.
* @return <code>true</code> if this renderer is running * @return <code>true</code> if this renderer is running
*/ */
@DebugDump
boolean isRunning(); boolean isRunning();
/** /**

View File

@ -1,5 +1,30 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* 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; 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.Marker;
import de.bluecolored.bluemap.api.marker.POIMarker; import de.bluecolored.bluemap.api.marker.POIMarker;
import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector2i;
@ -16,6 +41,7 @@ public interface WebApp {
* Getter for the configured web-root folder * Getter for the configured web-root folder
* @return The {@link Path} of the web-root folder * @return The {@link Path} of the web-root folder
*/ */
@DebugDump
Path getWebRoot(); Path getWebRoot();
/** /**
@ -50,6 +76,7 @@ public interface WebApp {
* </ul> * </ul>
* @throws IOException If an {@link IOException} is thrown while reading the images * @throws IOException If an {@link IOException} is thrown while reading the images
*/ */
@DebugDump
Map<String, String> availableImages() throws IOException; Map<String, String> availableImages() throws IOException;
} }

View File

@ -0,0 +1,46 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* 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 <code>/bluemap debug dump</code>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.METHOD,
ElementType.FIELD,
ElementType.TYPE
})
public @interface DebugDump {
String value() default "";
}

View File

@ -25,7 +25,9 @@
package de.bluecolored.bluemap.api.marker; package de.bluecolored.bluemap.api.marker;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
@DebugDump
public abstract class DistanceRangedMarker extends Marker { public abstract class DistanceRangedMarker extends Marker {
private double minDistance, maxDistance; private double minDistance, maxDistance;

View File

@ -26,11 +26,15 @@
import com.flowpowered.math.vector.Vector2d; import com.flowpowered.math.vector.Vector2d;
import com.flowpowered.math.vector.Vector3d; 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.Color;
import de.bluecolored.bluemap.api.math.Shape;
import java.util.Objects; import java.util.Objects;
@DebugDump
public class ExtrudeMarker extends ObjectMarker { public class ExtrudeMarker extends ObjectMarker {
private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1);
private Shape shape; private Shape shape;
private float shapeMinY, shapeMaxY; private float shapeMinY, shapeMaxY;
@ -39,6 +43,14 @@ public class ExtrudeMarker extends ObjectMarker {
private Color lineColor = new Color(255, 0, 0, 1f); private Color lineColor = new Color(255, 0, 0, 1f);
private Color fillColor = new Color(200, 0, 0, 0.3f); 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}. * Creates a new {@link ExtrudeMarker}.
* <p><i>(The position of the marker will be the center of the shape (it's bounding box))</i></p> * <p><i>(The position of the marker will be the center of the shape (it's bounding box))</i></p>

View File

@ -27,17 +27,27 @@
import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Objects; import java.util.Objects;
/** /**
* A marker that is a html-element placed somewhere on the map. * A marker that is a html-element placed somewhere on the map.
*/ */
@DebugDump
public class HtmlMarker extends DistanceRangedMarker { public class HtmlMarker extends DistanceRangedMarker {
private Vector2i anchor; private Vector2i anchor;
private String html; private String html;
/**
* Empty constructor for deserialization.
*/
@SuppressWarnings("unused")
private HtmlMarker() {
this("", Vector3d.ZERO, "");
}
/** /**
* Creates a new {@link HtmlMarker}. * Creates a new {@link HtmlMarker}.
* *

View File

@ -25,17 +25,29 @@
package de.bluecolored.bluemap.api.marker; package de.bluecolored.bluemap.api.marker;
import com.flowpowered.math.vector.Vector3d; 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.Color;
import de.bluecolored.bluemap.api.math.Line;
import java.util.Objects; import java.util.Objects;
@DebugDump
public class LineMarker extends ObjectMarker { public class LineMarker extends ObjectMarker {
private static final Line DEFAULT_LINE = new Line(Vector3d.ZERO, Vector3d.ONE);
private Line line; private Line line;
private boolean depthTest = true; private boolean depthTest = true;
private int lineWidth = 2; private int lineWidth = 2;
private Color lineColor = new Color(255, 0, 0, 1f); 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}. * Creates a new {@link LineMarker}.
* <p><i>(The position of the marker will be the center of the line (it's bounding box))</i></p> * <p><i>(The position of the marker will be the center of the line (it's bounding box))</i></p>

View File

@ -25,6 +25,7 @@
package de.bluecolored.bluemap.api.marker; package de.bluecolored.bluemap.api.marker;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Objects; import java.util.Objects;
@ -37,6 +38,7 @@
* @see ExtrudeMarker * @see ExtrudeMarker
* @see LineMarker * @see LineMarker
*/ */
@DebugDump
public abstract class Marker { public abstract class Marker {
private final String type; private final String type;

View File

@ -0,0 +1,360 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* 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<Marker> {
private static final Map<String, Class<? extends Marker>> 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<? extends Marker> 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<Line> {
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<Vector3d> 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<Shape> {
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<Vector2d> 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<Color> {
@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<Vector2d> {
@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<Vector3d> {
@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<Vector2i> {
@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<Vector3i> {
@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);
}
}
}

View File

@ -24,18 +24,29 @@
*/ */
package de.bluecolored.bluemap.api.marker; package de.bluecolored.bluemap.api.marker;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* A set of {@link Marker}s that are displayed on the maps in the web-app. * A set of {@link Marker}s that are displayed on the maps in the web-app.
*/ */
@DebugDump
public class MarkerSet { public class MarkerSet {
private String label; private String label;
private boolean toggleable, defaultHidden; private boolean toggleable, defaultHidden;
private final Map<String, Marker> markers; private final Map<String, Marker> markers;
/**
* Empty constructor for deserialization.
*/
@SuppressWarnings("unused")
private MarkerSet() {
this("");
}
/** /**
* Creates a new {@link MarkerSet}. * Creates a new {@link MarkerSet}.
* *

View File

@ -25,11 +25,13 @@
package de.bluecolored.bluemap.api.marker; package de.bluecolored.bluemap.api.marker;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
@DebugDump
public abstract class ObjectMarker extends DistanceRangedMarker { public abstract class ObjectMarker extends DistanceRangedMarker {
private String detail; private String detail;
@ -41,8 +43,6 @@ public abstract class ObjectMarker extends DistanceRangedMarker {
public ObjectMarker(String type, String label, Vector3d position) { public ObjectMarker(String type, String label, Vector3d position) {
super(type, label, position); super(type, label, position);
this.detail = Objects.requireNonNull(label, "label must not be null"); this.detail = Objects.requireNonNull(label, "label must not be null");
this.link = null;
this.newTab = false;
} }
/** /**

View File

@ -27,14 +27,24 @@
import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.WebApp; import de.bluecolored.bluemap.api.WebApp;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Objects; import java.util.Objects;
@DebugDump
public class POIMarker extends DistanceRangedMarker { public class POIMarker extends DistanceRangedMarker {
private String icon; private String icon;
private Vector2i anchor; private Vector2i anchor;
/**
* Empty constructor for deserialization.
*/
@SuppressWarnings("unused")
private POIMarker() {
this("", Vector3d.ZERO);
}
/** /**
* Creates a new {@link POIMarker} with the standard icon. * Creates a new {@link POIMarker} with the standard icon.
* *

View File

@ -27,11 +27,15 @@
import com.flowpowered.math.vector.Vector2d; import com.flowpowered.math.vector.Vector2d;
import com.flowpowered.math.vector.Vector3d; 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.Color;
import de.bluecolored.bluemap.api.math.Shape;
import java.util.Objects; import java.util.Objects;
@DebugDump
public class ShapeMarker extends ObjectMarker { public class ShapeMarker extends ObjectMarker {
private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1);
private Shape shape; private Shape shape;
private float shapeY; private float shapeY;
@ -40,6 +44,14 @@ public class ShapeMarker extends ObjectMarker {
private Color lineColor = new Color(255, 0, 0, 1f); private Color lineColor = new Color(255, 0, 0, 1f);
private Color fillColor = new Color(200, 0, 0, 0.3f); 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}. * Creates a new {@link ShapeMarker}.
* <p><i>(The position of the marker will be the center of the shape (it's bounding box))</i></p> * <p><i>(The position of the marker will be the center of the shape (it's bounding box))</i></p>

View File

@ -1,7 +1,34 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* 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; package de.bluecolored.bluemap.api.math;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Objects; import java.util.Objects;
@DebugDump
public class Color { public class Color {
private final int r, g, b; private final int r, g, b;

View File

@ -22,9 +22,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package de.bluecolored.bluemap.api.marker; package de.bluecolored.bluemap.api.math;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Arrays; import java.util.Arrays;
@ -32,6 +33,7 @@
/** /**
* A line consisting of 2 or more {@link Vector3d}-points. * A line consisting of 2 or more {@link Vector3d}-points.
*/ */
@DebugDump
public class Line { public class Line {
private final Vector3d[] points; private final Vector3d[] points;

View File

@ -22,20 +22,24 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package de.bluecolored.bluemap.api.marker; package de.bluecolored.bluemap.api.math;
import com.flowpowered.math.vector.Vector2d; import com.flowpowered.math.vector.Vector2d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays; import java.util.Arrays;
/** /**
* A shape consisting of 3 or more {@link Vector2d}-points on a plane. * A shape consisting of 3 or more {@link Vector2d}-points on a plane.
*/ */
@DebugDump
public class Shape { public class Shape {
private final Vector2d[] points; private final Vector2d[] points;
private Vector2d min = null;
private Vector2d max = null; @Nullable
private Vector2d min = null, max = null;
public Shape(Vector2d... points) { public Shape(Vector2d... points) {
if (points.length < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!"); if (points.length < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!");