Compare commits

...

28 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
26 changed files with 341 additions and 117 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

@ -33,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 {
@ -82,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)
}
}
}
@ -101,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

@ -35,20 +35,20 @@ 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!
* <p>
* gets closed!<br>
* <br>
* Example:
* <pre>
* try (OutputStream out = assetStorage.writeAsset("image.png")) {
* ImageIO.write(image, "png", out);
* }
* </pre>
* </p>
* @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
@ -57,8 +57,8 @@ public interface AssetStorage {
/**
* Reads an asset from this storage.<br>
* Use the returned {@link InputStream} to read the asset-data.
* <p>
* Use the returned {@link InputStream} to read the asset-data.<br>
* <br>
* Example:
* <pre>
* Optional&lt;InputStream&gt; optIn = assetStorage.readAsset("image.png");
@ -68,7 +68,6 @@ public interface AssetStorage {
* }
* }
* </pre>
* </p>
* @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.

View File

@ -27,8 +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;
@ -43,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")
@ -58,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();
}
}
@ -71,42 +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}
*/
@DebugDump
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();
/**
@ -137,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;
}
@ -163,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) {
@ -176,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) {
@ -197,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);
@ -244,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,27 +37,25 @@ 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();
/**
@ -66,7 +64,6 @@ public interface BlueMapMap {
* is displaying this map. E.g. these assets are also available in server-networks.
* @return the {@link AssetStorage} of this map
*/
@DebugDump
AssetStorage getAssetStorage();
/**
@ -74,14 +71,12 @@ public interface BlueMapMap {
* Changing this map will change the {@link MarkerSet}s and markers displayed on the web-app for this map.
* @return a {@link Map} of {@link MarkerSet}s.
*/
@DebugDump
Map<String, MarkerSet> getMarkerSets();
/**
* Getter for the size of all tiles on this map in blocks.
* @return the tile-size in blocks
*/
@DebugDump
Vector2i getTileSize();
/**
@ -89,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();
/**
@ -99,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);
/**
@ -115,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

@ -110,7 +110,7 @@ public class ContentTypeRegistry {
}
/**
* Registers a new file-suffix => content-type mapping to this registry.
* 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
*/

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,7 +24,7 @@
*/
package de.bluecolored.bluemap.api;
import de.bluecolored.bluemap.api.debug.DebugDump;
import org.jetbrains.annotations.ApiStatus;
import java.awt.image.BufferedImage;
import java.io.IOException;
@ -33,13 +33,13 @@ 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();
/**
@ -47,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);
/**
@ -54,6 +55,7 @@ public interface WebApp {
* @see #setPlayerVisibility(UUID, boolean)
* @param player the UUID of the player
*/
@ApiStatus.Experimental
boolean getPlayerVisibility(UUID player);
/**
@ -61,15 +63,14 @@ public interface WebApp {
* 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!
* <p>
* Style-registrations are <b>not persistent</b>, register your style each time bluemap enables!<br>
* <br>
* Example:
* <pre>
* BlueMapAPI.onEnable(api -> {
* BlueMapAPI.onEnable(api -&gt; {
* api.getWebApp().registerStyle("js/my-custom-style.css");
* });
* </pre>
* </p>
* @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.
*/
@ -80,15 +81,14 @@ public interface WebApp {
* 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!
* <p>
* Script-registrations are <b>not persistent</b>, register your script each time bluemap enables!<br>
* <br>
* Example:
* <pre>
* BlueMapAPI.onEnable(api -> {
* BlueMapAPI.onEnable(api -&gt; {
* api.getWebApp().registerScript("js/my-custom-script.js");
* });
* </pre>
* </p>
* @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.
*/

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

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

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,7 +27,6 @@ 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.*;
@ -35,7 +34,6 @@ import java.util.*;
* A marker that is a html-element placed somewhere on the map.
*/
@SuppressWarnings("FieldMayBeFinal")
@DebugDump
public class HtmlMarker extends DistanceRangedMarker implements ElementMarker {
private Set<String> classes = new HashSet<>();

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;
}
/**
@ -107,6 +109,46 @@ public abstract class Marker {
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}.
@ -164,6 +208,28 @@ public abstract class Marker {
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;
}

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,7 +25,6 @@
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;
@ -36,7 +35,6 @@ import java.util.Optional;
* @see ExtrudeMarker
* @see LineMarker
*/
@DebugDump
public abstract class ObjectMarker extends DistanceRangedMarker implements DetailMarker {
private String detail;

View File

@ -27,12 +27,10 @@ package de.bluecolored.bluemap.api.markers;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.*;
@SuppressWarnings("FieldMayBeFinal")
@DebugDump
public class POIMarker extends DistanceRangedMarker implements DetailMarker, ElementMarker {
private Set<String> classes = new HashSet<>();

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

@ -24,15 +24,13 @@
*/
package de.bluecolored.bluemap.api.plugin;
import de.bluecolored.bluemap.api.debug.DebugDump;
@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
*/
@DebugDump
SkinProvider getSkinProvider();
/**
@ -46,7 +44,6 @@ public interface Plugin {
* for the Player-Markers
* @return The {@link PlayerIconFactory} bluemap uses to convert skins into player-marker icons
*/
@DebugDump
PlayerIconFactory getPlayerMarkerIconFactory();
/**