Compare commits

...

38 Commits

Author SHA1 Message Date
Lukas Rieger (Blue) ec97711349
Tidy up 2024-05-20 21:24:31 +02:00
Lukas Rieger (Blue) 8b179fb5e0
Deprecate/remove DebugDump annotation 2024-05-15 23:46:25 +02:00
Lukas Rieger (Blue) 6c84500dfc
Update gradle 2024-05-08 18:06:38 +02:00
Lukas Rieger (Blue) b200d339f1
Publish on tag 2024-04-04 00:19:54 +02:00
Lukas Rieger (Blue) 030f29e7f3
Change project group 2024-04-03 23:02:41 +02:00
Lukas Rieger (Blue) f5709ce836
Fix credentials problems 2024-04-03 22:55:28 +02:00
Lukas Rieger (Blue) 9d37bdeb15
Fix workflow syntax 2024-04-03 22:46:53 +02:00
Lukas Rieger (Blue) baeef5994e
Publish to BlueColored Maven Repo 2024-04-03 22:45:31 +02:00
Lukas Rieger (Blue) e7e32301f2
Require Java 16 2024-04-03 21:58:13 +02:00
TechnicJelle 6cad751ac5
Link javadocs to FlowPoweredMath & GSON (#6)
* Link javadocs to FlowPoweredMath & GSON

* Update build.gradle.kts
2024-02-20 01:15:43 +01:00
Lukas Rieger (Blue) c7a9be42ad
Fix Javadoc 2024-02-07 20:49:31 +01:00
Lukas Rieger (Blue) dcae50572a
Merge branch 'master' of https://github.com/BlueMap-Minecraft/BlueMapAPI 2024-02-07 20:45:54 +01:00
Lukas Rieger (Blue) c3ce6d95de
Deprecate BlueMapWorld#getSaveFolder() 2024-02-07 20:45:28 +01:00
Takase 9ed7fdb1cf
Reduce marker coordinates precision (#5) 2024-02-03 12:08:46 +01:00
Lukas Rieger (Blue) 5c3624832f
Update gradle and action 2023-09-27 23:50:42 +02:00
Lukas Rieger (Blue) 2cdc5c8a87
Fix Shape label not being empty by default 2023-08-20 08:24:18 +02:00
Lukas Rieger (Blue) f398e7ab2b
Make addPoints in Shape and List accept a collection of points as well 2023-07-15 12:31:34 +02:00
Lukas Rieger (Blue) 7776c8e979
Implement toString() for Color class 2023-07-15 12:29:05 +02:00
Lukas Rieger (Blue) 40140f87c6
Fix javadoc errors 2023-06-26 16:38:59 +02:00
Lukas Rieger (Blue) f44fd20f5f
Add sources and javadoc jar to publish 2023-06-26 16:31:44 +02:00
Lukas Rieger (Blue) 85e3763d7a
Add enable/disable consumer invocation order guarantee 2023-05-02 21:29:10 +02:00
Lukas Rieger (Blue) 812e4b8fce
Add abillity to remove markers from the marker list while keeping them on the map 2023-02-07 19:43:15 +01:00
Lukas Rieger (Blue) 2a3cc1c270
Make builder value private 2023-02-07 17:06:28 +01:00
Lukas Rieger (Blue) bee8770fde
Add sorting option to Marker and MarkerSet 2023-02-07 17:04:38 +01:00
Lukas Rieger (Blue) 1d0d63f088
Use the original value in the error 2023-02-07 11:08:35 +01:00
Lukas Rieger (Blue) f9bbdc3d38
Add invalid value to color-format exception 2023-02-07 11:03:21 +01:00
Lukas Rieger (Blue) c70ab29ae8
Fix javadoc errors 2023-01-02 22:42:50 +01:00
Lukas Rieger (Blue) ad77b492dd
Add methods to add holes to shape and extrude markers 2022-12-29 17:39:28 +01:00
Lukas Rieger (Blue) 942cec6571
Fix style-classes not being applied by the builder 2022-12-16 12:37:59 +01:00
Lukas Rieger (Blue) 51d04e8135
Fix Marker-position setters taking ints instead of doubles 2022-12-13 23:45:45 +01:00
Lukas Rieger (Blue) 3e9c7dd72c
And apply spotless-fixes .. again 2022-12-13 21:57:06 +01:00
Lukas Rieger (Blue) abd5756609
Add the abillity to add css-classes to POI and HTML-Markers and add detail field to the POI-Marker 2022-12-13 21:54:16 +01:00
Lukas Rieger (Blue) 5b4093e404
Apply süpotless fixes 2022-12-12 21:16:16 +01:00
Lukas Rieger (Blue) 4cf0629e52
Add methods to control player-skin API and PlayerMarker-Icon generation 2022-12-12 21:13:46 +01:00
Lukas Rieger (Blue) 6b78d0d433
Make documentation-wording more clear 2022-12-03 23:21:30 +01:00
Lukas Rieger (Blue) 99e43dd19b
Add methods to register script and style files 2022-12-03 23:16:01 +01:00
Lukas Rieger (Blue) f063dc7fc2
Add missing file-headers 2022-12-02 15:46:38 +01:00
Lukas Rieger (Blue) a105baf81a
Add AssetStorage and deprecate the old way of managing marker-images 2022-12-02 15:42:54 +01:00
30 changed files with 1155 additions and 202 deletions

View File

@ -10,10 +10,12 @@ jobs:
with:
submodules: recursive
fetch-depth: 0 # needed for versioning
- name: Set up Java 11
uses: actions/setup-java@v1
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: 16
cache: 'gradle'
- name: Build with Gradle
run: ./gradlew clean build test
- uses: actions/upload-artifact@v2-preview

27
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,27 @@
name: Publish
on:
workflow_dispatch:
push:
tags:
- '**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0 # needed for versioning
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 16
cache: 'gradle'
- name: Build with Gradle
run: ./gradlew publish
env:
BLUECOLORED_USERNAME: ${{ secrets.BLUECOLORED_USERNAME }}
BLUECOLORED_PASSWORD: ${{ secrets.BLUECOLORED_PASSWORD }}

View File

@ -1,4 +1,5 @@
import java.io.IOException
import java.util.concurrent.TimeoutException
plugins {
java
@ -12,7 +13,11 @@ fun String.runCommand(): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`]
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
.apply { waitFor(60, TimeUnit.SECONDS) }
.apply {
if (!waitFor(10, TimeUnit.SECONDS)) {
throw TimeoutException("Failed to execute command: '" + this@runCommand + "'")
}
}
.run {
val error = errorStream.bufferedReader().readText().trim()
if (error.isNotEmpty()) {
@ -28,17 +33,20 @@ val lastVersion = lastTag.substring(1) // remove the leading 'v'
val commits = "git rev-list --count $lastTag..HEAD".runCommand()
println("Git hash: $gitHash" + if (clean) "" else " (dirty)")
group = "de.bluecolored.bluemap.api"
group = "de.bluecolored.bluemap"
version = lastVersion +
(if (commits == "0") "" else "-$commits") +
(if (clean) "" else "-dirty")
println("Version: $version")
val javaTarget = 11
val javaTarget = 16
java {
sourceCompatibility = JavaVersion.toVersion(javaTarget)
targetCompatibility = JavaVersion.toVersion(javaTarget)
withSourcesJar()
withJavadocJar()
}
repositories {
@ -77,8 +85,12 @@ tasks.javadoc {
options {
(this as? StandardJavadocDocletOptions)?.apply {
links(
"https://docs.oracle.com/javase/8/docs/api/"
"https://docs.oracle.com/en/java/javase/16/docs/api/",
"https://javadoc.io/doc/com.flowpowered/flow-math/1.0.3/",
"https://javadoc.io/doc/com.google.code.gson/gson/2.8.0/",
)
addStringOption("Xdoclint:none", "-quiet")
addBooleanOption("html5", true)
}
}
}
@ -96,6 +108,20 @@ tasks.processResources {
}
publishing {
repositories {
maven {
name = "bluecolored"
val releasesRepoUrl = "https://repo.bluecolored.de/releases"
val snapshotsRepoUrl = "https://repo.bluecolored.de/snapshots"
url = uri(if (version == lastVersion) releasesRepoUrl else snapshotsRepoUrl)
credentials {
username = project.findProperty("bluecoloredUsername") as String? ?: System.getenv("BLUECOLORED_USERNAME")
password = project.findProperty("bluecoloredPassword") as String? ?: System.getenv("BLUECOLORED_PASSWORD")
}
}
}
publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -0,0 +1,106 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.api;
import de.bluecolored.bluemap.api.markers.POIMarker;
import de.bluecolored.bluemap.api.markers.HtmlMarker;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
/**
* A storage that is able to hold any "asset"-data for a map. For example images, icons, scripts or json-files.
*/
@SuppressWarnings("unused")
public interface AssetStorage {
/**
* Writes a new asset into this storage, overwriting any existent assets with the same name.<br>
* Use the returned {@link OutputStream} to write the asset-data. The asset will be added to the storage as soon as that stream
* gets closed!<br>
* <br>
* Example:
* <pre>
* try (OutputStream out = assetStorage.writeAsset("image.png")) {
* ImageIO.write(image, "png", out);
* }
* </pre>
* @param name The (unique) name for this asset
* @return An {@link OutputStream} that should be used to write the asset and closed once!
* @throws IOException when the underlying storage rises an IOException
*/
OutputStream writeAsset(String name) throws IOException;
/**
* Reads an asset from this storage.<br>
* Use the returned {@link InputStream} to read the asset-data.<br>
* <br>
* Example:
* <pre>
* Optional&lt;InputStream&gt; optIn = assetStorage.readAsset("image.png");
* if (optIn.isPresent()) {
* try (InputStream in = optIn.get()) {
* BufferedImage image = ImageIO.read(in);
* }
* }
* </pre>
* @param name The name of the asset that should be read from the storage.
* @return An {@link Optional} with an {@link InputStream} when the asset is found, from which the asset can be read.
* Or an empty optional if there is no asset with this name.
* @throws IOException when the underlying storage rises an IOException
*/
Optional<InputStream> readAsset(String name) throws IOException;
/**
* Checks if an asset exists in this storage without reading it.<br>
* This is useful if the asset has a lot of data and using {@link #readAsset(String)}
* just to check if the asset is present would be wasteful.
* @param name The name of the asset to check for
* @return <code>true</code> if the asset is found, <code>false</code> if not
* @throws IOException when the underlying storage rises an IOException
*/
boolean assetExists(String name) throws IOException;
/**
* Returns the relative URL that can be used by the webapp to request this asset.<br>
* This is the url that you can e.g. use in {@link POIMarker}s or {@link HtmlMarker}s to add an icon.<br>
* If there is no asset with this name, then this method returns the URL that an asset with such a name <i>would</i>
* have if it would be added later.
* @param name The name of the asset
* @return The relative URL for an asset with the given name
*/
String getAssetUrl(String name);
/**
* Deletes the asset with the given name from this storage, if it exists.<br>
* If there is no asset with this name, this method does nothing.
* @param name The name of the asset that should be deleted
* @throws IOException when the underlying storage rises an IOException
*/
void deleteAsset(String name) throws IOException;
}

View File

@ -27,7 +27,8 @@ package de.bluecolored.bluemap.api;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.plugin.Plugin;
import org.jetbrains.annotations.ApiStatus;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -42,6 +43,7 @@ import java.util.function.Consumer;
* An API to control the running instance of BlueMap.
* <p>This API is thread-save, so you <b>can</b> use it async, off the main-server-thread, to save performance!</p>
*/
@SuppressWarnings({"unused", "UnusedReturnValue"})
public abstract class BlueMapAPI {
@SuppressWarnings("unused")
@ -57,6 +59,7 @@ public abstract class BlueMapAPI {
gitHash = element.get("git-hash").getAsString();
} catch (Exception ex) {
System.err.println("Failed to load version from resources!");
//noinspection CallToPrintStackTrace
ex.printStackTrace();
}
}
@ -70,35 +73,37 @@ public abstract class BlueMapAPI {
private static BlueMapAPI instance;
private static final Collection<Consumer<BlueMapAPI>> onEnableConsumers = new HashSet<>(2);
private static final Collection<Consumer<BlueMapAPI>> onDisableConsumers = new HashSet<>(2);
private static final LinkedHashSet<Consumer<BlueMapAPI>> onEnableConsumers = new LinkedHashSet<>();
private static final LinkedHashSet<Consumer<BlueMapAPI>> onDisableConsumers = new LinkedHashSet<>();
/**
* Getter for the {@link RenderManager}.
* @return the {@link RenderManager}
*/
@DebugDump
public abstract RenderManager getRenderManager();
/**
* Getter for the {@link WebApp}.
* @return the {@link WebApp}
*/
@DebugDump
public abstract WebApp getWebApp();
/**
* Getter for the {@link Plugin}
* @return the {@link Plugin}
*/
public abstract Plugin getPlugin();
/**
* Getter for all {@link BlueMapMap}s loaded by BlueMap.
* @return an unmodifiable collection of all loaded {@link BlueMapMap}s
*/
@DebugDump
public abstract Collection<BlueMapMap> getMaps();
/**
* Getter for all {@link BlueMapWorld}s loaded by BlueMap.
* @return an unmodifiable collection of all loaded {@link BlueMapWorld}s
*/
@DebugDump
public abstract Collection<BlueMapWorld> getWorlds();
/**
@ -129,14 +134,12 @@ public abstract class BlueMapAPI {
* Getter for the installed BlueMap version
* @return the version-string
*/
@DebugDump
public abstract String getBlueMapVersion();
/**
* Getter for the installed BlueMapAPI version
* @return the version-string
*/
@DebugDump
public String getAPIVersion() {
return VERSION;
}
@ -155,6 +158,7 @@ public abstract class BlueMapAPI {
* <p><b>The {@link Consumer} can be called multiple times if BlueMap disables and enables again, e.g. if BlueMap gets reloaded!</b></p>
* <p><i>(Note: The consumer will likely be called asynchronously, <b>not</b> on the server-thread!)</i></p>
* <p>Remember to unregister the consumer when you no longer need it using {@link #unregisterListener(Consumer)}.</p>
* <p>The {@link Consumer}s are guaranteed to be called in the order they were registered in.</p>
* @param consumer the {@link Consumer}
*/
public static synchronized void onEnable(Consumer<BlueMapAPI> consumer) {
@ -168,6 +172,7 @@ public abstract class BlueMapAPI {
* <p><b>The {@link Consumer} can be called multiple times if BlueMap disables and enables again, e.g. if BlueMap gets reloaded!</b></p>
* <p><i>(Note: The consumer will likely be called asynchronously, <b>not</b> on the server-thread!)</i></p>
* <p>Remember to unregister the consumer when you no longer need it using {@link #unregisterListener(Consumer)}.</p>
* <p>The {@link Consumer}s are guaranteed to be called in the order they were registered in.</p>
* @param consumer the {@link Consumer}
*/
public static synchronized void onDisable(Consumer<BlueMapAPI> consumer) {
@ -189,39 +194,33 @@ public abstract class BlueMapAPI {
* @return <code>true</code> if the instance has been registered, <code>false</code> if there already was an instance registered
* @throws ExecutionException if a listener threw an exception during the registration
*/
protected static synchronized boolean registerInstance(BlueMapAPI instance) throws ExecutionException {
@ApiStatus.Internal
protected static synchronized boolean registerInstance(BlueMapAPI instance) throws Exception {
if (BlueMapAPI.instance != null) return false;
BlueMapAPI.instance = instance;
List<Throwable> thrownExceptions = new ArrayList<>(0);
List<Exception> thrownExceptions = new ArrayList<>(0);
for (Consumer<BlueMapAPI> listener : BlueMapAPI.onEnableConsumers) {
try {
listener.accept(BlueMapAPI.instance);
} catch (Throwable ex) {
} catch (Exception 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;
return throwAsOne(thrownExceptions);
}
/**
* Used by BlueMap to unregister the API and call the listeners properly.
* @param instance the {@link BlueMapAPI} instance
* @return <code>true</code> if the instance was unregistered, <code>false</code> if there was no or an other instance registered
* @return <code>true</code> if the instance was unregistered, <code>false</code> if there was no or another instance registered
* @throws ExecutionException if a listener threw an exception during the un-registration
*/
protected static synchronized boolean unregisterInstance(BlueMapAPI instance) throws ExecutionException {
@ApiStatus.Internal
protected static synchronized boolean unregisterInstance(BlueMapAPI instance) throws Exception {
if (BlueMapAPI.instance != instance) return false;
List<Exception> thrownExceptions = new ArrayList<>(0);
@ -236,8 +235,12 @@ public abstract class BlueMapAPI {
BlueMapAPI.instance = null;
return throwAsOne(thrownExceptions);
}
private static boolean throwAsOne(List<Exception> thrownExceptions) throws Exception {
if (!thrownExceptions.isEmpty()) {
ExecutionException ex = new ExecutionException(thrownExceptions.get(0));
Exception ex = thrownExceptions.get(0);
for (int i = 1; i < thrownExceptions.size(); i++) {
ex.addSuppressed(thrownExceptions.get(i));
}

View File

@ -27,8 +27,8 @@ package de.bluecolored.bluemap.api;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.markers.MarkerSet;
import org.jetbrains.annotations.ApiStatus;
import java.util.Map;
import java.util.function.Predicate;
@ -37,42 +37,46 @@ import java.util.function.Predicate;
* This class represents a map that is rendered by BlueMap of a specific world ({@link BlueMapWorld}).
* Each map belongs to a map configured in BlueMap's configuration file (in the <code>maps: []</code> list).
*/
@SuppressWarnings("unused")
public interface BlueMapMap {
/**
* Returns this maps id, this is equal to the id configured in bluemap's config for this map.
* @return the id of this map
*/
@DebugDump
String getId();
/**
* Returns this maps display-name, this is equal to the name configured in bluemap's config for this map.
* @return the name of this map
*/
@DebugDump
String getName();
/**
* Getter for the {@link BlueMapWorld} of this map.
* @return the {@link BlueMapWorld} of this map
*/
@DebugDump
BlueMapWorld getWorld();
/**
* Getter for this map's {@link AssetStorage}. <br>
* Each map has its own storage for assets. Assets that are stored here will be available to every webapp that
* is displaying this map. E.g. these assets are also available in server-networks.
* @return the {@link AssetStorage} of this map
*/
AssetStorage getAssetStorage();
/**
* Getter for a (modifiable) {@link Map} of {@link MarkerSet}s with the key being the {@link MarkerSet}'s id.
* Changing this map will change the {@link MarkerSet}s and markers displayed on the web-app for this map.
* @return a {@link Map} of {@link MarkerSet}s.
*/
@DebugDump
Map<String, MarkerSet> getMarkerSets();
/**
* Getter for the size of all tiles on this map in blocks.
* @return the tile-size in blocks
*/
@DebugDump
Vector2i getTileSize();
/**
@ -80,7 +84,6 @@ public interface BlueMapMap {
* E.g. an offset of (2|-1) would mean that the tile (0|0) has block (2|0|-1) at it's min-corner.
* @return the tile-offset in blocks
*/
@DebugDump
Vector2i getTileOffset();
/**
@ -90,6 +93,7 @@ public interface BlueMapMap {
* <p>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.</p>
* @param filter The filter that will be used from now on.
*/
@ApiStatus.Experimental
void setTileFilter(Predicate<Vector2i> filter);
/**
@ -106,8 +110,9 @@ public interface BlueMapMap {
boolean isFrozen();
/**
* Returns the currently set TileFilter. The default TileFilter is equivalent to <code>t -> true</code>.
* Returns the currently set TileFilter. The default TileFilter is equivalent to <code>t -&gt; true</code>.
*/
@ApiStatus.Experimental
Predicate<Vector2i> getTileFilter();
/**

View File

@ -24,8 +24,6 @@
*/
package de.bluecolored.bluemap.api;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.nio.file.Path;
import java.util.Collection;
@ -38,21 +36,21 @@ public interface BlueMapWorld {
* Getter for the id of this world.
* @return the id of this world
*/
@DebugDump
String getId();
/**
* Getter for the {@link Path} of this world's save-files (folder). This matches the folder configured in bluemap's config for this map ( <code>world:</code> ).
* Getter for the {@link Path} of this world's save-files.<br>
* (To be exact: the parent-folder of the regions-folder used for rendering)
* @return the save-folder of this world.
* @deprecated Getting the save-folder of a world is no longer supported. As it is not guaranteed that every world has a save-folder.
*/
@DebugDump
@Deprecated
Path getSaveFolder();
/**
* Getter for all {@link BlueMapMap}s for this world
* @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world
*/
@DebugDump
Collection<BlueMapMap> getMaps();
}

View File

@ -0,0 +1,121 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.api;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
/**
* This Content-Type registry is used by the internal webserver to get the content-type of an asset.<br>
* The most commonly used file-suffixes and their content-types are registered by default, but you can use the static
* methods of this class to add more, if you need them.<br>
* <b>Note:</b> that any additionally added types won't work if the user uses an external webserver to serve their map-files.
*/
public class ContentTypeRegistry {
private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
private static final Map<String, String> SUFFIX_MAP = new HashMap<>();
static {
register("txt", "text/plain");
register("css", "text/css");
register("csv", "text/csv");
register("htm", "text/html");
register("html", "text/html");
register("js", "text/javascript");
register("xml", "text/xml");
register("png", "image/png");
register("jpg", "image/jpeg");
register("jpeg", "image/jpeg");
register("gif", "image/gif");
register("webp", "image/webp");
register("tif", "image/tiff");
register("tiff", "image/tiff");
register("svg", "image/svg+xml");
register("json", "application/json");
register("mp3", "audio/mpeg");
register("oga", "audio/ogg");
register("wav", "audio/wav");
register("weba", "audio/webm");
register("mp4", "video/mp4");
register("mpeg", "video/mpeg");
register("webm", "video/webm");
register("ttf", "font/ttf");
register("woff", "font/woff");
register("woff2", "font/woff2");
}
/**
* Derives the content-type (mime) string using a path denoting a file
* @param path The path pointing at the file
* @return The derived content-type string
*/
public static String fromPath(Path path) {
return fromFileName(path.getFileName().toString());
}
/**
* Derives the content-type (mime) string from the name of a file
* @param fileName The name of the file
* @return The derived content-type string
*/
public static String fromFileName(String fileName) {
int i = fileName.lastIndexOf('.');
if (i < 0) return DEFAULT_CONTENT_TYPE;
int s = fileName.lastIndexOf('/');
if (i < s) return DEFAULT_CONTENT_TYPE;
String suffix = fileName.substring(i + 1);
return fromFileSuffix(suffix);
}
/**
* Searches and returns the content-type for the provided file-suffix.
* @param suffix The type-suffix of a file-name
* @return The content-type string
*/
public static String fromFileSuffix(String suffix) {
String contentType = SUFFIX_MAP.get(suffix);
if (contentType != null) return contentType;
return DEFAULT_CONTENT_TYPE;
}
/**
* Registers a new file-suffix =&gt; content-type mapping to this registry.
* @param fileSuffix The type-suffix of a file-name
* @param contentType The content-type string
*/
public static void register(String fileSuffix, String contentType) {
SUFFIX_MAP.put(fileSuffix, contentType);
}
}

View File

@ -25,14 +25,13 @@
package de.bluecolored.bluemap.api;
import com.flowpowered.math.vector.Vector2i;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.io.IOException;
import java.util.Collection;
/**
* The {@link RenderManager} is used to schedule tile-renders and process them on a number of different threads.
*/
@SuppressWarnings("unused")
public interface RenderManager {
/**
@ -67,29 +66,25 @@ public interface RenderManager {
* 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;
boolean scheduleMapPurgeTask(BlueMapMap map);
/**
* Getter for the current size of the render-queue.
* @return the current size of the render-queue
*/
@DebugDump
int renderQueueSize();
/**
* Getter for the current count of render threads.
* @return the count of render threads
*/
@DebugDump
int renderThreadCount();
/**
* Whether this {@link RenderManager} is currently running or stopped.
* @return <code>true</code> if this renderer is running
*/
@DebugDump
boolean isRunning();
/**

View File

@ -24,24 +24,22 @@
*/
package de.bluecolored.bluemap.api;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.markers.Marker;
import de.bluecolored.bluemap.api.markers.POIMarker;
import com.flowpowered.math.vector.Vector2i;
import org.jetbrains.annotations.ApiStatus;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
@SuppressWarnings("unused")
public interface WebApp {
/**
* Getter for the configured web-root folder
* @return The {@link Path} of the web-root folder
*/
@DebugDump
Path getWebRoot();
/**
@ -49,6 +47,7 @@ public interface WebApp {
* @param player the UUID of the player
* @param visible true if the player-marker should be visible, false if it should be hidden
*/
@ApiStatus.Experimental
void setPlayerVisibility(UUID player, boolean visible);
/**
@ -56,34 +55,59 @@ public interface WebApp {
* @see #setPlayerVisibility(UUID, boolean)
* @param player the UUID of the player
*/
@ApiStatus.Experimental
boolean getPlayerVisibility(UUID player);
/**
* 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).
*
* <p>The given <code>path</code> is used as file-name and (separated with '/') optional folders to organize the image-files.
* Do NOT include the file-ending! (e.g. <code>"someFolder/somePOIIcon"</code> will result in a file "somePOIIcon.png" in a folder "someFolder").</p>
* <p>If the image file with the given path already exists, it will be replaced.</p>
*
* @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 POIMarker#setIcon(String, Vector2i)} method
* @throws IOException If an {@link IOException} is thrown while writing the image
* Registers a css-style so the webapp loads it.<br>
* This method should only be used inside the {@link Consumer} that got registered <i>(before bluemap loaded,
* pre server-start!)</i> to {@link BlueMapAPI#onEnable(Consumer)}.<br>
* Invoking this method at any other time is not supported.<br>
* Style-registrations are <b>not persistent</b>, register your style each time bluemap enables!<br>
* <br>
* Example:
* <pre>
* BlueMapAPI.onEnable(api -&gt; {
* api.getWebApp().registerStyle("js/my-custom-style.css");
* });
* </pre>
* @param url The (relative) URL that links to the style.css file. The {@link #getWebRoot()}-method can be used to
* create the custom file in the correct location and make it available to the web-app.
*/
void registerStyle(String url);
/**
* Registers a js-script so the webapp loads it.<br>
* This method should only be used inside the {@link Consumer} that got registered <i>(before bluemap loaded,
* pre server-start!)</i> to {@link BlueMapAPI#onEnable(Consumer)}.<br>
* Invoking this method at any other time is not supported.<br>
* Script-registrations are <b>not persistent</b>, register your script each time bluemap enables!<br>
* <br>
* Example:
* <pre>
* BlueMapAPI.onEnable(api -&gt; {
* api.getWebApp().registerScript("js/my-custom-script.js");
* });
* </pre>
* @param url The (relative) URL that links to the script.js file. The {@link #getWebRoot()}-method can be used to
* create the custom file in the correct location and make it available to the web-app.
*/
void registerScript(String url);
// ------
/**
* @deprecated You should use the {@link #getWebRoot()} method to create the image-files you need, or store map/marker
* specific images in the map's storage (See: {@link BlueMapMap#getAssetStorage()})!
*/
@Deprecated(forRemoval = true)
String createImage(BufferedImage image, String path) throws IOException;
/**
* 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:
* <ul>
* <li>the <b>key</b> is the image path how it would be used in the "path" parameter of the {@link #createImage(BufferedImage, String)} method</li>
* <li>and the <b>value</b> is the relative address of the image. The same ones that are returned from the {@link #createImage(BufferedImage, String)} method</li>
* </ul>
* @throws IOException If an {@link IOException} is thrown while reading the images
* @deprecated You should use the {@link #getWebRoot()} method to find the image-files you need, or read map/marker
* specific images from the map's storage (See: {@link BlueMapMap#getAssetStorage()})!
*/
@DebugDump
@Deprecated(forRemoval = true)
Map<String, String> availableImages() throws IOException;
}

View File

@ -30,8 +30,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks a class, field or method to be included in detail in a possible state-dump.
* E.g. triggered by <code>/bluemap debug dump</code>
* @deprecated not implemented, unused
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({
@ -39,6 +38,7 @@ import java.lang.annotation.Target;
ElementType.FIELD,
ElementType.TYPE
})
@Deprecated(forRemoval = true)
public @interface DebugDump {
String value() default "";

View File

@ -49,8 +49,9 @@ public final class MarkerGson {
.setLenient()
.create();
/* This class can not be instantiated. */
private MarkerGson() {}
private MarkerGson() {
throw new UnsupportedOperationException("Utility class");
}
public static GsonBuilder addAdapters(GsonBuilder builder) {
return builder
@ -235,8 +236,8 @@ public final class MarkerGson {
}
out.beginObject();
out.name("x"); out.value(value.getX());
out.name(useZ ? "z" : "y"); out.value(value.getY());
out.name("x"); writeRounded(out, value.getX());
out.name(useZ ? "z" : "y"); writeRounded(out, value.getY());
out.endObject();
}
@ -262,6 +263,13 @@ public final class MarkerGson {
return new Vector2d(x, y);
}
private void writeRounded(JsonWriter json, double value) throws IOException {
// rounding and remove ".0" to save string space
double d = Math.round(value * 10000d) / 10000d;
if (d == (long) d) json.value((long) d);
else json.value(d);
}
}
static class Vector3dAdapter extends TypeAdapter<Vector3d> {
@ -274,9 +282,9 @@ public final class MarkerGson {
}
out.beginObject();
out.name("x"); out.value(value.getX());
out.name("y"); out.value(value.getY());
out.name("z"); out.value(value.getZ());
out.name("x"); writeRounded(out, value.getX());
out.name("y"); writeRounded(out, value.getY());
out.name("z"); writeRounded(out, value.getZ());
out.endObject();
}
@ -302,6 +310,13 @@ public final class MarkerGson {
return new Vector3d(x, y, z);
}
private void writeRounded(JsonWriter json, double value) throws IOException {
// rounding and remove ".0" to save string space
double d = Math.round(value * 10000d) / 10000d;
if (d == (long) d) json.value((long) d);
else json.value(d);
}
}
static class Vector2iAdapter extends TypeAdapter<Vector2i> {

View File

@ -0,0 +1,74 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.api.markers;
/**
* @see POIMarker
* @see ShapeMarker
* @see ExtrudeMarker
* @see LineMarker
*/
public interface DetailMarker {
/**
* Getter for the detail of this marker. The label can include html-tags.
* @return the detail of this {@link Marker}
*/
String getDetail();
/**
* Sets the detail of this {@link Marker}. The detail can include html-tags.<br>
* This is the text that will be displayed on the popup when you click on this marker.
* <p>
* <b>Important:</b><br>
* Html-tags in the label will not be escaped, so you can use them to style the {@link Marker}-detail.<br>
* Make sure you escape all html-tags from possible user inputs to prevent possible
* <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">XSS-Attacks</a> on the web-client!
* </p>
*
* @param detail the new detail for this {@link ObjectMarker}
*/
void setDetail(String detail);
interface Builder<B> {
/**
* Sets the detail of the {@link Marker}. The detail can include html-tags.<br>
* This is the text that will be displayed on the popup when you click on the marker.
* <p>
* <b>Important:</b><br>
* Html-tags in the label will not be escaped, so you can use them to style the {@link Marker}-detail.<br>
* Make sure you escape all html-tags from possible user inputs to prevent possible
* <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">XSS-Attacks</a> on the web-client!
* </p>
*
* @param detail the new detail for the {@link Marker}
* @return this builder for chaining
*/
B detail(String detail);
}
}

View File

@ -25,9 +25,14 @@
package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
@DebugDump
/**
* @see HtmlMarker
* @see POIMarker
* @see ShapeMarker
* @see ExtrudeMarker
* @see LineMarker
*/
public abstract class DistanceRangedMarker extends Marker {
private double minDistance, maxDistance;

View File

@ -0,0 +1,137 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector2i;
import java.util.Arrays;
import java.util.Collection;
import java.util.regex.Pattern;
/**
* @see HtmlMarker
* @see POIMarker
*/
public interface ElementMarker {
Pattern STYLE_CLASS_PATTERN = Pattern.compile("-?[_a-zA-Z]+[_a-zA-Z0-9-]*");
/**
* Getter for the position (in pixels) where the element is anchored to the map.
* @return the anchor-position in pixels
*/
Vector2i getAnchor();
/**
* Sets the position (in pixels) where the element is anchored to the map.
* @param anchor the anchor-position in pixels
*/
void setAnchor(Vector2i anchor);
/**
* Sets the position (in pixels) where the 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 an (unmodifiable) collection of CSS-classed that the element of this marker will have.
* @return the style-classes of this element-marker
*/
Collection<String> getStyleClasses();
/**
* Sets the CSS-classes that the element of this marker will have.<br>
* All classes must match <code>-?[_a-zA-Z]+[_a-zA-Z0-9-]*</code><br>
* Any existing classes on this marker will be removed.
* @param styleClasses the style-classes this element-marker will have
*/
default void setStyleClasses(String... styleClasses) {
this.setStyleClasses(Arrays.asList(styleClasses));
}
/**
* Sets the CSS-classes that the element of this marker will have.<br>
* All classes must match <code>-?[_a-zA-Z]+[_a-zA-Z0-9-]*</code><br>
* Any existing classes on this marker will be removed.
* @param styleClasses the style-classes this element-marker will have
*/
void setStyleClasses(Collection<String> styleClasses);
/**
* Adds the CSS-classes that the element of this marker will have.<br>
* All classes must match <code>-?[_a-zA-Z]+[_a-zA-Z0-9-]*</code><br>
* @param styleClasses the style-classes this element-marker will have
*/
default void addStyleClasses(String... styleClasses) {
this.setStyleClasses(Arrays.asList(styleClasses));
}
/**
* Adds the CSS-classes that the element of this marker will have.<br>
* All classes must match <code>-?[_a-zA-Z]+[_a-zA-Z0-9-]*</code><br>
* @param styleClasses the style-classes this element-marker will have
*/
void addStyleClasses(Collection<String> styleClasses);
interface Builder<B> {
/**
* Sets the position (in pixels) where the element is anchored to the map.
* @param anchor the anchor-position in pixels
* @return this builder for chaining
*/
B anchor(Vector2i anchor);
/**
* <b>Adds</b> the CSS-classes that the element of this marker will have.<br>
* All classes must match <code>-?[_a-zA-Z]+[_a-zA-Z0-9-]*</code><br>
* @return this builder for chaining
*/
B styleClasses(String... styleClasses);
/**
* Removes any existing style-classes from this builder.
* @see #styleClasses(String...)
* @return this builder for chaining
*/
B clearStyleClasses();
/**
* Sets the position (in pixels) where the element is anchored to the map.
* @param x the anchor-x-position in pixels
* @param y the anchor-y-position in pixels
* @return this builder for chaining
*/
default B anchor(int x, int y) {
return anchor(new Vector2i(x, y));
}
}
}

View File

@ -26,17 +26,20 @@ package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector2d;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.math.Color;
import de.bluecolored.bluemap.api.math.Shape;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
@DebugDump
@SuppressWarnings("FieldMayBeFinal")
public class ExtrudeMarker extends ObjectMarker {
private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1);
private Shape shape;
private Collection<Shape> holes = new ArrayList<>();
private float shapeMinY, shapeMaxY;
private boolean depthTest = true;
private int lineWidth = 2;
@ -138,6 +141,15 @@ public class ExtrudeMarker extends ObjectMarker {
this.shapeMaxY = maxY;
}
/**
* Getter for the <b>mutable</b> collection of holes in this {@link ExtrudeMarker}.
* <p>Any shape in this collection will be a hole in the main {@link Shape} of this marker</p>
* @return A <b>mutable</b> collection of hole-shapes
*/
public Collection<Shape> getHoles() {
return holes;
}
/**
* Sets the position of this {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box).
* <p><i>(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)</i></p>
@ -272,6 +284,7 @@ public class ExtrudeMarker extends ObjectMarker {
Shape shape;
float shapeMinY, shapeMaxY;
Collection<Shape> holes = new ArrayList<>();
Boolean depthTest;
Integer lineWidth;
Color lineColor;
@ -294,6 +307,25 @@ public class ExtrudeMarker extends ObjectMarker {
return this;
}
/**
* <b>Adds</b> some hole-{@link Shape}s.
* @param holes the additional holes
* @return this builder for chaining
*/
public Builder holes(Shape... holes) {
this.holes.addAll(Arrays.asList(holes));
return this;
}
/**
* Removes all hole-shapes from this Builder.
* @return this builder for chaining
*/
public Builder clearHoles() {
this.holes.clear();
return this;
}
/**
* Sets the position of the {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box).
* @return this builder for chaining
@ -361,6 +393,7 @@ public class ExtrudeMarker extends ObjectMarker {
shapeMinY,
shapeMaxY
);
marker.getHoles().addAll(holes);
if (depthTest != null) marker.setDepthTestEnabled(depthTest);
if (lineWidth != null) marker.setLineWidth(lineWidth);
if (lineColor != null) marker.setLineColor(lineColor);

View File

@ -27,15 +27,16 @@ package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Objects;
import java.util.*;
/**
* A marker that is a html-element placed somewhere on the map.
*/
@DebugDump
public class HtmlMarker extends DistanceRangedMarker {
@SuppressWarnings("FieldMayBeFinal")
public class HtmlMarker extends DistanceRangedMarker implements ElementMarker {
private Set<String> classes = new HashSet<>();
private Vector2i anchor;
private String html;
@ -82,31 +83,16 @@ public class HtmlMarker extends DistanceRangedMarker {
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
}
/**
* Getter for the position (in pixels) where the html-element is anchored to the map.
* @return the anchor-position in pixels
*/
@Override
public Vector2i getAnchor() {
return anchor;
}
/**
* Sets the position (in pixels) where the html-element is anchored to the map.
* @param anchor the anchor-position in pixels
*/
@Override
public void setAnchor(Vector2i anchor) {
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
}
/**
* 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
*/
public void setAnchor(int x, int y) {
setAnchor(new Vector2i(x, y));
}
/**
* Getter for the html-code of this HTML marker
* @return the html-code
@ -130,6 +116,28 @@ public class HtmlMarker extends DistanceRangedMarker {
this.html = Objects.requireNonNull(html, "html must not be null");
}
@Override
public Collection<String> getStyleClasses() {
return Collections.unmodifiableCollection(this.classes);
}
@Override
public void setStyleClasses(Collection<String> styleClasses) {
if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate()))
throw new IllegalArgumentException("One of the provided style-classes has an invalid format!");
this.classes.clear();
this.classes.addAll(styleClasses);
}
@Override
public void addStyleClasses(Collection<String> styleClasses) {
if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate()))
throw new IllegalArgumentException("One of the provided style-classes has an invalid format!");
this.classes.addAll(styleClasses);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -158,32 +166,20 @@ public class HtmlMarker extends DistanceRangedMarker {
return new Builder();
}
public static class Builder extends DistanceRangedMarker.Builder<HtmlMarker, Builder> {
public static class Builder extends DistanceRangedMarker.Builder<HtmlMarker, Builder>
implements ElementMarker.Builder<Builder> {
Set<String> classes = new HashSet<>();
Vector2i anchor;
String html;
/**
* Sets the position (in pixels) where the html-element is anchored to the map.
* @param anchor the anchor-position in pixels
* @return this builder for chaining
*/
@Override
public Builder anchor(Vector2i anchor) {
this.anchor = anchor;
return this;
}
/**
* 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
* @return this builder for chaining
*/
public Builder anchor(int x, int y) {
this.anchor = new Vector2i(x, y);
return this;
}
/**
* Sets the html for the {@link HtmlMarker}.
*
@ -200,6 +196,22 @@ public class HtmlMarker extends DistanceRangedMarker {
return this;
}
@Override
public Builder styleClasses(String... styleClasses) {
Collection<String> styleClassesCollection = Arrays.asList(styleClasses);
if (!styleClassesCollection.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate()))
throw new IllegalArgumentException("One of the provided style-classes has an invalid format!");
this.classes.addAll(styleClassesCollection);
return this;
}
@Override
public Builder clearStyleClasses() {
this.classes.clear();
return this;
}
/**
* Creates a new {@link HtmlMarker} with the current builder-settings.<br>
* The minimum required settings to build this marker are:
@ -218,6 +230,7 @@ public class HtmlMarker extends DistanceRangedMarker {
checkNotNull(html, "html")
);
if (anchor != null) marker.setAnchor(anchor);
marker.setStyleClasses(classes);
return build(marker);
}

View File

@ -25,13 +25,11 @@
package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.math.Color;
import de.bluecolored.bluemap.api.math.Line;
import java.util.Objects;
@DebugDump
public class LineMarker extends ObjectMarker {
private static final Line DEFAULT_LINE = new Line(Vector3d.ZERO, Vector3d.ONE);

View File

@ -25,7 +25,6 @@
package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Objects;
@ -38,17 +37,20 @@ import java.util.Objects;
* @see ExtrudeMarker
* @see LineMarker
*/
@DebugDump
public abstract class Marker {
private final String type;
private String label;
private Vector3d position;
private int sorting;
private boolean listed;
public Marker(String type, String label, Vector3d position) {
this.type = Objects.requireNonNull(type, "type cannot be null");
this.label = Objects.requireNonNull(label, "label cannot be null");
this.position = Objects.requireNonNull(position, "position cannot be null");
this.sorting = 0;
this.listed = true;
}
/**
@ -103,10 +105,50 @@ public abstract class Marker {
* @param y the y-coordinate of the new position
* @param z the z-coordinate of the new position
*/
public void setPosition(int x, int y, int z) {
public void setPosition(double x, double y, double z) {
setPosition(new Vector3d(x, y, z));
}
/**
* Returns the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @return this markers sorting-value
*/
public int getSorting() {
return sorting;
}
/**
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker
*/
public void setSorting(int sorting) {
this.sorting = sorting;
}
/**
* This value defines whether the marker will be listed (true) in markers and lists by the webapp (additionally to being
* displayed on the map) or not (false).
* @return whether the marker will be listed or not
*/
public boolean isListed() {
return listed;
}
/**
* Defines whether the marker will be listed (true) in markers and lists by the webapp (additionally to being
* displayed on the map) or not (false).
* @param listed whether the marker will be listed or not
*/
public void setListed(boolean listed) {
this.listed = listed;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -131,6 +173,8 @@ public abstract class Marker {
String label;
Vector3d position;
Integer sorting;
Boolean listed;
/**
* Sets the label of the {@link Marker}.
@ -160,10 +204,32 @@ public abstract class Marker {
* @param z the z-coordinate of the new position
* @return this builder for chaining
*/
public B position(int x, int y, int z) {
public B position(double x, double y, double z) {
return position(new Vector3d(x, y, z));
}
/**
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker
*/
public B sorting(Integer sorting) {
this.sorting = sorting;
return self();
}
/**
* Defines whether the marker will be listed (true) in markers and lists by the webapp (additionally to being
* displayed on the map) or not (false).
* @param listed whether the marker will be listed or not
*/
public B listed(Boolean listed) {
this.listed = listed;
return self();
}
/**
* Creates a new {@link Marker} with the current builder-settings
* @return The new {@link Marker}-instance
@ -173,6 +239,8 @@ public abstract class Marker {
T build(T marker) {
if (label != null) marker.setLabel(label);
if (position != null) marker.setPosition(position);
if (sorting != null) marker.setSorting(sorting);
if (listed != null) marker.setListed(listed);
return marker;
}
@ -186,6 +254,26 @@ public abstract class Marker {
return object;
}
// -----
/**
* @deprecated use {@link #position(double, double, double)} instead
*/
@Deprecated(forRemoval = true)
public B position(int x, int y, int z) {
return position(new Vector3d(x, y, z));
}
}
// -----
/**
* @deprecated use {@link #setPosition(double, double, double)} instead
*/
@Deprecated(forRemoval = true)
public void setPosition(int x, int y, int z) {
setPosition(new Vector3d(x, y, z));
}
}

View File

@ -24,8 +24,6 @@
*/
package de.bluecolored.bluemap.api.markers;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@ -33,11 +31,11 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* A set of {@link Marker}s that are displayed on the maps in the web-app.
*/
@DebugDump
public class MarkerSet {
private String label;
private boolean toggleable, defaultHidden;
private int sorting;
private final ConcurrentHashMap<String, Marker> markers;
/**
@ -56,10 +54,7 @@ public class MarkerSet {
* @see #setLabel(String)
*/
public MarkerSet(String label) {
this.label = Objects.requireNonNull(label);
this.toggleable = true;
this.defaultHidden = false;
this.markers = new ConcurrentHashMap<>();
this(label, true, false);
}
/**
@ -77,6 +72,7 @@ public class MarkerSet {
this.label = Objects.requireNonNull(label);
this.toggleable = toggleable;
this.defaultHidden = defaultHidden;
this.sorting = 0;
this.markers = new ConcurrentHashMap<>();
}
@ -149,6 +145,28 @@ public class MarkerSet {
this.defaultHidden = defaultHidden;
}
/**
* Returns the sorting-value that will be used by the webapp to sort the marker-sets.<br>
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @return This marker-sets sorting-value
*/
public int getSorting() {
return sorting;
}
/**
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker-set
*/
public void setSorting(int sorting) {
this.sorting = sorting;
}
/**
* Getter for a (modifiable) {@link Map} of all {@link Marker}s in this {@link MarkerSet}.
* The keys of the map are the id's of the {@link Marker}s.
@ -220,6 +238,7 @@ public class MarkerSet {
private String label;
private Boolean toggleable, defaultHidden;
private Integer sorting;
/**
* Sets the label of the {@link MarkerSet}.
@ -262,6 +281,18 @@ public class MarkerSet {
return this;
}
/**
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker-set
*/
public Builder sorting(Integer sorting) {
this.sorting = sorting;
return this;
}
/**
* Creates a new {@link MarkerSet} with the current builder-settings.<br>
* The minimum required settings to build this marker-set are:
@ -276,6 +307,7 @@ public class MarkerSet {
);
if (toggleable != null) markerSet.setToggleable(toggleable);
if (defaultHidden != null) markerSet.setDefaultHidden(defaultHidden);
if (sorting != null) markerSet.setSorting(sorting);
return markerSet;
}

View File

@ -25,14 +25,17 @@
package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.Optional;
@DebugDump
public abstract class ObjectMarker extends DistanceRangedMarker {
/**
* @see ShapeMarker
* @see ExtrudeMarker
* @see LineMarker
*/
public abstract class ObjectMarker extends DistanceRangedMarker implements DetailMarker {
private String detail;
@ -45,26 +48,12 @@ public abstract class ObjectMarker extends DistanceRangedMarker {
this.detail = Objects.requireNonNull(label, "label must not be null");
}
/**
* Getter for the detail of this marker. The label can include html-tags.
* @return the detail of this {@link Marker}
*/
@Override
public String getDetail() {
return detail;
}
/**
* Sets the detail of this {@link Marker}. The detail can include html-tags.<br>
* This is the text that will be displayed on the popup when you click on this marker.
* <p>
* <b>Important:</b><br>
* Html-tags in the label will not be escaped, so you can use them to style the {@link Marker}-detail.<br>
* Make sure you escape all html-tags from possible user inputs to prevent possible
* <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">XSS-Attacks</a> on the web-client!
* </p>
*
* @param detail the new detail for this {@link ObjectMarker}
*/
@Override
public void setDetail(String detail) {
this.detail = Objects.requireNonNull(detail);
}
@ -131,25 +120,14 @@ public abstract class ObjectMarker extends DistanceRangedMarker {
}
public static abstract class Builder<T extends ObjectMarker, B extends ObjectMarker.Builder<T, B>>
extends DistanceRangedMarker.Builder<T, B> {
extends DistanceRangedMarker.Builder<T, B>
implements DetailMarker.Builder<B> {
String detail;
String link;
boolean newTab;
/**
* Sets the detail of the {@link Marker}. The detail can include html-tags.<br>
* This is the text that will be displayed on the popup when you click on the marker.
* <p>
* <b>Important:</b><br>
* Html-tags in the label will not be escaped, so you can use them to style the {@link Marker}-detail.<br>
* Make sure you escape all html-tags from possible user inputs to prevent possible
* <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">XSS-Attacks</a> on the web-client!
* </p>
*
* @param detail the new detail for the {@link Marker}
* @return this builder for chaining
*/
@Override
public B detail(String detail) {
this.detail = detail;
return self();

View File

@ -26,13 +26,16 @@ package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.WebApp;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.BlueMapMap;
import java.util.Objects;
import java.util.*;
@DebugDump
public class POIMarker extends DistanceRangedMarker {
@SuppressWarnings("FieldMayBeFinal")
public class POIMarker extends DistanceRangedMarker implements DetailMarker, ElementMarker {
private Set<String> classes = new HashSet<>();
private String detail;
private String icon;
private Vector2i anchor;
@ -72,10 +75,21 @@ public class POIMarker extends DistanceRangedMarker {
*/
public POIMarker(String label, Vector3d position, String iconAddress, Vector2i anchor) {
super("poi", label, position);
this.detail = Objects.requireNonNull(label, "label must not be null");
this.icon = Objects.requireNonNull(iconAddress, "iconAddress must not be null");
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
}
@Override
public String getDetail() {
return detail;
}
@Override
public void setDetail(String detail) {
this.detail = detail;
}
/**
* Getter for the relative address of the icon used to display this {@link POIMarker}
* @return the relative web-address of the icon
@ -84,18 +98,20 @@ public class POIMarker extends DistanceRangedMarker {
return icon;
}
/**
* Getter for the position (in pixels) where the icon is anchored to the map.
* @return the anchor-position in pixels
*/
@Override
public Vector2i getAnchor() {
return anchor;
}
@Override
public void setAnchor(Vector2i anchor) {
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
}
/**
* 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 WebApp#createImage(java.awt.image.BufferedImage, String)}.
* (See: {@link BlueMapMap#getAssetStorage()})
* @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
*/
@ -106,7 +122,7 @@ public class POIMarker extends DistanceRangedMarker {
/**
* 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 WebApp#createImage(java.awt.image.BufferedImage, String)}.
* (See: {@link BlueMapMap#getAssetStorage()})
* @param anchor the position of the position (in pixels) where the icon is anchored to the map
*/
public void setIcon(String iconAddress, Vector2i anchor) {
@ -114,6 +130,28 @@ public class POIMarker extends DistanceRangedMarker {
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
}
@Override
public Collection<String> getStyleClasses() {
return Collections.unmodifiableCollection(this.classes);
}
@Override
public void setStyleClasses(Collection<String> styleClasses) {
if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate()))
throw new IllegalArgumentException("One of the provided style-classes has an invalid format!");
this.classes.clear();
this.classes.addAll(styleClasses);
}
@Override
public void addStyleClasses(Collection<String> styleClasses) {
if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate()))
throw new IllegalArgumentException("One of the provided style-classes has an invalid format!");
this.classes.addAll(styleClasses);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -142,15 +180,25 @@ public class POIMarker extends DistanceRangedMarker {
return new Builder();
}
public static class Builder extends DistanceRangedMarker.Builder<POIMarker, Builder> {
public static class Builder extends DistanceRangedMarker.Builder<POIMarker, Builder>
implements DetailMarker.Builder<Builder>, ElementMarker.Builder<Builder> {
Set<String> classes = new HashSet<>();
String detail;
String icon;
Vector2i anchor;
@Override
public Builder detail(String detail) {
this.detail = detail;
return this;
}
/**
* Sets the icon for the {@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 WebApp#createImage(java.awt.image.BufferedImage, String)}.
* (See: {@link BlueMapMap#getAssetStorage()})
* @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
* @return this builder for chaining
@ -162,7 +210,7 @@ public class POIMarker extends DistanceRangedMarker {
/**
* Sets the icon for the {@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 WebApp#createImage(java.awt.image.BufferedImage, String)}.
* (See: {@link BlueMapMap#getAssetStorage()})
* @param anchor the position of the position (in pixels) where the icon is anchored to the map
* @return this builder for chaining
*/
@ -172,6 +220,12 @@ public class POIMarker extends DistanceRangedMarker {
return this;
}
@Override
public Builder anchor(Vector2i anchor) {
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
return this;
}
/**
* The {@link POIMarker} will use the default icon. (See: {@link #icon(String, Vector2i)})
* @return this builder for chaining
@ -182,6 +236,22 @@ public class POIMarker extends DistanceRangedMarker {
return this;
}
@Override
public Builder styleClasses(String... styleClasses) {
Collection<String> styleClassesCollection = Arrays.asList(styleClasses);
if (!styleClassesCollection.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate()))
throw new IllegalArgumentException("One of the provided style-classes has an invalid format!");
this.classes.addAll(styleClassesCollection);
return this;
}
@Override
public Builder clearStyleClasses() {
this.classes.clear();
return this;
}
/**
* Creates a new {@link POIMarker} with the current builder-settings.<br>
* The minimum required settings to build this marker are:
@ -196,7 +266,10 @@ public class POIMarker extends DistanceRangedMarker {
checkNotNull(label, "label"),
checkNotNull(position, "position")
);
if (detail != null) marker.setDetail(detail);
if (icon != null) marker.setIcon(icon, anchor);
else if (anchor != null) marker.setAnchor(anchor);
marker.setStyleClasses(classes);
return build(marker);
}
@ -207,7 +280,7 @@ public class POIMarker extends DistanceRangedMarker {
/**
* @deprecated use {@link #builder()} instead.
*/
@Deprecated
@Deprecated(forRemoval = true)
public static Builder toBuilder() {
return new Builder();
}

View File

@ -27,17 +27,20 @@ package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector2d;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.math.Color;
import de.bluecolored.bluemap.api.math.Shape;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
@DebugDump
@SuppressWarnings("FieldMayBeFinal")
public class ShapeMarker extends ObjectMarker {
private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1);
private Shape shape;
private Collection<Shape> holes = new ArrayList<>();
private float shapeY;
private boolean depthTest = true;
private int lineWidth = 2;
@ -49,7 +52,7 @@ public class ShapeMarker extends ObjectMarker {
*/
@SuppressWarnings("unused")
private ShapeMarker() {
this("shape", DEFAULT_SHAPE, 0);
this("", DEFAULT_SHAPE, 0);
}
/**
@ -119,6 +122,15 @@ public class ShapeMarker extends ObjectMarker {
this.shapeY = y;
}
/**
* Getter for the <b>mutable</b> collection of holes in this {@link ShapeMarker}.
* <p>Any shape in this collection will be a hole in the main {@link Shape} of this marker</p>
* @return A <b>mutable</b> collection of hole-shapes
*/
public Collection<Shape> getHoles() {
return holes;
}
/**
* Sets the position of this {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box).
* <p><i>(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)</i></p>
@ -250,6 +262,7 @@ public class ShapeMarker extends ObjectMarker {
Shape shape;
float shapeY;
Collection<Shape> holes = new ArrayList<>();
Boolean depthTest;
Integer lineWidth;
Color lineColor;
@ -269,6 +282,25 @@ public class ShapeMarker extends ObjectMarker {
return this;
}
/**
* <b>Adds</b> some hole-{@link Shape}s.
* @param holes the additional holes
* @return this builder for chaining
*/
public Builder holes(Shape... holes) {
this.holes.addAll(Arrays.asList(holes));
return this;
}
/**
* Removes all hole-shapes from this Builder.
* @return this builder for chaining
*/
public Builder clearHoles() {
this.holes.clear();
return this;
}
/**
* Sets the position of the {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box).
* @return this builder for chaining
@ -334,6 +366,7 @@ public class ShapeMarker extends ObjectMarker {
checkNotNull(shape, "shape"),
shapeY
);
marker.getHoles().addAll(holes);
if (depthTest != null) marker.setDepthTestEnabled(depthTest);
if (lineWidth != null) marker.setLineWidth(lineWidth);
if (lineColor != null) marker.setLineColor(lineColor);

View File

@ -24,11 +24,8 @@
*/
package de.bluecolored.bluemap.api.math;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Objects;
@DebugDump
public class Color {
private final int r, g, b;
@ -128,7 +125,8 @@ public class Color {
return a;
}
private static int parseColorString(String val) {
private static int parseColorString(String value) {
String val = value;
if (val.charAt(0) == '#') {
val = val.substring(1);
if (val.length() == 3) val = val + "f";
@ -136,7 +134,7 @@ public class Color {
val.charAt(0) + val.charAt(0) + val.charAt(1) + val.charAt(1) +
val.charAt(2) + val.charAt(2) + val.charAt(3) + val.charAt(3);
if (val.length() == 6) val = val + "ff";
if (val.length() != 8) throw new NumberFormatException("Invalid color format!");
if (val.length() != 8) throw new NumberFormatException("Invalid color format: '" + value + "'!");
val = val.substring(6, 8) + val.substring(0, 6); // move alpha to front
return Integer.parseUnsignedInt(val, 16);
}
@ -166,4 +164,13 @@ public class Color {
return result;
}
@Override
public String toString() {
return "Color{" +
"r=" + r +
", g=" + g +
", b=" + b +
", a=" + a +
'}';
}
}

View File

@ -25,7 +25,6 @@
package de.bluecolored.bluemap.api.math;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@ -36,7 +35,6 @@ import java.util.List;
/**
* A line consisting of 2 or more {@link Vector3d}-points.
*/
@DebugDump
public class Line {
private final Vector3d[] points;
@ -160,6 +158,16 @@ public class Line {
return this;
}
/**
* Adds multiple points to the end of line.
* @param points the points to be added.
* @return this builder for chaining
*/
public Builder addPoints(Collection<Vector3d> points) {
this.points.addAll(points);
return this;
}
/**
* Builds a new {@link Line} with the points set in this builder.<br>
* There need to be at least 2 points to build a {@link Line}.

View File

@ -25,7 +25,6 @@
package de.bluecolored.bluemap.api.math;
import com.flowpowered.math.vector.Vector2d;
import de.bluecolored.bluemap.api.debug.DebugDump;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@ -36,7 +35,6 @@ import java.util.List;
/**
* A shape consisting of 3 or more {@link Vector2d}-points on a plane.
*/
@DebugDump
public class Shape {
private final Vector2d[] points;
@ -248,6 +246,16 @@ public class Shape {
return this;
}
/**
* Adds multiple points to the end of line.
* @param points the points to be added.
* @return this builder for chaining
*/
public Builder addPoints(Collection<Vector2d> points) {
this.points.addAll(points);
return this;
}
/**
* Builds a new {@link Shape} with the points set in this builder.<br>
* There need to be at least 3 points to build a {@link Shape}.

View File

@ -0,0 +1,42 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.api.plugin;
import java.awt.image.BufferedImage;
import java.util.UUID;
import java.util.function.BiFunction;
@FunctionalInterface
public interface PlayerIconFactory extends BiFunction<UUID, BufferedImage, BufferedImage> {
/**
* Takes a players UUID and skin-image and creates an icon
* @param playerUuid the players UUID
* @param playerSkin the input image
* @return a <b>new</b> {@link BufferedImage} generated based on the input image
*/
BufferedImage apply(UUID playerUuid, BufferedImage playerSkin);
}

View File

@ -0,0 +1,56 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.api.plugin;
@SuppressWarnings("unused")
public interface Plugin {
/**
* Get the {@link SkinProvider} that bluemap is using to fetch player-skins
* @return the {@link SkinProvider} instance bluemap is using
*/
SkinProvider getSkinProvider();
/**
* Sets the {@link SkinProvider} that bluemap will use to fetch new player-skins.
* @param skinProvider The new {@link SkinProvider} bluemap should use
*/
void setSkinProvider(SkinProvider skinProvider);
/**
* Get the {@link PlayerIconFactory} that bluemap is using to convert a player-skin into the icon-image that is used
* for the Player-Markers
* @return The {@link PlayerIconFactory} bluemap uses to convert skins into player-marker icons
*/
PlayerIconFactory getPlayerMarkerIconFactory();
/**
* Set the {@link PlayerIconFactory} that bluemap will use to convert a player-skin into the icon-image that is used
* for the Player-Markers
* @param playerMarkerIconFactory The {@link PlayerIconFactory} bluemap uses to convert skins into player-marker icons
*/
void setPlayerMarkerIconFactory(PlayerIconFactory playerMarkerIconFactory);
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.api.plugin;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Optional;
import java.util.UUID;
/**
* A skin-provider capable of loading minecraft player-skins for a given UUID
*/
@FunctionalInterface
public interface SkinProvider {
/**
* Attempts to load a minecraft-skin from this skin-provider.
* @return an {@link Optional} containing a {@link BufferedImage} with the skin-image or an empty Optional if there is no
* skin for this UUID
* @throws IOException if something went wrong trying to load the skin
*/
Optional<BufferedImage> load(UUID playerUUID) throws IOException;
}