diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java index 16e6fb4..2df8c85 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java @@ -38,251 +38,251 @@ /** * An API to control the running instance of BlueMap. - *

This API is thread-save, so you can use it async, off the main-server-thread, to save performance!

+ *

This API is thread-save, so you can use it async, off the main-server-thread, to save performance!

*/ public abstract class BlueMapAPI { - private static BlueMapAPI instance; + private static BlueMapAPI instance; - @Deprecated - private static final Collection listener = new HashSet<>(2); - - private static final Collection> onEnableConsumers = new HashSet<>(2); - private static final Collection> onDisableConsumers = new HashSet<>(2); + @Deprecated + private static final Collection listener = new HashSet<>(2); - /** - * Getter for the {@link RenderAPI}. - * @return the {@link RenderAPI} - */ - public abstract RenderAPI getRenderAPI(); - - /** - * Getter for the {@link MarkerAPI}.
- * Calling this gives you a fresh loaded {@link MarkerAPI}, so you don't have to call {@link MarkerAPI#load()} right away! - * @return the {@link MarkerAPI} - * @throws IOException if there was an IOException loading the marker.json - */ - public abstract MarkerAPI getMarkerAPI() throws IOException; - - /** - * Getter for all {@link BlueMapMap}s loaded by BlueMap. - * @return an unmodifiable collection of all loaded {@link BlueMapMap}s - */ - public abstract Collection getMaps(); - - /** - * Getter for all {@link BlueMapWorld}s loaded by BlueMap. - * @return an unmodifiable collection of all loaded {@link BlueMapWorld}s - */ - public abstract Collection getWorlds(); - - /** - * Getter for a {@link BlueMapWorld} loaded by BlueMap with the given {@link UUID}. - * - *

See the documentation of {@link BlueMapWorld#getUuid()} for more information about the nature of the worlds {@link UUID}s!

- * - * @see BlueMapWorld#getUuid() - * - * @param uuid the {@link UUID} of the world - * - * @return an {@link Optional} with the {@link BlueMapWorld} if it exists - */ - public abstract Optional getWorld(UUID uuid); - - /** - * Getter for a {@link BlueMapMap} loaded by BlueMap with the given id. - * @param id the map id (equivalent to the id configured in BlueMap's config - * @return an {@link Optional} with the {@link BlueMapMap} if it exists - */ - public abstract Optional getMap(String id); - - /** - * Creates an image-file with the given {@link BufferedImage} somewhere in the web-root, so it can be used in the web-app (e.g. for {@link Marker}-icons). - * - *

The given path is used as file-name and (separated with '/') optional folders to organize the image-files. Do NOT include the file-ending! (e.g. "someFolder/somePOIIcon" will result in a file "somePOIIcon.png" in a folder "someFolder").

- *

If the image file with the given path already exists, it will be replaced.

- * - * @param image the image to create - * @param path the path/name of this image, the separator-char is '/' - * @return the relative address of the image in the web-app, - * which can be used as it is e.g. in the {@link de.bluecolored.bluemap.api.marker.POIMarker#setIcon(String, Vector2i)} method - * @throws IOException If an {@link IOException} is thrown while writing the image - */ - public abstract String createImage(BufferedImage image, String path) throws IOException; + private static final Collection> onEnableConsumers = new HashSet<>(2); + private static final Collection> onDisableConsumers = new HashSet<>(2); - /** - * Lists all images that are available. This includes all images previously created with the {@link #createImage(BufferedImage, String)} - * function, but might include more. - * @return A map of available images where: - *
    - *
  • the key is the image path how it would be used in the "path" parameter of the {@link #createImage(BufferedImage, String)} method
  • - *
  • and the value is the relative address of the image. The same ones that are returned from the {@link #createImage(BufferedImage, String)} method
  • - *
- * @throws IOException If an {@link IOException} is thrown while reading the images - */ - public abstract Map availableImages() throws IOException; + /** + * Getter for the {@link RenderAPI}. + * @return the {@link RenderAPI} + */ + public abstract RenderAPI getRenderAPI(); - /** - * Getter for the configured web-root folder - * @return The {@link Path} of the web-root folder - */ - public abstract Path getWebRoot(); + /** + * Getter for the {@link MarkerAPI}.
+ * Calling this gives you a fresh loaded {@link MarkerAPI}, so you don't have to call {@link MarkerAPI#load()} right away! + * @return the {@link MarkerAPI} + * @throws IOException if there was an IOException loading the marker.json + */ + public abstract MarkerAPI getMarkerAPI() throws IOException; - /** - * Getter for the installed BlueMap version - * @return the version-string - */ - public abstract String getBlueMapVersion(); - - /** - * Register a listener that will be called when the API enables/disables - * @param listener the {@link BlueMapAPIListener} - * - * @deprecated Implementing {@link BlueMapAPIListener} can cause a ClassNotFoundException when you soft-depend on BlueMap and your plugin/mod gets used without BlueMap. - * Use {@link BlueMapAPI#onEnable(Consumer)} and {@link BlueMapAPI#onDisable(Consumer)} instead. - */ - @Deprecated - public static synchronized void registerListener(BlueMapAPIListener listener) { - BlueMapAPI.listener.add(listener); - if (BlueMapAPI.instance != null) listener.onEnable(BlueMapAPI.instance); - } - - /** - * Removes/Unregisters a previously registered listener - * @param listener the {@link BlueMapAPIListener} instance that has been registered previously - * - * @return true if a listener was removed as a result of this call - * - * @deprecated Implementing {@link BlueMapAPIListener} can cause a ClassNotFoundException when you soft-depend on BlueMap and your plugin/mod gets used without BlueMap. - * Use {@link BlueMapAPI#onEnable(Consumer)} and {@link BlueMapAPI#onDisable(Consumer)} instead. - */ - @Deprecated - public static synchronized boolean unregisterListener(BlueMapAPIListener listener) { - return BlueMapAPI.listener.remove(listener); - } - - /** - * Returns an instance of {@link BlueMapAPI} if it is currently enabled, else an empty {@link Optional} is returned. - * @return an {@link Optional}<{@link BlueMapAPI}> - */ - public static synchronized Optional getInstance() { - return Optional.ofNullable(instance); - } + /** + * Getter for all {@link BlueMapMap}s loaded by BlueMap. + * @return an unmodifiable collection of all loaded {@link BlueMapMap}s + */ + public abstract Collection getMaps(); - /** - * Registers a {@link Consumer} that will be called every time BlueMap has just been loaded and started and the API is ready to use.
- * If {@link BlueMapAPI} is already enabled when this listener is registered the consumer will be called immediately (once, on the same thread)! - *

The {@link Consumer} can be called multiple times if BlueMap disables and enables again, e.g. if BlueMap gets reloaded!

- *

(Note: The consumer will likely be called asynchronously, not on the server-thread!)

- *

Remember to unregister the consumer when you no longer need it using {@link #unregisterListener(Consumer)}.

- * @param consumer the {@link Consumer} - */ - public static synchronized void onEnable(Consumer consumer) { - onEnableConsumers.add(consumer); - if (BlueMapAPI.instance != null) consumer.accept(BlueMapAPI.instance); - } - - /** - * Registers a {@link Consumer} that will be called every time before BlueMap is being unloaded and stopped, after the consumer returns the API is no longer usable!
- * Unlike with {@link BlueMapAPI#onEnable(Consumer)}, if {@link BlueMapAPI} is not enabled when this listener is registered the consumer will not be called. - *

The {@link Consumer} can be called multiple times if BlueMap disables and enables again, e.g. if BlueMap gets reloaded!

- *

(Note: The consumer will likely be called asynchronously, not on the server-thread!)

- *

Remember to unregister the consumer when you no longer need it using {@link #unregisterListener(Consumer)}.

- * @param consumer the {@link Consumer} - */ - public static synchronized void onDisable(Consumer consumer) { - onDisableConsumers.add(consumer); - } + /** + * Getter for all {@link BlueMapWorld}s loaded by BlueMap. + * @return an unmodifiable collection of all loaded {@link BlueMapWorld}s + */ + public abstract Collection getWorlds(); - /** - * Removes a {@link Consumer} that has been registered using {@link #onEnable(Consumer)} or {@link #onDisable(Consumer)}. - * @param consumer the {@link Consumer} instance that has been registered previously - * @return true if a listener was removed as a result of this call - */ - public static synchronized boolean unregisterListener(Consumer consumer) { - return onEnableConsumers.remove(consumer) | onDisableConsumers.remove(consumer); - } + /** + * Getter for a {@link BlueMapWorld} loaded by BlueMap with the given {@link UUID}. + * + *

See the documentation of {@link BlueMapWorld#getUuid()} for more information about the nature of the worlds {@link UUID}s!

+ * + * @see BlueMapWorld#getUuid() + * + * @param uuid the {@link UUID} of the world + * + * @return an {@link Optional} with the {@link BlueMapWorld} if it exists + */ + public abstract Optional getWorld(UUID uuid); - /** - * Used by BlueMap to register the API and call the listeners properly. - * @param instance the {@link BlueMapAPI}-instance - * @return true if the instance has been registered, false if there already was an instance registered - * @throws ExecutionException if a {@link BlueMapAPIListener} threw an exception during the registration - */ - @SuppressWarnings("deprecation") - protected static synchronized boolean registerInstance(BlueMapAPI instance) throws ExecutionException { - if (BlueMapAPI.instance != null) return false; - - BlueMapAPI.instance = instance; + /** + * Getter for a {@link BlueMapMap} loaded by BlueMap with the given id. + * @param id the map id (equivalent to the id configured in BlueMap's config + * @return an {@link Optional} with the {@link BlueMapMap} if it exists + */ + public abstract Optional getMap(String id); - List thrownExceptions = new ArrayList<>(0); - - for (Consumer listener : BlueMapAPI.onEnableConsumers) { - try { - listener.accept(BlueMapAPI.instance); - } catch (Throwable ex) { - thrownExceptions.add(ex); - } - } - - // backwards compatibility - for (BlueMapAPIListener listener : BlueMapAPI.listener) { - try { - listener.onEnable(BlueMapAPI.instance); - } catch (Throwable ex) { - thrownExceptions.add(ex); - } - } - - if (!thrownExceptions.isEmpty()) { - ExecutionException ex = new ExecutionException(thrownExceptions.get(0)); - for (int i = 1; i < thrownExceptions.size(); i++) { - ex.addSuppressed(thrownExceptions.get(i)); - } - throw ex; - } + /** + * Creates an image-file with the given {@link BufferedImage} somewhere in the web-root, so it can be used in the web-app (e.g. for {@link Marker}-icons). + * + *

The given path is used as file-name and (separated with '/') optional folders to organize the image-files. Do NOT include the file-ending! (e.g. "someFolder/somePOIIcon" will result in a file "somePOIIcon.png" in a folder "someFolder").

+ *

If the image file with the given path already exists, it will be replaced.

+ * + * @param image the image to create + * @param path the path/name of this image, the separator-char is '/' + * @return the relative address of the image in the web-app, + * which can be used as it is e.g. in the {@link de.bluecolored.bluemap.api.marker.POIMarker#setIcon(String, Vector2i)} method + * @throws IOException If an {@link IOException} is thrown while writing the image + */ + public abstract String createImage(BufferedImage image, String path) throws IOException; - return true; - } - - /** - * Used by BlueMap to unregister the API and call the listeners properly. - * @param instance the {@link BlueMapAPI} instance - * @return true if the instance was unregistered, false if there was no or an other instance registered - * @throws ExecutionException if a {@link BlueMapAPIListener} threw an exception during the un-registration - */ - @SuppressWarnings("deprecation") - protected static synchronized boolean unregisterInstance(BlueMapAPI instance) throws ExecutionException { - if (BlueMapAPI.instance != instance) return false; + /** + * Lists all images that are available. This includes all images previously created with the {@link #createImage(BufferedImage, String)} + * function, but might include more. + * @return A map of available images where: + *
    + *
  • the key is the image path how it would be used in the "path" parameter of the {@link #createImage(BufferedImage, String)} method
  • + *
  • and the value is the relative address of the image. The same ones that are returned from the {@link #createImage(BufferedImage, String)} method
  • + *
+ * @throws IOException If an {@link IOException} is thrown while reading the images + */ + public abstract Map availableImages() throws IOException; - List thrownExceptions = new ArrayList<>(0); - - for (Consumer listener : BlueMapAPI.onDisableConsumers) { - try { - listener.accept(BlueMapAPI.instance); - } catch (Exception ex) { - thrownExceptions.add(ex); - } - } + /** + * Getter for the configured web-root folder + * @return The {@link Path} of the web-root folder + */ + public abstract Path getWebRoot(); - // backwards compatibility - for (BlueMapAPIListener listener : BlueMapAPI.listener) { - try { - listener.onDisable(BlueMapAPI.instance); - } catch (Exception ex) { - thrownExceptions.add(ex); - } - } - - BlueMapAPI.instance = null; + /** + * Getter for the installed BlueMap version + * @return the version-string + */ + public abstract String getBlueMapVersion(); - if (!thrownExceptions.isEmpty()) { - ExecutionException ex = new ExecutionException(thrownExceptions.get(0)); - for (int i = 1; i < thrownExceptions.size(); i++) { - ex.addSuppressed(thrownExceptions.get(i)); - } - throw ex; - } - - return true; - } + /** + * Register a listener that will be called when the API enables/disables + * @param listener the {@link BlueMapAPIListener} + * + * @deprecated Implementing {@link BlueMapAPIListener} can cause a ClassNotFoundException when you soft-depend on BlueMap and your plugin/mod gets used without BlueMap. + * Use {@link BlueMapAPI#onEnable(Consumer)} and {@link BlueMapAPI#onDisable(Consumer)} instead. + */ + @Deprecated + public static synchronized void registerListener(BlueMapAPIListener listener) { + BlueMapAPI.listener.add(listener); + if (BlueMapAPI.instance != null) listener.onEnable(BlueMapAPI.instance); + } + + /** + * Removes/Unregisters a previously registered listener + * @param listener the {@link BlueMapAPIListener} instance that has been registered previously + * + * @return true if a listener was removed as a result of this call + * + * @deprecated Implementing {@link BlueMapAPIListener} can cause a ClassNotFoundException when you soft-depend on BlueMap and your plugin/mod gets used without BlueMap. + * Use {@link BlueMapAPI#onEnable(Consumer)} and {@link BlueMapAPI#onDisable(Consumer)} instead. + */ + @Deprecated + public static synchronized boolean unregisterListener(BlueMapAPIListener listener) { + return BlueMapAPI.listener.remove(listener); + } + + /** + * Returns an instance of {@link BlueMapAPI} if it is currently enabled, else an empty {@link Optional} is returned. + * @return an {@link Optional}<{@link BlueMapAPI}> + */ + public static synchronized Optional getInstance() { + return Optional.ofNullable(instance); + } + + /** + * Registers a {@link Consumer} that will be called every time BlueMap has just been loaded and started and the API is ready to use.
+ * If {@link BlueMapAPI} is already enabled when this listener is registered the consumer will be called immediately (once, on the same thread)! + *

The {@link Consumer} can be called multiple times if BlueMap disables and enables again, e.g. if BlueMap gets reloaded!

+ *

(Note: The consumer will likely be called asynchronously, not on the server-thread!)

+ *

Remember to unregister the consumer when you no longer need it using {@link #unregisterListener(Consumer)}.

+ * @param consumer the {@link Consumer} + */ + public static synchronized void onEnable(Consumer consumer) { + onEnableConsumers.add(consumer); + if (BlueMapAPI.instance != null) consumer.accept(BlueMapAPI.instance); + } + + /** + * Registers a {@link Consumer} that will be called every time before BlueMap is being unloaded and stopped, after the consumer returns the API is no longer usable!
+ * Unlike with {@link BlueMapAPI#onEnable(Consumer)}, if {@link BlueMapAPI} is not enabled when this listener is registered the consumer will not be called. + *

The {@link Consumer} can be called multiple times if BlueMap disables and enables again, e.g. if BlueMap gets reloaded!

+ *

(Note: The consumer will likely be called asynchronously, not on the server-thread!)

+ *

Remember to unregister the consumer when you no longer need it using {@link #unregisterListener(Consumer)}.

+ * @param consumer the {@link Consumer} + */ + public static synchronized void onDisable(Consumer consumer) { + onDisableConsumers.add(consumer); + } + + /** + * Removes a {@link Consumer} that has been registered using {@link #onEnable(Consumer)} or {@link #onDisable(Consumer)}. + * @param consumer the {@link Consumer} instance that has been registered previously + * @return true if a listener was removed as a result of this call + */ + public static synchronized boolean unregisterListener(Consumer consumer) { + return onEnableConsumers.remove(consumer) | onDisableConsumers.remove(consumer); + } + + /** + * Used by BlueMap to register the API and call the listeners properly. + * @param instance the {@link BlueMapAPI}-instance + * @return true if the instance has been registered, false if there already was an instance registered + * @throws ExecutionException if a {@link BlueMapAPIListener} threw an exception during the registration + */ + @SuppressWarnings("deprecation") + protected static synchronized boolean registerInstance(BlueMapAPI instance) throws ExecutionException { + if (BlueMapAPI.instance != null) return false; + + BlueMapAPI.instance = instance; + + List thrownExceptions = new ArrayList<>(0); + + for (Consumer listener : BlueMapAPI.onEnableConsumers) { + try { + listener.accept(BlueMapAPI.instance); + } catch (Throwable ex) { + thrownExceptions.add(ex); + } + } + + // backwards compatibility + for (BlueMapAPIListener listener : BlueMapAPI.listener) { + try { + listener.onEnable(BlueMapAPI.instance); + } catch (Throwable ex) { + thrownExceptions.add(ex); + } + } + + if (!thrownExceptions.isEmpty()) { + ExecutionException ex = new ExecutionException(thrownExceptions.get(0)); + for (int i = 1; i < thrownExceptions.size(); i++) { + ex.addSuppressed(thrownExceptions.get(i)); + } + throw ex; + } + + return true; + } + + /** + * Used by BlueMap to unregister the API and call the listeners properly. + * @param instance the {@link BlueMapAPI} instance + * @return true if the instance was unregistered, false if there was no or an other instance registered + * @throws ExecutionException if a {@link BlueMapAPIListener} threw an exception during the un-registration + */ + @SuppressWarnings("deprecation") + protected static synchronized boolean unregisterInstance(BlueMapAPI instance) throws ExecutionException { + if (BlueMapAPI.instance != instance) return false; + + List thrownExceptions = new ArrayList<>(0); + + for (Consumer listener : BlueMapAPI.onDisableConsumers) { + try { + listener.accept(BlueMapAPI.instance); + } catch (Exception ex) { + thrownExceptions.add(ex); + } + } + + // backwards compatibility + for (BlueMapAPIListener listener : BlueMapAPI.listener) { + try { + listener.onDisable(BlueMapAPI.instance); + } catch (Exception ex) { + thrownExceptions.add(ex); + } + } + + BlueMapAPI.instance = null; + + if (!thrownExceptions.isEmpty()) { + ExecutionException ex = new ExecutionException(thrownExceptions.get(0)); + for (int i = 1; i < thrownExceptions.size(); i++) { + ex.addSuppressed(thrownExceptions.get(i)); + } + throw ex; + } + + return true; + } } diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPIListener.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPIListener.java index 3a85102..f351c0c 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPIListener.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPIListener.java @@ -33,20 +33,20 @@ @Deprecated public interface BlueMapAPIListener { - /** - * Called when BlueMap has been loaded and started and the API is ready to use.
- * If {@link BlueMapAPI} is already enabled when this listener is registered this method will be called immediately (on the same thread)! - *

(Note: This method will likely be called asynchronously, not on the server-thread!

- * @param blueMapApi the {@link BlueMapAPI} - */ - default void onEnable(BlueMapAPI blueMapApi) {} - - /** - * Called before BlueMap is being unloaded and stopped, after this method returns the API is no longer usable!
- * Unlike {@link BlueMapAPIListener#onEnable(BlueMapAPI)}, if {@link BlueMapAPI} is not enabled when this listener is registered this method will not be called immediately. - *

(Note: This method will likely be called asynchronously, not on the server-thread!

- * @param blueMapApi the {@link BlueMapAPI} - */ - default void onDisable(BlueMapAPI blueMapApi) {} - + /** + * Called when BlueMap has been loaded and started and the API is ready to use.
+ * If {@link BlueMapAPI} is already enabled when this listener is registered this method will be called immediately (on the same thread)! + *

(Note: This method will likely be called asynchronously, not on the server-thread!

+ * @param blueMapApi the {@link BlueMapAPI} + */ + default void onEnable(BlueMapAPI blueMapApi) {} + + /** + * Called before BlueMap is being unloaded and stopped, after this method returns the API is no longer usable!
+ * Unlike {@link BlueMapAPIListener#onEnable(BlueMapAPI)}, if {@link BlueMapAPI} is not enabled when this listener is registered this method will not be called immediately. + *

(Note: This method will likely be called asynchronously, not on the server-thread!

+ * @param blueMapApi the {@link BlueMapAPI} + */ + default void onDisable(BlueMapAPI blueMapApi) {} + } diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java index a715530..bd4dd0b 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java @@ -37,99 +37,99 @@ */ 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 - */ - String getId(); + /** + * Returns this maps id, this is equal to the id configured in bluemap's config for this map. + * @return the id of this map + */ + 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 - */ - String getName(); - - /** - * Getter for the {@link BlueMapWorld} of this map. - * @return the {@link BlueMapWorld} of this map - */ - BlueMapWorld getWorld(); + /** + * 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 + */ + String getName(); - /** - * Getter for the size of all tiles on this map in blocks. - * @return the tile-size in blocks - */ - Vector2i getTileSize(); - - /** - * Getter for the offset of the tile-grid on this map.
- * 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 - */ - Vector2i getTileOffset(); + /** + * Getter for the {@link BlueMapWorld} of this map. + * @return the {@link BlueMapWorld} of this map + */ + BlueMapWorld getWorld(); - /** - *

Sets a filter that determines if a specific (hires) tile of this map should be updated or not. - * If this filter returns false for a tile, the "render"-process of this tile will be cancelled and the tile will be left untouched.

- *

Warning: Using this method will harm the integrity of the map! Since BlueMap will still assume that the tile got updated properly.

- *

Any previously set filters will get overwritten with the new one. You can get the current filter using {@link #getTileFilter()} and combine them if you wish.

- * @param filter The filter that will be used from now on. - */ - void setTileFilter(Predicate filter); + /** + * Getter for the size of all tiles on this map in blocks. + * @return the tile-size in blocks + */ + Vector2i getTileSize(); - /** - * Freezes or unfreezes the map in the same way the `/bluemap freeze` command does. - * BlueMap will no longer attempt to update this map if it is frozen. - * @param frozen Whether the map will be frozen or not - */ - void setFrozen(boolean frozen); + /** + * Getter for the offset of the tile-grid on this map.
+ * 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 + */ + Vector2i getTileOffset(); - /** - * Checks if the map is currently frozen - * @return true if the map is frozen, false otherwise - */ - boolean isFrozen(); + /** + *

Sets a filter that determines if a specific (hires) tile of this map should be updated or not. + * If this filter returns false for a tile, the "render"-process of this tile will be cancelled and the tile will be left untouched.

+ *

Warning: Using this method will harm the integrity of the map! Since BlueMap will still assume that the tile got updated properly.

+ *

Any previously set filters will get overwritten with the new one. You can get the current filter using {@link #getTileFilter()} and combine them if you wish.

+ * @param filter The filter that will be used from now on. + */ + void setTileFilter(Predicate filter); - /** - * Returns the currently set TileFilter. The default TileFilter is equivalent to t -> true. - */ - Predicate getTileFilter(); + /** + * Freezes or unfreezes the map in the same way the `/bluemap freeze` command does. + * BlueMap will no longer attempt to update this map if it is frozen. + * @param frozen Whether the map will be frozen or not + */ + void setFrozen(boolean frozen); - /** - * Converts a block-position to a map-tile-coordinate for this map - * - * @param blockX the x-position of the block - * @param blockZ the z-position of the block - * @return the tile position - */ - default Vector2i posToTile(double blockX, double blockZ){ - Vector2i offset = getTileOffset(); - Vector2i size = getTileSize(); - - return Vector2i.from( - (int) Math.floor((blockX - offset.getX()) / size.getX()), - (int) Math.floor((blockZ - offset.getY()) / size.getY()) - ); - } - - /** - * Converts a block-position to a map-tile-coordinate for this map - * - * @param pos the position of the block - * @return the tile position - */ - default Vector2i posToTile(Vector3i pos){ - return posToTile(pos.getX(), pos.getZ()); - } + /** + * Checks if the map is currently frozen + * @return true if the map is frozen, false otherwise + */ + boolean isFrozen(); + + /** + * Returns the currently set TileFilter. The default TileFilter is equivalent to t -> true. + */ + Predicate getTileFilter(); + + /** + * Converts a block-position to a map-tile-coordinate for this map + * + * @param blockX the x-position of the block + * @param blockZ the z-position of the block + * @return the tile position + */ + default Vector2i posToTile(double blockX, double blockZ){ + Vector2i offset = getTileOffset(); + Vector2i size = getTileSize(); + + return Vector2i.from( + (int) Math.floor((blockX - offset.getX()) / size.getX()), + (int) Math.floor((blockZ - offset.getY()) / size.getY()) + ); + } + + /** + * Converts a block-position to a map-tile-coordinate for this map + * + * @param pos the position of the block + * @return the tile position + */ + default Vector2i posToTile(Vector3i pos){ + return posToTile(pos.getX(), pos.getZ()); + } + + /** + * Converts a block-position to a map-tile-coordinate for this map + * + * @param pos the position of the block + * @return the tile position + */ + default Vector2i posToTile(Vector3d pos){ + return posToTile(pos.getX(), pos.getZ()); + } - /** - * Converts a block-position to a map-tile-coordinate for this map - * - * @param pos the position of the block - * @return the tile position - */ - default Vector2i posToTile(Vector3d pos){ - return posToTile(pos.getX(), pos.getZ()); - } - } diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java index 59d0a8b..3d9a1b8 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java @@ -33,37 +33,37 @@ */ public interface BlueMapWorld { - /** - *

Getter for the {@link UUID} of the world.

- *

- * The {@link UUID}s of this worlds are not guaranteed to be consistent across reloads/restarts! - *

- *

- * Implementation notes:
- * The used UUID highly depends on the implementation - *

- * - * - * - * - * - * - *
Implementations
SpongeThe UUID is equal to the returned UUID by world-instances of the Sponge-API, so you can just use spongeWorld.getUniqueId()
BukkitThe UUID is equal to the returned UUID by world-instances of the Bukkit-API, so you can just use bukkitWorld.getUID()
ForgeThe UUID is randomly generated, and changes on each reload/restart
CLIThe UUID is randomly generated, and changes on each reload/restart
- * - * @return the {@link UUID} of the world - */ - UUID getUuid(); - - /** - * 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. - */ - Path getSaveFolder(); - - /** - * Getter for all {@link BlueMapMap}s for this world - * @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world - */ - Collection getMaps(); - + /** + *

Getter for the {@link UUID} of the world.

+ *

+ * The {@link UUID}s of this worlds are not guaranteed to be consistent across reloads/restarts! + *

+ *

+ * Implementation notes:
+ * The used UUID highly depends on the implementation + *

+ * + * + * + * + * + * + *
Implementations
SpongeThe UUID is equal to the returned UUID by world-instances of the Sponge-API, so you can just use spongeWorld.getUniqueId()
BukkitThe UUID is equal to the returned UUID by world-instances of the Bukkit-API, so you can just use bukkitWorld.getUID()
ForgeThe UUID is randomly generated, and changes on each reload/restart
CLIThe UUID is randomly generated, and changes on each reload/restart
+ * + * @return the {@link UUID} of the world + */ + UUID getUuid(); + + /** + * 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. + */ + Path getSaveFolder(); + + /** + * Getter for all {@link BlueMapMap}s for this world + * @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world + */ + Collection getMaps(); + } 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 1a4729f..5d97660 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/DistanceRangedMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/DistanceRangedMarker.java @@ -26,36 +26,36 @@ public interface DistanceRangedMarker extends Marker { - /** - * Getter for the minimum distance of the camera to the position for this {@link Marker} to be displayed.
- * If the camera is closer to this {@link Marker} than this distance, it will be hidden! - * - * @return the minimum distance for this {@link Marker} to be displayed - */ - double getMinDistance(); + /** + * Getter for the minimum distance of the camera to the position for this {@link Marker} to be displayed.
+ * If the camera is closer to this {@link Marker} than this distance, it will be hidden! + * + * @return the minimum distance for this {@link Marker} to be displayed + */ + double getMinDistance(); - /** - * Sets the minimum distance of the camera to the position of the {@link Marker} for it to be displayed.
- * If the camera is closer to this {@link Marker} than this distance, it will be hidden! - * - * @param minDistance the new minimum distance - */ - void setMinDistance(double minDistance); + /** + * Sets the minimum distance of the camera to the position of the {@link Marker} for it to be displayed.
+ * If the camera is closer to this {@link Marker} than this distance, it will be hidden! + * + * @param minDistance the new minimum distance + */ + void setMinDistance(double minDistance); - /** - * Getter for the maximum distance of the camera to the position of the {@link Marker} for it to be displayed.
- * If the camera is further to this {@link Marker} than this distance, it will be hidden! - * - * @return the maximum distance for this {@link Marker} to be displayed - */ - double getMaxDistance(); + /** + * Getter for the maximum distance of the camera to the position of the {@link Marker} for it to be displayed.
+ * If the camera is further to this {@link Marker} than this distance, it will be hidden! + * + * @return the maximum distance for this {@link Marker} to be displayed + */ + double getMaxDistance(); - /** - * Sets the maximum distance of the camera to the position of the {@link Marker} for it to be displayed.
- * If the camera is further to this {@link Marker} than this distance, it will be hidden! - * - * @param maxDistance the new maximum distance - */ - void setMaxDistance(double maxDistance); + /** + * Sets the maximum distance of the camera to the position of the {@link Marker} for it to be displayed.
+ * If the camera is further to this {@link Marker} than this distance, it will be hidden! + * + * @param maxDistance the new maximum distance + */ + void setMaxDistance(double 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 549fefb..549e5f6 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/ExtrudeMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/ExtrudeMarker.java @@ -28,95 +28,95 @@ public interface ExtrudeMarker extends ObjectMarker, DistanceRangedMarker { - /** - * Getter for {@link Shape} of this {@link ExtrudeMarker}. - *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points are the z-coordinates in the map.

- * @return the {@link Shape} - */ - Shape getShape(); + /** + * Getter for {@link Shape} of this {@link ExtrudeMarker}. + *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points are the z-coordinates in the map.

+ * @return the {@link Shape} + */ + Shape getShape(); - /** - * Getter for the minimum height (y-coordinate) of where the shape is displayed on the map.
- * (The shape will be extruded from this value to {@link #getShapeMaxY()} on the map) - * @return the min-height of the shape on the map - */ - float getShapeMinY(); + /** + * Getter for the minimum height (y-coordinate) of where the shape is displayed on the map.
+ * (The shape will be extruded from this value to {@link #getShapeMaxY()} on the map) + * @return the min-height of the shape on the map + */ + float getShapeMinY(); - /** - * Getter for the maximum height (y-coordinate) of where the shape is displayed on the map. - * (The shape will be extruded from {@link #getShapeMinY()} to this value on the map) - * @return the max-height of the shape on the map - */ - float getShapeMaxY(); - - /** - * Sets the {@link Shape} of this {@link ExtrudeMarker}. - *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points will be the z-coordinates in the map.

- * (The shape will be extruded from minY to maxY on the map) - * @param shape the new {@link Shape} - * @param minY the new min-height (y-coordinate) of the shape on the map - * @param maxY the new max-height (y-coordinate) of the shape on the map - */ - void setShape(Shape shape, float minY, float maxY); + /** + * Getter for the maximum height (y-coordinate) of where the shape is displayed on the map. + * (The shape will be extruded from {@link #getShapeMinY()} to this value on the map) + * @return the max-height of the shape on the map + */ + float getShapeMaxY(); - /** - * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. - * @return true if the depthTest is enabled - */ - boolean isDepthTestEnabled(); - - /** - * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. - * @param enabled if the depth-test should be enabled for this {@link ExtrudeMarker} - */ - void setDepthTestEnabled(boolean enabled); + /** + * Sets the {@link Shape} of this {@link ExtrudeMarker}. + *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points will be the z-coordinates in the map.

+ * (The shape will be extruded from minY to maxY on the map) + * @param shape the new {@link Shape} + * @param minY the new min-height (y-coordinate) of the shape on the map + * @param maxY the new max-height (y-coordinate) of the shape on the map + */ + void setShape(Shape shape, float minY, float maxY); - /** - * Getter for the width of the lines of this {@link ExtrudeMarker}. - * @return the width of the lines in pixels - */ - int getLineWidth(); + /** + * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. + * @return true if the depthTest is enabled + */ + boolean isDepthTestEnabled(); - /** - * Sets the width of the lines for this {@link ExtrudeMarker}. - * @param width the new width in pixels - */ - void setLineWidth(int width); + /** + * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. + * @param enabled if the depth-test should be enabled for this {@link ExtrudeMarker} + */ + void setDepthTestEnabled(boolean enabled); - /** - * Getter for the {@link Color} of the border-line of the shape. - * @return the line-color - */ - Color getLineColor(); + /** + * Getter for the width of the lines of this {@link ExtrudeMarker}. + * @return the width of the lines in pixels + */ + int getLineWidth(); - /** - * Sets the {@link Color} of the border-line of the shape. - * @param color the new line-color - */ - void setLineColor(Color color); + /** + * Sets the width of the lines for this {@link ExtrudeMarker}. + * @param width the new width in pixels + */ + void setLineWidth(int width); + + /** + * Getter for the {@link Color} of the border-line of the shape. + * @return the line-color + */ + Color getLineColor(); + + /** + * Sets the {@link Color} of the border-line of the shape. + * @param color the new line-color + */ + void setLineColor(Color color); + + /** + * Getter for the fill-{@link Color} of the shape. + * @return the fill-color + */ + Color getFillColor(); + + /** + * Sets the fill-{@link Color} of the shape. + * @param color the new fill-color + */ + void setFillColor(Color color); + + /** + * Sets the border- and fill- color. + * @param lineColor the new border-color + * @param fillColor the new fill-color + * @see #setLineColor(Color) + * @see #setFillColor(Color) + */ + default void setColors(Color lineColor, Color fillColor) { + setLineColor(lineColor); + setFillColor(fillColor); + } - /** - * Getter for the fill-{@link Color} of the shape. - * @return the fill-color - */ - Color getFillColor(); - - /** - * Sets the fill-{@link Color} of the shape. - * @param color the new fill-color - */ - void setFillColor(Color color); - - /** - * Sets the border- and fill- color. - * @param lineColor the new border-color - * @param fillColor the new fill-color - * @see #setLineColor(Color) - * @see #setFillColor(Color) - */ - default void setColors(Color lineColor, Color fillColor) { - setLineColor(lineColor); - setFillColor(fillColor); - } - } 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 11b7042..fb111d1 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/HtmlMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/HtmlMarker.java @@ -29,43 +29,43 @@ public interface HtmlMarker extends Marker, DistanceRangedMarker { - /** - * Getter for the position (in pixels) where the html-element is anchored to the map. - * @return the anchor-position in pixels - */ - Vector2i getAnchor(); + /** + * Getter for the position (in pixels) where the html-element is anchored to the map. + * @return the anchor-position in pixels + */ + Vector2i getAnchor(); - /** - * Sets the position (in pixels) where the html-element is anchored to the map. - * @param anchor the anchor-position in pixels - */ - void setAnchor(Vector2i anchor); + /** + * Sets the position (in pixels) where the html-element is anchored to the map. + * @param anchor the anchor-position in pixels + */ + void setAnchor(Vector2i anchor); - /** - * Sets the position (in pixels) where the html-element is anchored to the map. - * @param x the anchor-x-position in pixels - * @param y the anchor-y-position in pixels - */ - default void setAnchor(int x, int y) { - setAnchor(new Vector2i(x, y)); - } + /** + * Sets the position (in pixels) where the html-element is anchored to the map. + * @param x the anchor-x-position in pixels + * @param y the anchor-y-position in pixels + */ + default void setAnchor(int x, int y) { + setAnchor(new Vector2i(x, y)); + } - /** - * Getter for the html-code of this HTML marker - * @return the html-code - */ - String getHtml(); + /** + * Getter for the html-code of this HTML marker + * @return the html-code + */ + String getHtml(); + + /** + * Sets the html for this {@link HtmlMarker}. + * + *

+ * Important:
+ * Make sure you escape all html-tags from possible user inputs to prevent possible XSS-Attacks on the web-client! + *

+ * + * @param html the html that will be inserted as the marker. + */ + void setHtml(String html); - /** - * Sets the html for this {@link HtmlMarker}. - * - *

- * Important:
- * Make sure you escape all html-tags from possible user inputs to prevent possible XSS-Attacks on the web-client! - *

- * - * @param html the html that will be inserted as the marker. - */ - void setHtml(String html); - } diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/Line.java b/src/main/java/de/bluecolored/bluemap/api/marker/Line.java index 34d9074..2f336c0 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/Line.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/Line.java @@ -33,64 +33,64 @@ */ public class Line { - private final Vector3d[] points; - private Vector3d min = null; - private Vector3d max = null; + private final Vector3d[] points; + private Vector3d min = null; + private Vector3d max = null; + + public Line(Vector3d... points) { + if (points.length < 2) throw new IllegalArgumentException("A line has to have at least 2 points!"); + this.points = points; + } + + /** + * Getter for the amount of points in this line. + * @return the amount of points + */ + public int getPointCount() { + return points.length; + } + + public Vector3d getPoint(int i) { + return points[i]; + } + + /** + * Getter for a copy of the points array.
+ * (A line is immutable once created) + * @return the points of this line + */ + public Vector3d[] getPoints() { + return Arrays.copyOf(points, points.length); + } + + /** + * Calculates and returns the minimum corner of the axis-aligned-bounding-box of this line. + * @return the min of the AABB of this line + */ + public Vector3d getMin() { + if (this.min == null) { + Vector3d min = points[0]; + for (int i = 1; i < points.length; i++) { + min = min.min(points[i]); + } + this.min = min; + } + return this.min; + } + + /** + * Calculates and returns the maximum corner of the axis-aligned-bounding-box of this line. + * @return the max of the AABB of this line + */ + public Vector3d getMax() { + if (this.max == null) { + Vector3d max = points[0]; + for (int i = 1; i < points.length; i++) { + max = max.max(points[i]); + } + this.max = max; + } + return this.max; + } - public Line(Vector3d... points) { - if (points.length < 2) throw new IllegalArgumentException("A line has to have at least 2 points!"); - this.points = points; - } - - /** - * Getter for the amount of points in this line. - * @return the amount of points - */ - public int getPointCount() { - return points.length; - } - - public Vector3d getPoint(int i) { - return points[i]; - } - - /** - * Getter for a copy of the points array.
- * (A line is immutable once created) - * @return the points of this line - */ - public Vector3d[] getPoints() { - return Arrays.copyOf(points, points.length); - } - - /** - * Calculates and returns the minimum corner of the axis-aligned-bounding-box of this line. - * @return the min of the AABB of this line - */ - public Vector3d getMin() { - if (this.min == null) { - Vector3d min = points[0]; - for (int i = 1; i < points.length; i++) { - min = min.min(points[i]); - } - this.min = min; - } - return this.min; - } - - /** - * Calculates and returns the maximum corner of the axis-aligned-bounding-box of this line. - * @return the max of the AABB of this line - */ - public Vector3d getMax() { - if (this.max == null) { - Vector3d max = points[0]; - for (int i = 1; i < points.length; i++) { - max = max.max(points[i]); - } - this.max = max; - } - return this.max; - } - } 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 d25861d..e3a5cf3 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/LineMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/LineMarker.java @@ -28,52 +28,52 @@ public interface LineMarker extends ObjectMarker, DistanceRangedMarker { - /** - * Getter for {@link Line} of this {@link LineMarker}. - * @return the {@link Line} - */ - Line getLine(); - - /** - * Sets the {@link Line} of this {@link LineMarker}. - * @param line the new {@link Line} - */ - void setLine(Line line); + /** + * Getter for {@link Line} of this {@link LineMarker}. + * @return the {@link Line} + */ + Line getLine(); - /** - * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. - * @return true if the depthTest is enabled - */ - boolean isDepthTestEnabled(); - - /** - * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. - * @param enabled if the depth-test should be enabled for this {@link LineMarker} - */ - void setDepthTestEnabled(boolean enabled); + /** + * Sets the {@link Line} of this {@link LineMarker}. + * @param line the new {@link Line} + */ + void setLine(Line line); - /** - * Getter for the width of the lines of this {@link LineMarker}. - * @return the width of the lines in pixels - */ - int getLineWidth(); + /** + * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. + * @return true if the depthTest is enabled + */ + boolean isDepthTestEnabled(); - /** - * Sets the width of the lines for this {@link LineMarker}. - * @param width the new width in pixels - */ - void setLineWidth(int width); + /** + * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. + * @param enabled if the depth-test should be enabled for this {@link LineMarker} + */ + void setDepthTestEnabled(boolean enabled); - /** - * Getter for the {@link Color} of the border-line of the shape. - * @return the line-color - */ - Color getLineColor(); + /** + * Getter for the width of the lines of this {@link LineMarker}. + * @return the width of the lines in pixels + */ + int getLineWidth(); + + /** + * Sets the width of the lines for this {@link LineMarker}. + * @param width the new width in pixels + */ + void setLineWidth(int width); + + /** + * Getter for the {@link Color} of the border-line of the shape. + * @return the line-color + */ + Color getLineColor(); + + /** + * Sets the {@link Color} of the border-line of the shape. + * @param color the new line-color + */ + void setLineColor(Color color); - /** - * Sets the {@link Color} of the border-line of the shape. - * @param color the new line-color - */ - void setLineColor(Color color); - } diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/LinkMarker.java b/src/main/java/de/bluecolored/bluemap/api/marker/LinkMarker.java index eb8f653..9a6604e 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/LinkMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/LinkMarker.java @@ -28,33 +28,33 @@ public interface LinkMarker extends Marker { - /** - * Gets the link-address of this {@link Marker}.
- * If a link is present, this link will be followed when the user clicks on the marker in the web-app. - * - * @return the {@link Optional} link - */ - Optional getLink(); + /** + * Gets the link-address of this {@link Marker}.
+ * If a link is present, this link will be followed when the user clicks on the marker in the web-app. + * + * @return the {@link Optional} link + */ + Optional getLink(); - /** - * If this is true the link ({@link #getLink()}) will be opened in a new tab. - * @return whether the link will be opened in a new tab - * @see #getLink() - */ - boolean isNewTab(); + /** + * If this is true the link ({@link #getLink()}) will be opened in a new tab. + * @return whether the link will be opened in a new tab + * @see #getLink() + */ + boolean isNewTab(); - /** - * Sets the link-address of this {@link Marker}.
- * If a link is present, this link will be followed when the user clicks on the marker in the web-app. - * - * @param link the link, or null to disable the link - * @param newTab whether the link should be opened in a new tab - */ - void setLink(String link, boolean newTab); + /** + * Sets the link-address of this {@link Marker}.
+ * If a link is present, this link will be followed when the user clicks on the marker in the web-app. + * + * @param link the link, or null to disable the link + * @param newTab whether the link should be opened in a new tab + */ + void setLink(String link, boolean newTab); - /** - * Removes the link of this {@link Marker}. - */ - void removeLink(); + /** + * Removes the link of this {@link Marker}. + */ + void removeLink(); } 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 04fa0dd..6fb21a6 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/Marker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/Marker.java @@ -31,129 +31,129 @@ /** * A marker that is displayed on one of the maps in the web-app. - *

Each marker has an id that is unique in the {@link MarkerSet} that it is in.

+ *

Each marker has an id that is unique in the {@link MarkerSet} that it is in.

*/ public interface Marker { - /** - * Getter for the id of this {@link Marker}. - *

The id is unique in the {@link MarkerSet} that this marker is in.

- * @return the id of this {@link Marker} - */ - String getId(); - - /** - * Getter for the {@link BlueMapMap} this {@link Marker} lives in. - * @return the {@link BlueMapMap} this {@link Marker} lives in - */ - BlueMapMap getMap(); - - /** - * Sets the {@link BlueMapMap} this {@link Marker} lives in - * @param map the new {@link BlueMapMap} - */ - void setMap(BlueMapMap map); - - /** - * Getter for the position of where this {@link Marker} lives on the map. - * @return the position of this {@link Marker} - */ - Vector3d getPosition(); - - /** - * Sets the position of where this {@link Marker} lives on the map. - * @param position the new position - */ - void setPosition(Vector3d position); - - /** - * Getter for the label of this marker. - * @return the label of this {@link Marker} - */ - String getLabel(); - - /** - * Sets the label of this {@link Marker}. - *

- * Using html-tags in the label is possible but deprecated! - *

- *

- * Important:
- * Html-tags in the label will not be escaped, so you can use them to style the {@link Marker}-labels.
- * Make sure you escape all html-tags from possible user inputs to prevent possible XSS-Attacks on the web-client! - *

- * - * @param label the new label for this {@link Marker} - */ - void setLabel(String label); + /** + * Getter for the id of this {@link Marker}. + *

The id is unique in the {@link MarkerSet} that this marker is in.

+ * @return the id of this {@link Marker} + */ + String getId(); - /** - * Getter for the minimum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
- * If the camera is closer to this {@link Marker} than this distance, it will be hidden! - * - * @return the minimum distance for this {@link Marker} to be displayed - * @deprecated Not all marker-types support this - */ - double getMinDistance(); + /** + * Getter for the {@link BlueMapMap} this {@link Marker} lives in. + * @return the {@link BlueMapMap} this {@link Marker} lives in + */ + BlueMapMap getMap(); - /** - * Sets the minimum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
- * If the camera is closer to this {@link Marker} than this distance, it will be hidden! - * - * @param minDistance the new minimum distance - * @deprecated Not all marker-types support this - */ - void setMinDistance(double minDistance); + /** + * Sets the {@link BlueMapMap} this {@link Marker} lives in + * @param map the new {@link BlueMapMap} + */ + void setMap(BlueMapMap map); - /** - * Getter for the maximum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
- * If the camera is further to this {@link Marker} than this distance, it will be hidden! - * - * @return the maximum distance for this {@link Marker} to be displayed - * @deprecated Not all marker-types support this - */ - double getMaxDistance(); + /** + * Getter for the position of where this {@link Marker} lives on the map. + * @return the position of this {@link Marker} + */ + Vector3d getPosition(); - /** - * Sets the maximum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
- * If the camera is further to this {@link Marker} than this distance, it will be hidden! - * - * @param maxDistance the new maximum distance - * @deprecated Not all marker-types support this - */ - void setMaxDistance(double maxDistance); + /** + * Sets the position of where this {@link Marker} lives on the map. + * @param position the new position + */ + void setPosition(Vector3d position); - /** - * Gets the link-address of this {@link Marker}.
- * If a link is present, this link will be followed when the user clicks on the marker in the web-app. - * - * @return the {@link Optional} link - * @deprecated Not all marker-types support this - */ - Optional getLink(); + /** + * Getter for the label of this marker. + * @return the label of this {@link Marker} + */ + String getLabel(); - /** - * If this is true the link ({@link #getLink()}) will be opened in a new tab. - * @return whether the link will be opened in a new tab - * @see #getLink() - * @deprecated Not all marker-types support this - */ - boolean isNewTab(); - - /** - * Sets the link-address of this {@link Marker}.
- * If a link is present, this link will be followed when the user clicks on the marker in the web-app. - * - * @param link the link, or null to disable the link - * @param newTab whether the link should be opened in a new tab - * @deprecated Not all marker-types support this - */ - void setLink(String link, boolean newTab); + /** + * Sets the label of this {@link Marker}. + *

+ * Using html-tags in the label is possible but deprecated! + *

+ *

+ * Important:
+ * Html-tags in the label will not be escaped, so you can use them to style the {@link Marker}-labels.
+ * Make sure you escape all html-tags from possible user inputs to prevent possible XSS-Attacks on the web-client! + *

+ * + * @param label the new label for this {@link Marker} + */ + void setLabel(String label); + + /** + * Getter for the minimum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
+ * If the camera is closer to this {@link Marker} than this distance, it will be hidden! + * + * @return the minimum distance for this {@link Marker} to be displayed + * @deprecated Not all marker-types support this + */ + double getMinDistance(); + + /** + * Sets the minimum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
+ * If the camera is closer to this {@link Marker} than this distance, it will be hidden! + * + * @param minDistance the new minimum distance + * @deprecated Not all marker-types support this + */ + void setMinDistance(double minDistance); + + /** + * Getter for the maximum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
+ * If the camera is further to this {@link Marker} than this distance, it will be hidden! + * + * @return the maximum distance for this {@link Marker} to be displayed + * @deprecated Not all marker-types support this + */ + double getMaxDistance(); + + /** + * Sets the maximum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.
+ * If the camera is further to this {@link Marker} than this distance, it will be hidden! + * + * @param maxDistance the new maximum distance + * @deprecated Not all marker-types support this + */ + void setMaxDistance(double maxDistance); + + /** + * Gets the link-address of this {@link Marker}.
+ * If a link is present, this link will be followed when the user clicks on the marker in the web-app. + * + * @return the {@link Optional} link + * @deprecated Not all marker-types support this + */ + Optional getLink(); + + /** + * If this is true the link ({@link #getLink()}) will be opened in a new tab. + * @return whether the link will be opened in a new tab + * @see #getLink() + * @deprecated Not all marker-types support this + */ + boolean isNewTab(); + + /** + * Sets the link-address of this {@link Marker}.
+ * If a link is present, this link will be followed when the user clicks on the marker in the web-app. + * + * @param link the link, or null to disable the link + * @param newTab whether the link should be opened in a new tab + * @deprecated Not all marker-types support this + */ + void setLink(String link, boolean newTab); + + /** + * Removes the link of this {@link Marker}. + * @deprecated Not all marker-types support this + */ + void removeLink(); - /** - * Removes the link of this {@link Marker}. - * @deprecated Not all marker-types support this - */ - void removeLink(); - } diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/MarkerAPI.java b/src/main/java/de/bluecolored/bluemap/api/marker/MarkerAPI.java index 2119830..aef1f44 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/MarkerAPI.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/MarkerAPI.java @@ -36,69 +36,69 @@ * Important:
* If you made changes to any {@link MarkerSet} or {@link Marker} including creations and deletions, you need to finally save your changes by calling {@link #save()}!
*

- *

To avoid any concurrent modifications to the markers.json, make sure your {@link MarkerAPI} is always loaded before making any changes, and saved right after the changes.

- * + *

To avoid any concurrent modifications to the markers.json, make sure your {@link MarkerAPI} is always loaded before making any changes, and saved right after the changes.

+ * * @see BlueMapAPI#getMarkerAPI() */ public interface MarkerAPI { - /** - * Getter for an unmodifiable {@link Collection} containing all {@link MarkerSet}s that are currently loaded with BlueMap. - * - * @return a {@link Collection} with all loaded {@link MarkerSet}s - */ - Collection getMarkerSets(); - - /** - * Getter for a loaded {@link MarkerSet} with the given id.
- * Returns an empty {@link Optional} if no {@link MarkerSet} with that id is loaded. - * - * @param id the id of the {@link MarkerSet} - * @return an {@link Optional}<{@link MarkerSet}> with the given id - */ - Optional getMarkerSet(String id); - - /** - * Created a new {@link MarkerSet} with the given id.
- * If there is already a {@link MarkerSet} with that id loaded, no new {@link MarkerSet} is created and the existing one is returned. - * - * @param id the id of the {@link MarkerSet} - * @return a {@link MarkerSet} with the given id - */ - MarkerSet createMarkerSet(String id); - - /** - * Removes the given {@link MarkerSet}.
- * This is equivalent to calling removeMarkerSet(markerSet.getId()). - * - * @param markerSet the {@link MarkerSet} to be removed - * @return true if the {@link MarkerSet} was removed, false if that {@link MarkerSet} didn't exist - */ - default boolean removeMarkerSet(MarkerSet markerSet) { - return removeMarkerSet(markerSet.getId()); - } - - /** - * Removes the {@link MarkerSet} with the given id. - * - * @param id the id of the {@link MarkerSet} to be removed - * @return true if the {@link MarkerSet} was removed, false if there was no {@link MarkerSet} with that id - */ - boolean removeMarkerSet(String id); - - /** - * Loads changes made by others, changes could be from other plugin's using the API or external changes to the markers.json.
- * Calling this will override all unsaved changes you made with this instance! - * - * @throws IOException if an {@link IOException} occurred while loading the markers.json - */ - void load() throws IOException; - - /** - * Saves all changes made with this instance to the markers.json.
- * - * @throws IOException if an {@link IOException} occurred while saving the markers.json - */ - void save() throws IOException; - + /** + * Getter for an unmodifiable {@link Collection} containing all {@link MarkerSet}s that are currently loaded with BlueMap. + * + * @return a {@link Collection} with all loaded {@link MarkerSet}s + */ + Collection getMarkerSets(); + + /** + * Getter for a loaded {@link MarkerSet} with the given id.
+ * Returns an empty {@link Optional} if no {@link MarkerSet} with that id is loaded. + * + * @param id the id of the {@link MarkerSet} + * @return an {@link Optional}<{@link MarkerSet}> with the given id + */ + Optional getMarkerSet(String id); + + /** + * Created a new {@link MarkerSet} with the given id.
+ * If there is already a {@link MarkerSet} with that id loaded, no new {@link MarkerSet} is created and the existing one is returned. + * + * @param id the id of the {@link MarkerSet} + * @return a {@link MarkerSet} with the given id + */ + MarkerSet createMarkerSet(String id); + + /** + * Removes the given {@link MarkerSet}.
+ * This is equivalent to calling removeMarkerSet(markerSet.getId()). + * + * @param markerSet the {@link MarkerSet} to be removed + * @return true if the {@link MarkerSet} was removed, false if that {@link MarkerSet} didn't exist + */ + default boolean removeMarkerSet(MarkerSet markerSet) { + return removeMarkerSet(markerSet.getId()); + } + + /** + * Removes the {@link MarkerSet} with the given id. + * + * @param id the id of the {@link MarkerSet} to be removed + * @return true if the {@link MarkerSet} was removed, false if there was no {@link MarkerSet} with that id + */ + boolean removeMarkerSet(String id); + + /** + * Loads changes made by others, changes could be from other plugin's using the API or external changes to the markers.json.
+ * Calling this will override all unsaved changes you made with this instance! + * + * @throws IOException if an {@link IOException} occurred while loading the markers.json + */ + void load() throws IOException; + + /** + * Saves all changes made with this instance to the markers.json.
+ * + * @throws IOException if an {@link IOException} occurred while saving the markers.json + */ + void save() throws IOException; + } 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 5e08730..d20cfee 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/MarkerSet.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/MarkerSet.java @@ -33,313 +33,313 @@ /** * A set of {@link Marker}s that are displayed on the maps in the web-app. - * - *

Each {@link MarkerSet} has an unique id.

+ * + *

Each {@link MarkerSet} has an unique id.

*/ public interface MarkerSet { - /** - * Getter for the id of this {@link MarkerSet}. - * @return the id of this {@link MarkerSet} - */ - String getId(); - - /** - * Getter for the label of this {@link MarkerSet}. - *

The label is used in the web-app to name the toggle-button of this {@link MarkerSet} if it is toggleable. ({@link #isToggleable()})

- * @return the label of this {@link MarkerSet} - */ - String getLabel(); - - /** - * Sets the label of this {@link MarkerSet}. - *

The label is used in the web-app to name the toggle-button of this {@link MarkerSet} if it is toggleable. ({@link #isToggleable()})

- * @param label the new label - */ - void setLabel(String label); - - /** - * Checks if the {@link MarkerSet} is toggleable. - *

If this is true, the web-app will display a toggle-button for this {@link MarkerSet} so the user can choose to enable/disable all markers of this set.

- * @return whether this {@link MarkerSet} is toggleable - */ - boolean isToggleable(); - - /** - * Changes if this {@link MarkerSet} is toggleable. - *

If this is true, the web-app will display a toggle-button for this {@link MarkerSet} so the user can choose to enable/disable all markers of this set.

- * @param toggleable whether this {@link MarkerSet} should be toggleable - */ - void setToggleable(boolean toggleable); + /** + * Getter for the id of this {@link MarkerSet}. + * @return the id of this {@link MarkerSet} + */ + String getId(); - /** - * @deprecated method name has a typo, use {@link #isDefaultHidden()} instead. - */ - default boolean isDefautHidden() { - return isDefaultHidden(); - } + /** + * Getter for the label of this {@link MarkerSet}. + *

The label is used in the web-app to name the toggle-button of this {@link MarkerSet} if it is toggleable. ({@link #isToggleable()})

+ * @return the label of this {@link MarkerSet} + */ + String getLabel(); - /** - * Checks if this {@link MarkerSet} is hidden by default. - *

This is basically the default-state of the toggle-button from {@link #isToggleable()}. If this is true the markers of this marker set will initially be hidden and can be displayed using the toggle-button.

- * - * @return whether this {@link MarkerSet} is hidden by default - * @see #isToggleable() - */ - boolean isDefaultHidden(); - - /** - * Sets if this {@link MarkerSet} is hidden by default. - *

This is basically the default-state of the toggle-button from {@link #isToggleable()}. If this is true the markers of this marker set will initially be hidden and can be displayed using the toggle-button.

- * - * @param defaultHide whether this {@link MarkerSet} should be hidden by default - * @see #isToggleable() - */ - void setDefaultHidden(boolean defaultHide); - - /** - * Getter for an unmodifiable {@link Collection} of all {@link Marker}s in this {@link MarkerSet}. - * - * @return a {@link Collection} with all {@link Marker}s of this {@link MarkerSet}. - */ - Collection getMarkers(); - - /** - * Getter for a {@link Marker} with the given id.
- * Returns an empty {@link Optional} if no {@link Marker} exists with the given id. - * - * @param id the id of the {@link Marker} - * @return an {@link Optional}<{@link Marker}> with the given id - */ - Optional getMarker(String id); + /** + * Sets the label of this {@link MarkerSet}. + *

The label is used in the web-app to name the toggle-button of this {@link MarkerSet} if it is toggleable. ({@link #isToggleable()})

+ * @param label the new label + */ + void setLabel(String label); - /** - * Creates a {@link POIMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a Marker with that id already exists, it will be replaced by the new {@link POIMarker}! - * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param position the position of the new marker - * @return the created {@link POIMarker} - */ - POIMarker createPOIMarker(String id, BlueMapMap map, Vector3d position); - - /** - * Creates a {@link POIMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link POIMarker}! - * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param posX the x-position of the new marker - * @param posY the y-position of the new marker - * @param posZ the z-position of the new marker - * @return the created {@link POIMarker} - */ - default POIMarker createPOIMarker(String id, BlueMapMap map, double posX, double posY, double posZ) { - return createPOIMarker(id, map, new Vector3d(posX, posY, posZ)); - } + /** + * Checks if the {@link MarkerSet} is toggleable. + *

If this is true, the web-app will display a toggle-button for this {@link MarkerSet} so the user can choose to enable/disable all markers of this set.

+ * @return whether this {@link MarkerSet} is toggleable + */ + boolean isToggleable(); + + /** + * Changes if this {@link MarkerSet} is toggleable. + *

If this is true, the web-app will display a toggle-button for this {@link MarkerSet} so the user can choose to enable/disable all markers of this set.

+ * @param toggleable whether this {@link MarkerSet} should be toggleable + */ + void setToggleable(boolean toggleable); + + /** + * @deprecated method name has a typo, use {@link #isDefaultHidden()} instead. + */ + default boolean isDefautHidden() { + return isDefaultHidden(); + } + + /** + * Checks if this {@link MarkerSet} is hidden by default. + *

This is basically the default-state of the toggle-button from {@link #isToggleable()}. If this is true the markers of this marker set will initially be hidden and can be displayed using the toggle-button.

+ * + * @return whether this {@link MarkerSet} is hidden by default + * @see #isToggleable() + */ + boolean isDefaultHidden(); + + /** + * Sets if this {@link MarkerSet} is hidden by default. + *

This is basically the default-state of the toggle-button from {@link #isToggleable()}. If this is true the markers of this marker set will initially be hidden and can be displayed using the toggle-button.

+ * + * @param defaultHide whether this {@link MarkerSet} should be hidden by default + * @see #isToggleable() + */ + void setDefaultHidden(boolean defaultHide); + + /** + * Getter for an unmodifiable {@link Collection} of all {@link Marker}s in this {@link MarkerSet}. + * + * @return a {@link Collection} with all {@link Marker}s of this {@link MarkerSet}. + */ + Collection getMarkers(); + + /** + * Getter for a {@link Marker} with the given id.
+ * Returns an empty {@link Optional} if no {@link Marker} exists with the given id. + * + * @param id the id of the {@link Marker} + * @return an {@link Optional}<{@link Marker}> with the given id + */ + Optional getMarker(String id); + + /** + * Creates a {@link POIMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a Marker with that id already exists, it will be replaced by the new {@link POIMarker}! + * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param position the position of the new marker + * @return the created {@link POIMarker} + */ + POIMarker createPOIMarker(String id, BlueMapMap map, Vector3d position); + + /** + * Creates a {@link POIMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link POIMarker}! + * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param posX the x-position of the new marker + * @param posY the y-position of the new marker + * @param posZ the z-position of the new marker + * @return the created {@link POIMarker} + */ + default POIMarker createPOIMarker(String id, BlueMapMap map, double posX, double posY, double posZ) { + return createPOIMarker(id, map, new Vector3d(posX, posY, posZ)); + } - /** - * Creates a {@link HtmlMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a Marker with that id already exists, it will be replaced by the new {@link HtmlMarker}! - * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param position the position of the new marker - * @param html the html-content of the new marker - * @return the created {@link HtmlMarker} - */ - HtmlMarker createHtmlMarker(String id, BlueMapMap map, Vector3d position, String html); + /** + * Creates a {@link HtmlMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a Marker with that id already exists, it will be replaced by the new {@link HtmlMarker}! + * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param position the position of the new marker + * @param html the html-content of the new marker + * @return the created {@link HtmlMarker} + */ + HtmlMarker createHtmlMarker(String id, BlueMapMap map, Vector3d position, String html); - /** - * Creates a {@link HtmlMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link HtmlMarker}! - * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param posX the x-position of the new marker - * @param posY the y-position of the new marker - * @param posZ the z-position of the new marker - * @param html the html-content of the new marker - * @return the created {@link HtmlMarker} - */ - default HtmlMarker createHtmlMarker(String id, BlueMapMap map, double posX, double posY, double posZ, String html) { - return createHtmlMarker(id, map, new Vector3d(posX, posY, posZ), html); - } - - /** - * Creates a {@link ShapeMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ShapeMarker}! - * - *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param position the position of the new marker - * @param shape the Shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) - * @param y the height (y-position on the map) of shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) - * @return the created {@link ShapeMarker} - */ - ShapeMarker createShapeMarker(String id, BlueMapMap map, Vector3d position, Shape shape, float y); - - /** - * Creates a {@link ShapeMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a Marker with that id already exists, it will be replaced by the new {@link ShapeMarker}! - * - *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param posX the x-position of the new marker - * @param posY the y-position of the new marker - * @param posZ the z-position of the new marker - * @param shape the Shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) - * @param y the height (y-position on the map) of shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) - * @return the created {@link ShapeMarker} - */ - default ShapeMarker createShapeMarker(String id, BlueMapMap map, double posX, double posY, double posZ, Shape shape, float y) { - return createShapeMarker(id, map, new Vector3d(posX, posY, posZ), shape, y); - } - - /** - * Creates a {@link ShapeMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a Marker with that id already exists, it will be replaced by the new {@link ShapeMarker}! - * - *

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

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param shape the Shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) - * @param y the height of shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) - * @return the created {@link ShapeMarker} - */ - default ShapeMarker createShapeMarker(String id, BlueMapMap map, Shape shape, float y) { - Vector2d center = shape.getMin().add(shape.getMax()).div(2); - return createShapeMarker(id, map, new Vector3d(center.getX(), y, center.getY()), shape, y); - } + /** + * Creates a {@link HtmlMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link HtmlMarker}! + * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param posX the x-position of the new marker + * @param posY the y-position of the new marker + * @param posZ the z-position of the new marker + * @param html the html-content of the new marker + * @return the created {@link HtmlMarker} + */ + default HtmlMarker createHtmlMarker(String id, BlueMapMap map, double posX, double posY, double posZ, String html) { + return createHtmlMarker(id, map, new Vector3d(posX, posY, posZ), html); + } - /** - * Creates a {@link ExtrudeMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ExtrudeMarker}! - * - *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param position the position of the new marker - * @param shape the {@link Shape} of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @param minY the min-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @param maxY the max-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @return the created {@link ExtrudeMarker} - */ - ExtrudeMarker createExtrudeMarker(String id, BlueMapMap map, Vector3d position, Shape shape, float minY, float maxY); + /** + * Creates a {@link ShapeMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ShapeMarker}! + * + *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param position the position of the new marker + * @param shape the Shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) + * @param y the height (y-position on the map) of shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) + * @return the created {@link ShapeMarker} + */ + ShapeMarker createShapeMarker(String id, BlueMapMap map, Vector3d position, Shape shape, float y); - /** - * Creates a {@link ExtrudeMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ExtrudeMarker}! - * - *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param posX the x-position of the new marker - * @param posY the y-position of the new marker - * @param posZ the z-position of the new marker - * @param shape the {@link Shape} of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @param minY the min-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @param maxY the max-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @return the created {@link ExtrudeMarker} - */ - default ExtrudeMarker createExtrudeMarker(String id, BlueMapMap map, double posX, double posY, double posZ, Shape shape, float minY, float maxY) { - return createExtrudeMarker(id, map, new Vector3d(posX, posY, posZ), shape, minY, maxY); - } + /** + * Creates a {@link ShapeMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a Marker with that id already exists, it will be replaced by the new {@link ShapeMarker}! + * + *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param posX the x-position of the new marker + * @param posY the y-position of the new marker + * @param posZ the z-position of the new marker + * @param shape the Shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) + * @param y the height (y-position on the map) of shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) + * @return the created {@link ShapeMarker} + */ + default ShapeMarker createShapeMarker(String id, BlueMapMap map, double posX, double posY, double posZ, Shape shape, float y) { + return createShapeMarker(id, map, new Vector3d(posX, posY, posZ), shape, y); + } - /** - * Creates a {@link ExtrudeMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ExtrudeMarker}! - * - *

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

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param shape the {@link Shape} of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @param minY the min-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @param maxY the max-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) - * @return the created {@link ExtrudeMarker} - */ - default ExtrudeMarker createExtrudeMarker(String id, BlueMapMap map, Shape shape, float minY, float maxY) { - Vector2d center = shape.getMin().add(shape.getMax()).div(2f); - float y = (minY + maxY)/2f; - return createExtrudeMarker(id, map, new Vector3d(center.getX(), y, center.getY()), shape, minY, maxY); - } + /** + * Creates a {@link ShapeMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a Marker with that id already exists, it will be replaced by the new {@link ShapeMarker}! + * + *

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

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param shape the Shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) + * @param y the height of shape of the marker (See: {@link ShapeMarker#setShape(Shape, float)}) + * @return the created {@link ShapeMarker} + */ + default ShapeMarker createShapeMarker(String id, BlueMapMap map, Shape shape, float y) { + Vector2d center = shape.getMin().add(shape.getMax()).div(2); + return createShapeMarker(id, map, new Vector3d(center.getX(), y, center.getY()), shape, y); + } - /** - * Creates a {@link LineMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link LineMarker}! - * - *

(Since the line has its own positions, the position is only used to determine e.g. the distance to the camera)

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param position the position of the new marker - * @param line the {@link Line} of the marker (See: {@link LineMarker#setLine(Line)}) - * @return the created {@link LineMarker} - */ - LineMarker createLineMarker(String id, BlueMapMap map, Vector3d position, Line line); + /** + * Creates a {@link ExtrudeMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ExtrudeMarker}! + * + *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param position the position of the new marker + * @param shape the {@link Shape} of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @param minY the min-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @param maxY the max-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @return the created {@link ExtrudeMarker} + */ + ExtrudeMarker createExtrudeMarker(String id, BlueMapMap map, Vector3d position, Shape shape, float minY, float maxY); - /** - * Creates a {@link LineMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link LineMarker}! - * - *

(Since the line has its own positions, the position is only used to determine e.g. the distance to the camera)

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param posX the x-position of the new marker - * @param posY the y-position of the new marker - * @param posZ the z-position of the new marker - * @param line the {@link Line} of the marker (See: {@link LineMarker#setLine(Line)}) - * @return the created {@link LineMarker} - */ - default LineMarker createLineMarker(String id, BlueMapMap map, double posX, double posY, double posZ, Line line) { - return createLineMarker(id, map, new Vector3d(posX, posY, posZ), line); - } + /** + * Creates a {@link ExtrudeMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ExtrudeMarker}! + * + *

(Since the shape has its own positions, the position is only used to determine e.g. the distance to the camera)

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param posX the x-position of the new marker + * @param posY the y-position of the new marker + * @param posZ the z-position of the new marker + * @param shape the {@link Shape} of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @param minY the min-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @param maxY the max-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @return the created {@link ExtrudeMarker} + */ + default ExtrudeMarker createExtrudeMarker(String id, BlueMapMap map, double posX, double posY, double posZ, Shape shape, float minY, float maxY) { + return createExtrudeMarker(id, map, new Vector3d(posX, posY, posZ), shape, minY, maxY); + } + + /** + * Creates a {@link ExtrudeMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link ExtrudeMarker}! + * + *

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

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param shape the {@link Shape} of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @param minY the min-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @param maxY the max-height (y-position on the map) of the shape of the marker (See: {@link ExtrudeMarker#setShape(Shape, float, float)}) + * @return the created {@link ExtrudeMarker} + */ + default ExtrudeMarker createExtrudeMarker(String id, BlueMapMap map, Shape shape, float minY, float maxY) { + Vector2d center = shape.getMin().add(shape.getMax()).div(2f); + float y = (minY + maxY)/2f; + return createExtrudeMarker(id, map, new Vector3d(center.getX(), y, center.getY()), shape, minY, maxY); + } + + /** + * Creates a {@link LineMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link LineMarker}! + * + *

(Since the line has its own positions, the position is only used to determine e.g. the distance to the camera)

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param position the position of the new marker + * @param line the {@link Line} of the marker (See: {@link LineMarker#setLine(Line)}) + * @return the created {@link LineMarker} + */ + LineMarker createLineMarker(String id, BlueMapMap map, Vector3d position, Line line); + + /** + * Creates a {@link LineMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link LineMarker}! + * + *

(Since the line has its own positions, the position is only used to determine e.g. the distance to the camera)

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param posX the x-position of the new marker + * @param posY the y-position of the new marker + * @param posZ the z-position of the new marker + * @param line the {@link Line} of the marker (See: {@link LineMarker#setLine(Line)}) + * @return the created {@link LineMarker} + */ + default LineMarker createLineMarker(String id, BlueMapMap map, double posX, double posY, double posZ, Line line) { + return createLineMarker(id, map, new Vector3d(posX, posY, posZ), line); + } + + /** + * Creates a {@link LineMarker} with the given id and adds it to this {@link MarkerSet}.
+ * If a {@link Marker} with that id already exists, it will be replaced by the new {@link LineMarker}! + * + *

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

+ * + * @param id the id of the new marker + * @param map the {@link BlueMapMap} of the new marker + * @param line the {@link Line} of the marker (See: {@link LineMarker#setLine(Line)}) + * @return the created {@link LineMarker} + */ + default LineMarker createLineMarker(String id, BlueMapMap map, Line line) { + Vector3d center = line.getMin().add(line.getMax()).div(2f); + return createLineMarker(id, map, center, line); + } + + /** + * Removes the given Marker from this {@link MarkerSet}.
+ * This is equivalent to calling removeMarker(marker.getId()). + * + * @param marker the {@link Marker} to be removed + * @return true if the {@link Marker} was removed, false if that {@link Marker} didn't exist + */ + default boolean removeMarker(Marker marker) { + return removeMarker(marker.getId()); + } + + /** + * Removes the {@link Marker} with the given id. + * + * @param id the id of the {@link Marker} to be removed + * @return true if the {@link Marker} was removed, false if there was no {@link Marker} with that id + */ + boolean removeMarker(String id); - /** - * Creates a {@link LineMarker} with the given id and adds it to this {@link MarkerSet}.
- * If a {@link Marker} with that id already exists, it will be replaced by the new {@link LineMarker}! - * - *

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

- * - * @param id the id of the new marker - * @param map the {@link BlueMapMap} of the new marker - * @param line the {@link Line} of the marker (See: {@link LineMarker#setLine(Line)}) - * @return the created {@link LineMarker} - */ - default LineMarker createLineMarker(String id, BlueMapMap map, Line line) { - Vector3d center = line.getMin().add(line.getMax()).div(2f); - return createLineMarker(id, map, center, line); - } - - /** - * Removes the given Marker from this {@link MarkerSet}.
- * This is equivalent to calling removeMarker(marker.getId()). - * - * @param marker the {@link Marker} to be removed - * @return true if the {@link Marker} was removed, false if that {@link Marker} didn't exist - */ - default boolean removeMarker(Marker marker) { - return removeMarker(marker.getId()); - } - - /** - * Removes the {@link Marker} with the given id. - * - * @param id the id of the {@link Marker} to be removed - * @return true if the {@link Marker} was removed, false if there was no {@link Marker} with that id - */ - boolean removeMarker(String id); - } 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 c2da249..c58cba3 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/ObjectMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/ObjectMarker.java @@ -26,23 +26,23 @@ public interface ObjectMarker extends Marker, LinkMarker { - /** - * Getter for the detail of this marker. The label can include html-tags. - * @return the detail of this {@link ObjectMarker} - */ - String getDetail(); + /** + * Getter for the detail of this marker. The label can include html-tags. + * @return the detail of this {@link ObjectMarker} + */ + String getDetail(); - /** - * Sets the detail of this {@link ObjectMarker}. The detail can include html-tags.
- * This is the text that will be displayed on the popup when you click on this marker. - *

- * Important:
- * Html-tags in the label will not be escaped, so you can use them to style the {@link ObjectMarker}-detail.
- * Make sure you escape all html-tags from possible user inputs to prevent possible XSS-Attacks on the web-client! - *

- * - * @param detail the new detail for this {@link ObjectMarker} - */ - void setDetail(String detail); + /** + * Sets the detail of this {@link ObjectMarker}. The detail can include html-tags.
+ * This is the text that will be displayed on the popup when you click on this marker. + *

+ * Important:
+ * Html-tags in the label will not be escaped, so you can use them to style the {@link ObjectMarker}-detail.
+ * Make sure you escape all html-tags from possible user inputs to prevent possible XSS-Attacks on the web-client! + *

+ * + * @param detail the new detail for this {@link ObjectMarker} + */ + void setDetail(String detail); } 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 6687d54..f25c9fe 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/POIMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/POIMarker.java @@ -30,42 +30,42 @@ public interface POIMarker extends Marker, DistanceRangedMarker { - /** - * Getter for the relative address of the icon used to display this {@link POIMarker} - * @return the relative web-address of the icon - */ - String getIconAddress(); - - /** - * Getter for the position (in pixels) where the icon is anchored to the map. - * @return the anchor-position in pixels - * @deprecated Use {@link #getAnchor()} instead - */ - default Vector2i getIconAnchor() { - return getAnchor(); - } + /** + * Getter for the relative address of the icon used to display this {@link POIMarker} + * @return the relative web-address of the icon + */ + String getIconAddress(); - /** - * Getter for the position (in pixels) where the icon is anchored to the map. - * @return the anchor-position in pixels - */ - Vector2i getAnchor(); + /** + * Getter for the position (in pixels) where the icon is anchored to the map. + * @return the anchor-position in pixels + * @deprecated Use {@link #getAnchor()} instead + */ + default Vector2i getIconAnchor() { + return getAnchor(); + } + + /** + * Getter for the position (in pixels) where the icon is anchored to the map. + * @return the anchor-position in pixels + */ + Vector2i getAnchor(); + + /** + * Sets the icon for this {@link POIMarker}. + * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. You can also use an address returned by {@link BlueMapAPI#createImage(java.awt.image.BufferedImage, String)}. + * @param anchorX the x-position of the position (in pixels) where the icon is anchored to the map + * @param anchorY the y-position of the position (in pixels) where the icon is anchored to the map + */ + default void setIcon(String iconAddress, int anchorX, int anchorY) { + setIcon(iconAddress, new Vector2i(anchorX, anchorY)); + } + + /** + * Sets the icon for this {@link POIMarker}. + * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. You can also use an address returned by {@link BlueMapAPI#createImage(java.awt.image.BufferedImage, String)}. + * @param anchor the position of the position (in pixels) where the icon is anchored to the map + */ + void setIcon(String iconAddress, Vector2i anchor); - /** - * Sets the icon for this {@link POIMarker}. - * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. You can also use an address returned by {@link BlueMapAPI#createImage(java.awt.image.BufferedImage, String)}. - * @param anchorX the x-position of the position (in pixels) where the icon is anchored to the map - * @param anchorY the y-position of the position (in pixels) where the icon is anchored to the map - */ - default void setIcon(String iconAddress, int anchorX, int anchorY) { - setIcon(iconAddress, new Vector2i(anchorX, anchorY)); - } - - /** - * Sets the icon for this {@link POIMarker}. - * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. You can also use an address returned by {@link BlueMapAPI#createImage(java.awt.image.BufferedImage, String)}. - * @param anchor the position of the position (in pixels) where the icon is anchored to the map - */ - void setIcon(String iconAddress, Vector2i anchor); - } diff --git a/src/main/java/de/bluecolored/bluemap/api/marker/Shape.java b/src/main/java/de/bluecolored/bluemap/api/marker/Shape.java index ec77eb9..3173ea0 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/Shape.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/Shape.java @@ -33,153 +33,153 @@ */ public class Shape { - private final Vector2d[] points; - private Vector2d min = null; - private Vector2d max = null; - - public Shape(Vector2d... points) { - if (points.length < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!"); - - this.points = points; - } - - /** - * Getter for the amount of points in this shape. - * @return the amount of points - */ - public int getPointCount() { - return points.length; - } - - public Vector2d getPoint(int i) { - return points[i]; - } - - /** - * Getter for a copy of the points array.
- * (A shape is immutable once created) - * @return the points of this shape - */ - public Vector2d[] getPoints() { - return Arrays.copyOf(points, points.length); - } - - /** - * Calculates and returns the minimum corner of the axis-aligned-bounding-box of this shape. - * @return the min of the AABB of this shape - */ - public Vector2d getMin() { - if (this.min == null) { - Vector2d min = points[0]; - for (int i = 1; i < points.length; i++) { - min = min.min(points[i]); - } - this.min = min; - } - return this.min; - } - - /** - * Calculates and returns the maximum corner of the axis-aligned-bounding-box of this shape. - * @return the max of the AABB of this shape - */ - public Vector2d getMax() { - if (this.max == null) { - Vector2d max = points[0]; - for (int i = 1; i < points.length; i++) { - max = max.max(points[i]); - } - this.max = max; - } - return this.max; - } + private final Vector2d[] points; + private Vector2d min = null; + private Vector2d max = null; + + public Shape(Vector2d... points) { + if (points.length < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!"); + + this.points = points; + } + + /** + * Getter for the amount of points in this shape. + * @return the amount of points + */ + public int getPointCount() { + return points.length; + } + + public Vector2d getPoint(int i) { + return points[i]; + } + + /** + * Getter for a copy of the points array.
+ * (A shape is immutable once created) + * @return the points of this shape + */ + public Vector2d[] getPoints() { + return Arrays.copyOf(points, points.length); + } + + /** + * Calculates and returns the minimum corner of the axis-aligned-bounding-box of this shape. + * @return the min of the AABB of this shape + */ + public Vector2d getMin() { + if (this.min == null) { + Vector2d min = points[0]; + for (int i = 1; i < points.length; i++) { + min = min.min(points[i]); + } + this.min = min; + } + return this.min; + } + + /** + * Calculates and returns the maximum corner of the axis-aligned-bounding-box of this shape. + * @return the max of the AABB of this shape + */ + public Vector2d getMax() { + if (this.max == null) { + Vector2d max = points[0]; + for (int i = 1; i < points.length; i++) { + max = max.max(points[i]); + } + this.max = max; + } + return this.max; + } + + /** + * Creates a {@link Shape} representing a rectangle spanning over pos1 and pos2 + * @param pos1 one corner of the rectangle + * @param pos2 the opposite corner of the rectangle + * @return the created {@link Shape} + */ + public static Shape createRect(Vector2d pos1, Vector2d pos2) { + Vector2d min = pos1.min(pos2); + Vector2d max = pos1.max(pos2); + + return new Shape( + min, + new Vector2d(max.getX(), min.getY()), + max, + new Vector2d(min.getX(), max.getY()) + ); + } + + /** + * Creates a {@link Shape} representing a rectangle spanning over two points + * @param x1 x position of one corner of the rectangle + * @param y1 y position of one corner of the rectangle + * @param x2 x position of the opposite corner of the rectangle + * @param y2 y position of the opposite corner of the rectangle + * @return the created {@link Shape} + */ + public static Shape createRect(double x1, double y1, double x2, double y2) { + return createRect(new Vector2d(x1, y1), new Vector2d(x2, y2)); + } + + /** + * Creates a {@link Shape} representing an ellipse. + * @param centerPos the center of the ellipse + * @param radiusX the x radius of the ellipse + * @param radiusY the y radius of the ellipse + * @param points the amount of points used to create the ellipse (at least 3) + * @return the created {@link Shape} + */ + public static Shape createEllipse(Vector2d centerPos, double radiusX, double radiusY, int points) { + if (points < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!"); + + Vector2d[] pointArray = new Vector2d[points]; + double segmentAngle = 2 * Math.PI / points; + double angle = 0d; + for (int i = 0; i < points; i++) { + pointArray[i] = centerPos.add(Math.sin(angle) * radiusX, Math.cos(angle) * radiusY); + angle += segmentAngle; + } + + return new Shape(pointArray); + } + + /** + * Creates a {@link Shape} representing an ellipse. + * @param centerX the x-position of the center of the ellipse + * @param centerY the y-position of the center of the ellipse + * @param radiusX the x radius of the ellipse + * @param radiusY the y radius of the ellipse + * @param points the amount of points used to create the ellipse (at least 3) + * @return the created {@link Shape} + */ + public static Shape createEllipse(double centerX, double centerY, double radiusX, double radiusY, int points) { + return createEllipse(new Vector2d(centerX, centerY), radiusX, radiusY, points); + } + + /** + * Creates a {@link Shape} representing a circle. + * @param centerPos the center of the circle + * @param radius the radius of the circle + * @param points the amount of points used to create the circle (at least 3) + * @return the created {@link Shape} + */ + public static Shape createCircle(Vector2d centerPos, double radius, int points) { + return createEllipse(centerPos, radius, radius, points); + } + + /** + * Creates a {@link Shape} representing a circle. + * @param centerX the x-position of the center of the circle + * @param centerY the y-position of the center of the circle + * @param radius the radius of the circle + * @param points the amount of points used to create the circle (at least 3) + * @return the created {@link Shape} + */ + public static Shape createCircle(double centerX, double centerY, double radius, int points) { + return createCircle(new Vector2d(centerX, centerY), radius, points); + } - /** - * Creates a {@link Shape} representing a rectangle spanning over pos1 and pos2 - * @param pos1 one corner of the rectangle - * @param pos2 the opposite corner of the rectangle - * @return the created {@link Shape} - */ - public static Shape createRect(Vector2d pos1, Vector2d pos2) { - Vector2d min = pos1.min(pos2); - Vector2d max = pos1.max(pos2); - - return new Shape( - min, - new Vector2d(max.getX(), min.getY()), - max, - new Vector2d(min.getX(), max.getY()) - ); - } - - /** - * Creates a {@link Shape} representing a rectangle spanning over two points - * @param x1 x position of one corner of the rectangle - * @param y1 y position of one corner of the rectangle - * @param x2 x position of the opposite corner of the rectangle - * @param y2 y position of the opposite corner of the rectangle - * @return the created {@link Shape} - */ - public static Shape createRect(double x1, double y1, double x2, double y2) { - return createRect(new Vector2d(x1, y1), new Vector2d(x2, y2)); - } - - /** - * Creates a {@link Shape} representing an ellipse. - * @param centerPos the center of the ellipse - * @param radiusX the x radius of the ellipse - * @param radiusY the y radius of the ellipse - * @param points the amount of points used to create the ellipse (at least 3) - * @return the created {@link Shape} - */ - public static Shape createEllipse(Vector2d centerPos, double radiusX, double radiusY, int points) { - if (points < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!"); - - Vector2d[] pointArray = new Vector2d[points]; - double segmentAngle = 2 * Math.PI / points; - double angle = 0d; - for (int i = 0; i < points; i++) { - pointArray[i] = centerPos.add(Math.sin(angle) * radiusX, Math.cos(angle) * radiusY); - angle += segmentAngle; - } - - return new Shape(pointArray); - } - - /** - * Creates a {@link Shape} representing an ellipse. - * @param centerX the x-position of the center of the ellipse - * @param centerY the y-position of the center of the ellipse - * @param radiusX the x radius of the ellipse - * @param radiusY the y radius of the ellipse - * @param points the amount of points used to create the ellipse (at least 3) - * @return the created {@link Shape} - */ - public static Shape createEllipse(double centerX, double centerY, double radiusX, double radiusY, int points) { - return createEllipse(new Vector2d(centerX, centerY), radiusX, radiusY, points); - } - - /** - * Creates a {@link Shape} representing a circle. - * @param centerPos the center of the circle - * @param radius the radius of the circle - * @param points the amount of points used to create the circle (at least 3) - * @return the created {@link Shape} - */ - public static Shape createCircle(Vector2d centerPos, double radius, int points) { - return createEllipse(centerPos, radius, radius, points); - } - - /** - * Creates a {@link Shape} representing a circle. - * @param centerX the x-position of the center of the circle - * @param centerY the y-position of the center of the circle - * @param radius the radius of the circle - * @param points the amount of points used to create the circle (at least 3) - * @return the created {@link Shape} - */ - public static Shape createCircle(double centerX, double centerY, double radius, int points) { - return createCircle(new Vector2d(centerX, centerY), radius, points); - } - } 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 0f708fd..75dcabf 100644 --- a/src/main/java/de/bluecolored/bluemap/api/marker/ShapeMarker.java +++ b/src/main/java/de/bluecolored/bluemap/api/marker/ShapeMarker.java @@ -28,112 +28,112 @@ public interface ShapeMarker extends ObjectMarker, DistanceRangedMarker { - /** - * Getter for {@link Shape} of this {@link ShapeMarker}. - *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points are the z-coordinates in the map.

- * @return the {@link Shape} - */ - Shape getShape(); - - /** - * Getter for the height (y-coordinate) of where the shape is displayed on the map. - * @return the height of the shape on the map - * @deprecated Use {@link #getShapeY()} instead - */ - default float getHeight() { - return getShapeY(); - } + /** + * Getter for {@link Shape} of this {@link ShapeMarker}. + *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points are the z-coordinates in the map.

+ * @return the {@link Shape} + */ + Shape getShape(); - /** - * Getter for the height (y-coordinate) of where the shape is displayed on the map. - * @return the height of the shape on the map - */ - float getShapeY(); - - /** - * Sets the {@link Shape} of this {@link ShapeMarker}. - *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points will be the z-coordinates in the map.

- * @param shape the new {@link Shape} - * @param y the new height (y-coordinate) of the shape on the map - */ - void setShape(Shape shape, float y); + /** + * Getter for the height (y-coordinate) of where the shape is displayed on the map. + * @return the height of the shape on the map + * @deprecated Use {@link #getShapeY()} instead + */ + default float getHeight() { + return getShapeY(); + } - /** - * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. - * @return true if the depthTest is enabled - */ - boolean isDepthTestEnabled(); - - /** - * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. - * @param enabled if the depth-test should be enabled for this {@link ShapeMarker} - */ - void setDepthTestEnabled(boolean enabled); + /** + * Getter for the height (y-coordinate) of where the shape is displayed on the map. + * @return the height of the shape on the map + */ + float getShapeY(); - /** - * Getter for the width of the border-line of this {@link ShapeMarker}. - * @return the width of the line in pixels - */ - int getLineWidth(); + /** + * Sets the {@link Shape} of this {@link ShapeMarker}. + *

The shape is placed on the xz-plane of the map, so the y-coordinates of the {@link Shape}'s points will be the z-coordinates in the map.

+ * @param shape the new {@link Shape} + * @param y the new height (y-coordinate) of the shape on the map + */ + void setShape(Shape shape, float y); - /** - * Sets the width of the border-line for this {@link ShapeMarker}. - * @param width the new width in pixels - */ - void setLineWidth(int width); + /** + * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. + * @return true if the depthTest is enabled + */ + boolean isDepthTestEnabled(); - /** - * Getter for the {@link Color} of the border of the shape. - * @return the border-color - * @deprecated Use {@link #getLineColor()} instead - */ - default Color getBorderColor() { - return getLineColor(); - } - - /** - * Sets the {@link Color} of the border of the shape. - * @param color the new border-color - * @deprecated Use {@link #setLineColor(Color)} instead - */ - default void setBorderColor(Color color){ - setLineColor(color); - } + /** + * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, you'll only see the marker when it is not behind anything. + * @param enabled if the depth-test should be enabled for this {@link ShapeMarker} + */ + void setDepthTestEnabled(boolean enabled); - /** - * Getter for the {@link Color} of the border-line of the shape. - * @return the line-color - */ - Color getLineColor(); + /** + * Getter for the width of the border-line of this {@link ShapeMarker}. + * @return the width of the line in pixels + */ + int getLineWidth(); - /** - * Sets the {@link Color} of the border-line of the shape. - * @param color the new line-color - */ - void setLineColor(Color color); + /** + * Sets the width of the border-line for this {@link ShapeMarker}. + * @param width the new width in pixels + */ + void setLineWidth(int width); + + /** + * Getter for the {@link Color} of the border of the shape. + * @return the border-color + * @deprecated Use {@link #getLineColor()} instead + */ + default Color getBorderColor() { + return getLineColor(); + } + + /** + * Sets the {@link Color} of the border of the shape. + * @param color the new border-color + * @deprecated Use {@link #setLineColor(Color)} instead + */ + default void setBorderColor(Color color){ + setLineColor(color); + } + + /** + * Getter for the {@link Color} of the border-line of the shape. + * @return the line-color + */ + Color getLineColor(); + + /** + * Sets the {@link Color} of the border-line of the shape. + * @param color the new line-color + */ + void setLineColor(Color color); + + /** + * Getter for the fill-{@link Color} of the shape. + * @return the fill-color + */ + Color getFillColor(); + + /** + * Sets the fill-{@link Color} of the shape. + * @param color the new fill-color + */ + void setFillColor(Color color); + + /** + * Sets the border- and fill- color. + * @param lineColor the new border-color + * @param fillColor the new fill-color + * @see #setLineColor(Color) + * @see #setFillColor(Color) + */ + default void setColors(Color lineColor, Color fillColor) { + setLineColor(lineColor); + setFillColor(fillColor); + } - /** - * Getter for the fill-{@link Color} of the shape. - * @return the fill-color - */ - Color getFillColor(); - - /** - * Sets the fill-{@link Color} of the shape. - * @param color the new fill-color - */ - void setFillColor(Color color); - - /** - * Sets the border- and fill- color. - * @param lineColor the new border-color - * @param fillColor the new fill-color - * @see #setLineColor(Color) - * @see #setFillColor(Color) - */ - default void setColors(Color lineColor, Color fillColor) { - setLineColor(lineColor); - setFillColor(fillColor); - } - } diff --git a/src/main/java/de/bluecolored/bluemap/api/renderer/RenderAPI.java b/src/main/java/de/bluecolored/bluemap/api/renderer/RenderAPI.java index e860cc3..060b9b1 100644 --- a/src/main/java/de/bluecolored/bluemap/api/renderer/RenderAPI.java +++ b/src/main/java/de/bluecolored/bluemap/api/renderer/RenderAPI.java @@ -38,140 +38,140 @@ */ public interface RenderAPI { - /** - * Schedules the render of the map-tile at this block position for all maps of this world.
- * If there already is a render scheduled for one of the tiles, a second one will not be created. - * - * @param world the {@link UUID} of the {@link BlueMapWorld} to render - * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tiles will be rendered not only that block) - * - * @throws IllegalArgumentException if there is no world loaded with the provided {@link UUID} - */ - @Deprecated - void render(UUID world, Vector3i blockPosition); + /** + * Schedules the render of the map-tile at this block position for all maps of this world.
+ * If there already is a render scheduled for one of the tiles, a second one will not be created. + * + * @param world the {@link UUID} of the {@link BlueMapWorld} to render + * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tiles will be rendered not only that block) + * + * @throws IllegalArgumentException if there is no world loaded with the provided {@link UUID} + */ + @Deprecated + void render(UUID world, Vector3i blockPosition); - /** - * Schedules the render of the map-tile at this block position for all maps of this world.
- * If there already is a render scheduled for one of the tiles, a second one will not be created. - * - * @param world the {@link BlueMapWorld} to render - * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tiles will be rendered not only that block) - */ - @Deprecated - default void render(BlueMapWorld world, Vector3i blockPosition) { - for (BlueMapMap map : world.getMaps()) { - render(map, blockPosition); - } - } + /** + * Schedules the render of the map-tile at this block position for all maps of this world.
+ * If there already is a render scheduled for one of the tiles, a second one will not be created. + * + * @param world the {@link BlueMapWorld} to render + * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tiles will be rendered not only that block) + */ + @Deprecated + default void render(BlueMapWorld world, Vector3i blockPosition) { + for (BlueMapMap map : world.getMaps()) { + render(map, blockPosition); + } + } - /** - * Schedules the render of the map-tile at this block position.
- * If there already is a render scheduled for the tile, a second one will not be created. - * - * @param mapId the id of the {@link BlueMapMap} to render - * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tile will be rendered not only that block) - * - * @throws IllegalArgumentException if there is no map loaded with the provided mapId - */ - @Deprecated - void render(String mapId, Vector3i blockPosition); + /** + * Schedules the render of the map-tile at this block position.
+ * If there already is a render scheduled for the tile, a second one will not be created. + * + * @param mapId the id of the {@link BlueMapMap} to render + * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tile will be rendered not only that block) + * + * @throws IllegalArgumentException if there is no map loaded with the provided mapId + */ + @Deprecated + void render(String mapId, Vector3i blockPosition); - /** - * Schedules the render of map-tile at this block position and returns the created render-ticket.
- * If there already is a render scheduled for the tile, a second one will not be created. - * - * @param map the {@link BlueMapMap} - * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tile will be rendered not only that block) - */ - @Deprecated - default void render(BlueMapMap map, Vector3i blockPosition) { - render(map, map.posToTile(blockPosition)); - } - - /** - * Schedules the render of the map-tile.
- * If there already is a render scheduled for the tile, a second one will not be created. - * - * @param mapId the id of the {@link BlueMapMap} to render - * @param tile a {@link Vector2i} for the tile-position to render - * - * @throws IllegalArgumentException if there is no map loaded with the provided mapId - */ - @Deprecated - void render(String mapId, Vector2i tile); + /** + * Schedules the render of map-tile at this block position and returns the created render-ticket.
+ * If there already is a render scheduled for the tile, a second one will not be created. + * + * @param map the {@link BlueMapMap} + * @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tile will be rendered not only that block) + */ + @Deprecated + default void render(BlueMapMap map, Vector3i blockPosition) { + render(map, map.posToTile(blockPosition)); + } - /** - * Schedules the render of the map-tile.
- * If there already is a render scheduled for the tile, a second one will not be created. - * - * @param map the {@link BlueMapMap} - * @param tile a {@link Vector2i} for the tile-position to render - */ - @Deprecated - void render(BlueMapMap map, Vector2i tile); + /** + * Schedules the render of the map-tile.
+ * If there already is a render scheduled for the tile, a second one will not be created. + * + * @param mapId the id of the {@link BlueMapMap} to render + * @param tile a {@link Vector2i} for the tile-position to render + * + * @throws IllegalArgumentException if there is no map loaded with the provided mapId + */ + @Deprecated + void render(String mapId, Vector2i tile); - /** - * Schedules a task to update the given map. - * @param map the map to be updated - * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) - */ - default boolean scheduleMapUpdateTask(BlueMapMap map) { - return scheduleMapUpdateTask(map, false); - } + /** + * Schedules the render of the map-tile.
+ * If there already is a render scheduled for the tile, a second one will not be created. + * + * @param map the {@link BlueMapMap} + * @param tile a {@link Vector2i} for the tile-position to render + */ + @Deprecated + void render(BlueMapMap map, Vector2i tile); - /** - * Schedules a task to update the given map. - * @param map the map to be updated - * @param force it this is true, the task will forcefully re-render all tiles, even if there are no changes since the last map-update. - * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) - */ - boolean scheduleMapUpdateTask(BlueMapMap map, boolean force); + /** + * Schedules a task to update the given map. + * @param map the map to be updated + * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) + */ + default boolean scheduleMapUpdateTask(BlueMapMap map) { + return scheduleMapUpdateTask(map, false); + } - /** - * Schedules a task to update the given map. - * @param map the map to be updated - * @param regions The regions that should be updated ("region" refers to the coordinates of a minecraft region-file (32x32 chunks, 512x512 blocks))
- * BlueMaps updating-system works based on region-files. For this reason you can always only update a whole region-file at once. - * @param force it this is true, the task will forcefully re-render all tiles, even if there are no changes since the last map-update. - * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) - */ - boolean scheduleMapUpdateTask(BlueMapMap map, Collection regions, boolean force); + /** + * Schedules a task to update the given map. + * @param map the map to be updated + * @param force it this is true, the task will forcefully re-render all tiles, even if there are no changes since the last map-update. + * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) + */ + boolean scheduleMapUpdateTask(BlueMapMap map, boolean force); - /** - * Schedules a task to purge the given map. - * An update-task will be scheduled right after the purge, to get the map up-to-date again. - * @param map the map to be purged - * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) - * @throws IOException if an IOException occurs while trying to create the task. - */ - boolean scheduleMapPurgeTask(BlueMapMap map) throws IOException; + /** + * Schedules a task to update the given map. + * @param map the map to be updated + * @param regions The regions that should be updated ("region" refers to the coordinates of a minecraft region-file (32x32 chunks, 512x512 blocks))
+ * BlueMaps updating-system works based on region-files. For this reason you can always only update a whole region-file at once. + * @param force it this is true, the task will forcefully re-render all tiles, even if there are no changes since the last map-update. + * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) + */ + boolean scheduleMapUpdateTask(BlueMapMap map, Collection regions, boolean force); - /** - * Getter for the current size of the render-queue. - * @return the current size of the render-queue - */ - int renderQueueSize(); - - /** - * Getter for the count of render threads. - * @return the count of render threads - */ - int renderThreadCount(); - - /** - * Whether this {@link RenderAPI} is currently running or paused. - * @return true if this renderer is running - */ - boolean isRunning(); - - /** - * Starts the renderer if it is not already running. - */ - void start(); + /** + * Schedules a task to purge the given map. + * An update-task will be scheduled right after the purge, to get the map up-to-date again. + * @param map the map to be purged + * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) + * @throws IOException if an IOException occurs while trying to create the task. + */ + boolean scheduleMapPurgeTask(BlueMapMap map) throws IOException; + + /** + * Getter for the current size of the render-queue. + * @return the current size of the render-queue + */ + int renderQueueSize(); + + /** + * Getter for the count of render threads. + * @return the count of render threads + */ + int renderThreadCount(); + + /** + * Whether this {@link RenderAPI} is currently running or paused. + * @return true if this renderer is running + */ + boolean isRunning(); + + /** + * Starts the renderer if it is not already running. + */ + void start(); + + /** + * Pauses the renderer if it currently is running. + */ + void pause(); - /** - * Pauses the renderer if it currently is running. - */ - void pause(); - }