├── .gitattributes ├── .github └── workflows │ ├── build.yml │ └── publish.yml ├── .gitignore ├── LICENSE ├── LICENSE_HEADER ├── README.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── bluemap.base.gradle.kts │ └── versioning.kt ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src └── main ├── java └── de │ └── bluecolored │ └── bluemap │ └── api │ ├── AssetStorage.java │ ├── BlueMapAPI.java │ ├── BlueMapMap.java │ ├── BlueMapWorld.java │ ├── ContentTypeRegistry.java │ ├── RenderManager.java │ ├── WebApp.java │ ├── debug │ └── DebugDump.java │ ├── gson │ └── MarkerGson.java │ ├── markers │ ├── DetailMarker.java │ ├── DistanceRangedMarker.java │ ├── ElementMarker.java │ ├── ExtrudeMarker.java │ ├── HtmlMarker.java │ ├── LineMarker.java │ ├── Marker.java │ ├── MarkerSet.java │ ├── ObjectMarker.java │ ├── POIMarker.java │ └── ShapeMarker.java │ ├── math │ ├── Color.java │ ├── Line.java │ └── Shape.java │ └── plugin │ ├── PlayerIconFactory.java │ ├── Plugin.java │ └── SkinProvider.java └── resources └── de └── bluecolored └── bluemap └── api └── version.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Normalize as LF in the repository, OS native locally 2 | * text=auto 3 | 4 | *.bat text eol=crlf 5 | gradlew text eol=lf 6 | *.sh text eol=lf 7 | *.conf text eol=lf 8 | 9 | *.java text 10 | *.java diff=java 11 | 12 | # Binary files that should not be modified 13 | *.dat binary 14 | *.db binary 15 | *.icns binary 16 | *.ico binary 17 | *.jar binary 18 | *.jks binary 19 | *.jpg binary 20 | *.key binary 21 | *.png binary 22 | *.ttf binary 23 | *.wav binary 24 | JavaApplicationStub binary 25 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | with: 11 | submodules: recursive 12 | fetch-depth: 0 # needed for versioning 13 | - name: Set up Java 14 | uses: actions/setup-java@v4 15 | with: 16 | distribution: 'temurin' 17 | java-version: 21 18 | cache: 'gradle' 19 | - name: Build with Gradle 20 | run: ./gradlew clean build test 21 | - uses: actions/upload-artifact@v4 22 | with: 23 | name: artifact 24 | path: build/libs/* 25 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | tags: 7 | - '**' 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | with: 15 | submodules: recursive 16 | fetch-depth: 0 # needed for versioning 17 | - name: Set up Java 18 | uses: actions/setup-java@v4 19 | with: 20 | distribution: 'temurin' 21 | java-version: 21 22 | cache: 'gradle' 23 | - name: Build with Gradle 24 | run: ./gradlew publish 25 | env: 26 | BLUECOLORED_USERNAME: ${{ secrets.BLUECOLORED_USERNAME }} 27 | BLUECOLORED_PASSWORD: ${{ secrets.BLUECOLORED_PASSWORD }} 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .gradle/* 3 | */.gradle/* 4 | 5 | build/ 6 | build/* 7 | */build/* 8 | 9 | .settings/ 10 | .settings/* 11 | */.settings/* 12 | 13 | bin/ 14 | bin/* 15 | */bin/* 16 | 17 | doc/ 18 | doc/* 19 | */doc/* 20 | 21 | .classpath 22 | */.classpath 23 | 24 | .project 25 | */.project 26 | 27 | .idea 28 | */.idea 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Blue 4 | Copyright (c) contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![title-banner](https://bluecolored.de/paste/BluemapBanner.png) 2 | 3 | ### Using BlueMapAPI 4 | See the wiki for instructions on how to use the API: 5 | [https://github.com/BlueMap-Minecraft/BlueMapAPI/wiki](https://github.com/BlueMap-Minecraft/BlueMapAPI/wiki) 6 | 7 | ### Discord 8 | If you have a question, help others using BlueMap or get the latest news and info you are welcome to join us [on Discord](https://discord.gg/zmkyJa3)! 9 | 10 | ### Clone 11 | If you have git installed, simply use the command `git clone https://github.com/BlueMap-Minecraft/BlueMapAPI.git` to clone BlueMapAPI. 12 | 13 | ### Build 14 | In order to build BlueMap you simply need to run the `./gradlew build` command in BlueMap's root directory. 15 | You can find the compiled JAR files in `./build/libs`. 16 | 17 | ### Issues / Suggestions 18 | You found a bug, have another issue or a suggestion? Please create an issue [here](https://github.com/BlueMap-Minecraft/BlueMapAPI/issues)! 19 | 20 | ### Contributing 21 | You are welcome to contribute! 22 | Just create a pull request with your changes :) -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | bluemap.base 3 | } 4 | 5 | dependencies { 6 | api ( libs.flow.math ) 7 | api ( libs.gson ) 8 | 9 | compileOnly ( libs.jetbrains.annotations ) 10 | compileOnly ( libs.lombok ) 11 | 12 | annotationProcessor ( libs.lombok ) 13 | } 14 | 15 | publishing { 16 | publications { 17 | create("maven") { 18 | groupId = project.group.toString() 19 | artifactId = project.name 20 | version = project.version.toString() 21 | 22 | from(components["java"]) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | gradlePluginPortal() 8 | } 9 | 10 | dependencies { 11 | fun plugin(dependency: Provider) = dependency.map { 12 | "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" 13 | } 14 | 15 | implementation ( plugin( libs.plugins.spotless ) ) 16 | implementation ( plugin( libs.plugins.shadow ) ) 17 | } 18 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | 2 | // use version-catalog from root project 3 | dependencyResolutionManagement { 4 | versionCatalogs { 5 | register("libs") { 6 | from(files("../gradle/libs.versions.toml")) 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/bluemap.base.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | java 3 | `java-library` 4 | `maven-publish` 5 | id ( "com.diffplug.spotless" ) 6 | } 7 | 8 | group = "de.bluecolored" 9 | version = gitVersion() 10 | 11 | repositories { 12 | maven ("https://repo.bluecolored.de/releases") { 13 | content { includeGroupByRegex ("de\\.bluecolored\\..*") } 14 | } 15 | maven ("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") { 16 | content { includeGroup ("org.spigotmc") } 17 | } 18 | 19 | mavenCentral() 20 | maven ("https://libraries.minecraft.net") 21 | maven ( "https://maven.minecraftforge.net" ) 22 | maven ("https://repo.papermc.io/repository/maven-public/") 23 | } 24 | 25 | tasks.withType(JavaCompile::class).configureEach { 26 | options.encoding = "utf-8" 27 | } 28 | 29 | tasks.withType(AbstractArchiveTask::class).configureEach { 30 | isReproducibleFileOrder = true 31 | isPreserveFileTimestamps = false 32 | } 33 | 34 | java { 35 | toolchain.languageVersion = JavaLanguageVersion.of(21) 36 | withSourcesJar() 37 | withJavadocJar() 38 | } 39 | 40 | tasks.javadoc { 41 | (options as StandardJavadocDocletOptions).apply { 42 | links( 43 | "https://docs.oracle.com/en/java/javase/16/docs/api/", 44 | "https://javadoc.io/doc/com.flowpowered/flow-math/1.0.3/", 45 | "https://javadoc.io/doc/com.google.code.gson/gson/2.8.9/", 46 | ) 47 | addStringOption("Xdoclint:none", "-quiet") 48 | addBooleanOption("html5", true) 49 | } 50 | } 51 | 52 | tasks.test { 53 | useJUnitPlatform() 54 | } 55 | 56 | spotless { 57 | java { 58 | target ("src/*/java/**/*.java") 59 | 60 | licenseHeaderFile(rootProject.file("LICENSE_HEADER")) 61 | indentWithSpaces() 62 | trimTrailingWhitespace() 63 | } 64 | } 65 | 66 | publishing { 67 | repositories { 68 | maven { 69 | name = "bluecolored" 70 | url = uri( "https://repo.bluecolored.de/releases" ) 71 | 72 | credentials { 73 | username = project.findProperty("bluecoloredUsername") as String? ?: System.getenv("BLUECOLORED_USERNAME") 74 | password = project.findProperty("bluecoloredPassword") as String? ?: System.getenv("BLUECOLORED_PASSWORD") 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/versioning.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.Project 2 | import java.io.IOException 3 | import java.util.concurrent.TimeUnit 4 | import java.util.concurrent.TimeoutException 5 | 6 | fun Project.gitHash(): String { 7 | return runCommand("git rev-parse --verify HEAD", "-") 8 | } 9 | 10 | fun Project.gitClean(): Boolean { 11 | if (runCommand("git update-index --refresh", "NOT-CLEAN").equals("NOT-CLEAN")) return false; 12 | return runCommand("git diff-index HEAD --", "NOT-CLEAN").isEmpty(); 13 | } 14 | 15 | fun Project.gitVersion(): String { 16 | val lastTag = if (runCommand("git tag", "").isEmpty()) "" else runCommand("git describe --tags --abbrev=0", "") 17 | val lastVersion = if (lastTag.isEmpty()) "0.0" else lastTag.substring(1) // remove the leading 'v' 18 | val commits = runCommand("git rev-list --count $lastTag..HEAD", "0") 19 | val branch = runCommand("git branch --show-current", "master") 20 | val gitVersion = lastVersion + 21 | (if (branch == "master" || branch.isEmpty()) "" else "-${branch.replace('/', '.')}") + 22 | (if (commits == "0") "" else "-$commits") + 23 | (if (gitClean()) "" else "-dirty") 24 | 25 | logger.lifecycle("${project.name} version: $gitVersion") 26 | 27 | return gitVersion 28 | } 29 | 30 | private fun Project.runCommand(cmd: String, fallback: String? = null): String { 31 | ProcessBuilder(cmd.split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) 32 | .directory(projectDir) 33 | .redirectOutput(ProcessBuilder.Redirect.PIPE) 34 | .redirectError(ProcessBuilder.Redirect.PIPE) 35 | .start() 36 | .apply { 37 | if (!waitFor(10, TimeUnit.SECONDS)) 38 | throw TimeoutException("Failed to execute command: '$cmd'") 39 | } 40 | .run { 41 | val exitCode = waitFor() 42 | if (exitCode == 0) return inputStream.bufferedReader().readText().trim() 43 | 44 | val error = errorStream.bufferedReader().readText().trim() 45 | logger.warn("Failed to execute command '$cmd': $error") 46 | if (fallback != null) return fallback 47 | throw IOException(error) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | junit = "5.8.2" 3 | 4 | [libraries] 5 | flow-math = { module = "com.flowpowered:flow-math", version = "1.0.3" } 6 | gson = { module = "com.google.code.gson:gson", version = "2.8.9" } 7 | jetbrains-annotations = { module = "org.jetbrains:annotations", version = "23.0.0" } 8 | junit-core = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" } 9 | junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" } 10 | lombok = { module = "org.projectlombok:lombok", version = "1.18.32" } 11 | 12 | [plugins] 13 | shadow = { id = "io.github.goooler.shadow", version = "8.+" } 14 | spotless = { id = "com.diffplug.spotless", version = "6.+" } 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueMap-Minecraft/BlueMapAPI/4c6ed2fcfb657ec7088549452ec335bb7eacca6c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "bluemap-api" 2 | 3 | logger.lifecycle(""" 4 | ## Building BlueMapAPI ... 5 | Java: ${System.getProperty("java.version")} 6 | JVM: ${System.getProperty("java.vm.version")} (${System.getProperty("java.vendor")}) 7 | Arch: ${System.getProperty("os.arch")} 8 | """) 9 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/AssetStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api; 26 | 27 | import de.bluecolored.bluemap.api.markers.POIMarker; 28 | import de.bluecolored.bluemap.api.markers.HtmlMarker; 29 | 30 | import java.io.IOException; 31 | import java.io.InputStream; 32 | import java.io.OutputStream; 33 | import java.util.Optional; 34 | 35 | /** 36 | * A storage that is able to hold any "asset"-data for a map. For example images, icons, scripts or json-files. 37 | */ 38 | @SuppressWarnings("unused") 39 | public interface AssetStorage { 40 | 41 | /** 42 | * Writes a new asset into this storage, overwriting any existent assets with the same name.
43 | * Use the returned {@link OutputStream} to write the asset-data. The asset will be added to the storage as soon as that stream 44 | * gets closed!
45 | *
46 | * Example: 47 | *
 48 |      * try (OutputStream out = assetStorage.writeAsset("image.png")) {
 49 |      *     ImageIO.write(image, "png", out);
 50 |      * }
 51 |      * 
52 | * @param name The (unique) name for this asset 53 | * @return An {@link OutputStream} that should be used to write the asset and closed once! 54 | * @throws IOException when the underlying storage rises an IOException 55 | */ 56 | OutputStream writeAsset(String name) throws IOException; 57 | 58 | /** 59 | * Reads an asset from this storage.
60 | * Use the returned {@link InputStream} to read the asset-data.
61 | *
62 | * Example: 63 | *
 64 |      * Optional<InputStream> optIn = assetStorage.readAsset("image.png");
 65 |      * if (optIn.isPresent()) {
 66 |      *     try (InputStream in = optIn.get()) {
 67 |      *         BufferedImage image = ImageIO.read(in);
 68 |      *     }
 69 |      * }
 70 |      * 
71 | * @param name The name of the asset that should be read from the storage. 72 | * @return An {@link Optional} with an {@link InputStream} when the asset is found, from which the asset can be read. 73 | * Or an empty optional if there is no asset with this name. 74 | * @throws IOException when the underlying storage rises an IOException 75 | */ 76 | Optional readAsset(String name) throws IOException; 77 | 78 | /** 79 | * Checks if an asset exists in this storage without reading it.
80 | * This is useful if the asset has a lot of data and using {@link #readAsset(String)} 81 | * just to check if the asset is present would be wasteful. 82 | * @param name The name of the asset to check for 83 | * @return true if the asset is found, false if not 84 | * @throws IOException when the underlying storage rises an IOException 85 | */ 86 | boolean assetExists(String name) throws IOException; 87 | 88 | /** 89 | * Returns the relative URL that can be used by the webapp to request this asset.
90 | * This is the url that you can e.g. use in {@link POIMarker}s or {@link HtmlMarker}s to add an icon.
91 | * If there is no asset with this name, then this method returns the URL that an asset with such a name would 92 | * have if it would be added later. 93 | * @param name The name of the asset 94 | * @return The relative URL for an asset with the given name 95 | */ 96 | String getAssetUrl(String name); 97 | 98 | /** 99 | * Deletes the asset with the given name from this storage, if it exists.
100 | * If there is no asset with this name, this method does nothing. 101 | * @param name The name of the asset that should be deleted 102 | * @throws IOException when the underlying storage rises an IOException 103 | */ 104 | void deleteAsset(String name) throws IOException; 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.JsonElement; 29 | import com.google.gson.JsonObject; 30 | import de.bluecolored.bluemap.api.plugin.Plugin; 31 | import org.jetbrains.annotations.ApiStatus; 32 | 33 | import java.io.InputStream; 34 | import java.io.InputStreamReader; 35 | import java.io.Reader; 36 | import java.net.URL; 37 | import java.nio.file.Path; 38 | import java.util.*; 39 | import java.util.concurrent.ExecutionException; 40 | import java.util.function.Consumer; 41 | 42 | /** 43 | * An API to control the running instance of BlueMap. 44 | *

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

45 | */ 46 | @SuppressWarnings({"unused", "UnusedReturnValue"}) 47 | public abstract class BlueMapAPI { 48 | 49 | @SuppressWarnings("unused") 50 | private static final String VERSION, GIT_HASH; 51 | static { 52 | String version = "DEV", gitHash = "DEV"; 53 | URL url = BlueMapAPI.class.getResource("/de/bluecolored/bluemap/api/version.json"); 54 | if (url != null) { 55 | Gson gson = new Gson(); 56 | try (InputStream in = url.openStream(); Reader reader = new InputStreamReader(in)) { 57 | JsonObject element = gson.fromJson(reader, JsonElement.class).getAsJsonObject(); 58 | version = element.get("version").getAsString(); 59 | gitHash = element.get("git-hash").getAsString(); 60 | } catch (Exception ex) { 61 | System.err.println("Failed to load version from resources!"); 62 | //noinspection CallToPrintStackTrace 63 | ex.printStackTrace(); 64 | } 65 | } 66 | 67 | if (version.equals("${version}")) version = "DEV"; 68 | if (gitHash.equals("${gitHash}")) version = "DEV"; 69 | 70 | VERSION = version; 71 | GIT_HASH = gitHash; 72 | } 73 | 74 | private static BlueMapAPI instance; 75 | 76 | private static final LinkedHashSet> onEnableConsumers = new LinkedHashSet<>(); 77 | private static final LinkedHashSet> onDisableConsumers = new LinkedHashSet<>(); 78 | 79 | /** 80 | * Getter for the {@link RenderManager}. 81 | * @return the {@link RenderManager} 82 | */ 83 | public abstract RenderManager getRenderManager(); 84 | 85 | /** 86 | * Getter for the {@link WebApp}. 87 | * @return the {@link WebApp} 88 | */ 89 | public abstract WebApp getWebApp(); 90 | 91 | /** 92 | * Getter for the {@link Plugin} 93 | * @return the {@link Plugin} 94 | */ 95 | public abstract Plugin getPlugin(); 96 | 97 | /** 98 | * Getter for all {@link BlueMapMap}s loaded by BlueMap. 99 | * @return an unmodifiable collection of all loaded {@link BlueMapMap}s 100 | */ 101 | public abstract Collection getMaps(); 102 | 103 | /** 104 | * Getter for all {@link BlueMapWorld}s loaded by BlueMap. 105 | * @return an unmodifiable collection of all loaded {@link BlueMapWorld}s 106 | */ 107 | public abstract Collection getWorlds(); 108 | 109 | /** 110 | * Getter for a {@link BlueMapWorld} loaded by BlueMap. 111 | * 112 | * @param world Any object that BlueMap can use to identify a world.
113 | * This could be: 114 | *
    115 | *
  • A {@link String} that is the id of the world
  • 116 | *
  • A {@link Path} that is the path to the world-folder
  • 117 | *
  • A Resource-Key object, {@link UUID} or anything that your platform uses to identify worlds
  • 118 | *
  • The actual world-object, any object directly representing the a world on your platform
  • 119 | *
120 | * ("Platform" here stands for the mod/plugin-loader or server-implementation you are using, 121 | * e.g. Spigot, Forge, Fabric or Sponge) 122 | * @return an {@link Optional} with the {@link BlueMapWorld} if it exists 123 | */ 124 | public abstract Optional getWorld(Object world); 125 | 126 | /** 127 | * Getter for a {@link BlueMapMap} loaded by BlueMap with the given id. 128 | * @param id the map id (equivalent to the id configured in BlueMap's config 129 | * @return an {@link Optional} with the {@link BlueMapMap} if it exists 130 | */ 131 | public abstract Optional getMap(String id); 132 | 133 | /** 134 | * Getter for the installed BlueMap version 135 | * @return the version-string 136 | */ 137 | public abstract String getBlueMapVersion(); 138 | 139 | /** 140 | * Getter for the installed BlueMapAPI version 141 | * @return the version-string 142 | */ 143 | public String getAPIVersion() { 144 | return VERSION; 145 | } 146 | 147 | /** 148 | * Returns an instance of {@link BlueMapAPI} if it is currently enabled, else an empty {@link Optional} is returned. 149 | * @return an {@link Optional}<{@link BlueMapAPI}> 150 | */ 151 | public static synchronized Optional getInstance() { 152 | return Optional.ofNullable(instance); 153 | } 154 | 155 | /** 156 | * Registers a {@link Consumer} that will be called every time BlueMap has just been loaded and started and the API is ready to use.
157 | * If {@link BlueMapAPI} is already enabled when this listener is registered the consumer will be called immediately (once, on the same thread)! 158 | *

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

159 | *

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

160 | *

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

161 | *

The {@link Consumer}s are guaranteed to be called in the order they were registered in.

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

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

173 | *

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

174 | *

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

175 | *

The {@link Consumer}s are guaranteed to be called in the order they were registered in.

176 | * @param consumer the {@link Consumer} 177 | */ 178 | public static synchronized void onDisable(Consumer consumer) { 179 | onDisableConsumers.add(consumer); 180 | } 181 | 182 | /** 183 | * Removes a {@link Consumer} that has been registered using {@link #onEnable(Consumer)} or {@link #onDisable(Consumer)}. 184 | * @param consumer the {@link Consumer} instance that has been registered previously 185 | * @return true if a listener was removed as a result of this call 186 | */ 187 | public static synchronized boolean unregisterListener(Consumer consumer) { 188 | return onEnableConsumers.remove(consumer) | onDisableConsumers.remove(consumer); 189 | } 190 | 191 | /** 192 | * Used by BlueMap to register the API and call the listeners properly. 193 | * @param instance the {@link BlueMapAPI}-instance 194 | * @return true if the instance has been registered, false if there already was an instance registered 195 | * @throws ExecutionException if a listener threw an exception during the registration 196 | */ 197 | @ApiStatus.Internal 198 | protected static synchronized boolean registerInstance(BlueMapAPI instance) throws Exception { 199 | if (BlueMapAPI.instance != null) return false; 200 | 201 | BlueMapAPI.instance = instance; 202 | 203 | List thrownExceptions = new ArrayList<>(0); 204 | 205 | for (Consumer listener : BlueMapAPI.onEnableConsumers) { 206 | try { 207 | listener.accept(BlueMapAPI.instance); 208 | } catch (Exception ex) { 209 | thrownExceptions.add(ex); 210 | } 211 | } 212 | 213 | return throwAsOne(thrownExceptions); 214 | } 215 | 216 | /** 217 | * Used by BlueMap to unregister the API and call the listeners properly. 218 | * @param instance the {@link BlueMapAPI} instance 219 | * @return true if the instance was unregistered, false if there was no or another instance registered 220 | * @throws ExecutionException if a listener threw an exception during the un-registration 221 | */ 222 | @ApiStatus.Internal 223 | protected static synchronized boolean unregisterInstance(BlueMapAPI instance) throws Exception { 224 | if (BlueMapAPI.instance != instance) return false; 225 | 226 | List thrownExceptions = new ArrayList<>(0); 227 | 228 | for (Consumer listener : BlueMapAPI.onDisableConsumers) { 229 | try { 230 | listener.accept(BlueMapAPI.instance); 231 | } catch (Exception ex) { 232 | thrownExceptions.add(ex); 233 | } 234 | } 235 | 236 | BlueMapAPI.instance = null; 237 | 238 | return throwAsOne(thrownExceptions); 239 | } 240 | 241 | private static boolean throwAsOne(List thrownExceptions) throws Exception { 242 | if (!thrownExceptions.isEmpty()) { 243 | Exception ex = thrownExceptions.get(0); 244 | for (int i = 1; i < thrownExceptions.size(); i++) { 245 | ex.addSuppressed(thrownExceptions.get(i)); 246 | } 247 | throw ex; 248 | } 249 | 250 | return true; 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/BlueMapMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api; 26 | 27 | import com.flowpowered.math.vector.Vector2i; 28 | import com.flowpowered.math.vector.Vector3d; 29 | import com.flowpowered.math.vector.Vector3i; 30 | import de.bluecolored.bluemap.api.markers.MarkerSet; 31 | import org.jetbrains.annotations.ApiStatus; 32 | 33 | import java.util.Map; 34 | import java.util.function.Predicate; 35 | 36 | /** 37 | * This class represents a map that is rendered by BlueMap of a specific world ({@link BlueMapWorld}). 38 | * Each map belongs to a map configured in BlueMap's configuration file (in the maps: [] list). 39 | */ 40 | @SuppressWarnings("unused") 41 | public interface BlueMapMap { 42 | 43 | /** 44 | * Returns this maps id, this is equal to the id configured in bluemap's config for this map. 45 | * @return the id of this map 46 | */ 47 | String getId(); 48 | 49 | /** 50 | * Returns this maps display-name, this is equal to the name configured in bluemap's config for this map. 51 | * @return the name of this map 52 | */ 53 | String getName(); 54 | 55 | /** 56 | * Getter for the {@link BlueMapWorld} of this map. 57 | * @return the {@link BlueMapWorld} of this map 58 | */ 59 | BlueMapWorld getWorld(); 60 | 61 | /** 62 | * Getter for this map's {@link AssetStorage}.
63 | * Each map has its own storage for assets. Assets that are stored here will be available to every webapp that 64 | * is displaying this map. E.g. these assets are also available in server-networks. 65 | * @return the {@link AssetStorage} of this map 66 | */ 67 | AssetStorage getAssetStorage(); 68 | 69 | /** 70 | * Getter for a (modifiable) {@link Map} of {@link MarkerSet}s with the key being the {@link MarkerSet}'s id. 71 | * Changing this map will change the {@link MarkerSet}s and markers displayed on the web-app for this map. 72 | * @return a {@link Map} of {@link MarkerSet}s. 73 | */ 74 | Map getMarkerSets(); 75 | 76 | /** 77 | * Getter for the size of all tiles on this map in blocks. 78 | * @return the tile-size in blocks 79 | */ 80 | Vector2i getTileSize(); 81 | 82 | /** 83 | * Getter for the offset of the tile-grid on this map.
84 | * E.g. an offset of (2|-1) would mean that the tile (0|0) has block (2|0|-1) at it's min-corner. 85 | * @return the tile-offset in blocks 86 | */ 87 | Vector2i getTileOffset(); 88 | 89 | /** 90 | *

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

92 | *

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

93 | *

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.

94 | * @param filter The filter that will be used from now on. 95 | */ 96 | @ApiStatus.Experimental 97 | void setTileFilter(Predicate filter); 98 | 99 | /** 100 | * Freezes or unfreezes the map in the same way the `/bluemap freeze` command does. 101 | * BlueMap will no longer attempt to update this map if it is frozen. 102 | * @param frozen Whether the map will be frozen or not 103 | */ 104 | void setFrozen(boolean frozen); 105 | 106 | /** 107 | * Checks if the map is currently frozen 108 | * @return true if the map is frozen, false otherwise 109 | */ 110 | boolean isFrozen(); 111 | 112 | /** 113 | * Returns the currently set TileFilter. The default TileFilter is equivalent to t -> true. 114 | */ 115 | @ApiStatus.Experimental 116 | Predicate getTileFilter(); 117 | 118 | /** 119 | * Converts a block-position to a map-tile-coordinate for this map 120 | * 121 | * @param blockX the x-position of the block 122 | * @param blockZ the z-position of the block 123 | * @return the tile position 124 | */ 125 | default Vector2i posToTile(double blockX, double blockZ){ 126 | Vector2i offset = getTileOffset(); 127 | Vector2i size = getTileSize(); 128 | 129 | return new Vector2i( 130 | (int) Math.floor((blockX - offset.getX()) / size.getX()), 131 | (int) Math.floor((blockZ - offset.getY()) / size.getY()) 132 | ); 133 | } 134 | 135 | /** 136 | * Converts a block-position to a map-tile-coordinate for this map 137 | * 138 | * @param pos the position of the block 139 | * @return the tile position 140 | */ 141 | default Vector2i posToTile(Vector3i pos){ 142 | return posToTile(pos.getX(), pos.getZ()); 143 | } 144 | 145 | /** 146 | * Converts a block-position to a map-tile-coordinate for this map 147 | * 148 | * @param pos the position of the block 149 | * @return the tile position 150 | */ 151 | default Vector2i posToTile(Vector3d pos){ 152 | return posToTile(pos.getX(), pos.getZ()); 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/BlueMapWorld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api; 26 | 27 | import java.nio.file.Path; 28 | import java.util.Collection; 29 | 30 | /** 31 | * This class represents a world loaded by BlueMap. 32 | */ 33 | public interface BlueMapWorld { 34 | 35 | /** 36 | * Getter for the id of this world. 37 | * @return the id of this world 38 | */ 39 | String getId(); 40 | 41 | /** 42 | * Getter for the {@link Path} of this world's save-files.
43 | * (To be exact: the parent-folder of the regions-folder used for rendering) 44 | * @return the save-folder of this world. 45 | * @deprecated Getting the save-folder of a world is no longer supported. As it is not guaranteed that every world has a save-folder. 46 | */ 47 | @Deprecated 48 | Path getSaveFolder(); 49 | 50 | /** 51 | * Getter for all {@link BlueMapMap}s for this world 52 | * @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world 53 | */ 54 | Collection getMaps(); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/ContentTypeRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api; 26 | 27 | import java.nio.file.Path; 28 | import java.util.HashMap; 29 | import java.util.Map; 30 | 31 | /** 32 | * This Content-Type registry is used by the internal webserver to get the content-type of an asset.
33 | * The most commonly used file-suffixes and their content-types are registered by default, but you can use the static 34 | * methods of this class to add more, if you need them.
35 | * Note: that any additionally added types won't work if the user uses an external webserver to serve their map-files. 36 | */ 37 | public class ContentTypeRegistry { 38 | 39 | private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream"; 40 | private static final Map SUFFIX_MAP = new HashMap<>(); 41 | 42 | static { 43 | register("txt", "text/plain"); 44 | register("css", "text/css"); 45 | register("csv", "text/csv"); 46 | register("htm", "text/html"); 47 | register("html", "text/html"); 48 | register("js", "text/javascript"); 49 | register("xml", "text/xml"); 50 | 51 | register("png", "image/png"); 52 | register("jpg", "image/jpeg"); 53 | register("jpeg", "image/jpeg"); 54 | register("gif", "image/gif"); 55 | register("webp", "image/webp"); 56 | register("tif", "image/tiff"); 57 | register("tiff", "image/tiff"); 58 | register("svg", "image/svg+xml"); 59 | 60 | register("json", "application/json"); 61 | 62 | register("mp3", "audio/mpeg"); 63 | register("oga", "audio/ogg"); 64 | register("wav", "audio/wav"); 65 | register("weba", "audio/webm"); 66 | 67 | register("mp4", "video/mp4"); 68 | register("mpeg", "video/mpeg"); 69 | register("webm", "video/webm"); 70 | 71 | register("ttf", "font/ttf"); 72 | register("woff", "font/woff"); 73 | register("woff2", "font/woff2"); 74 | } 75 | 76 | /** 77 | * Derives the content-type (mime) string using a path denoting a file 78 | * @param path The path pointing at the file 79 | * @return The derived content-type string 80 | */ 81 | public static String fromPath(Path path) { 82 | return fromFileName(path.getFileName().toString()); 83 | } 84 | 85 | /** 86 | * Derives the content-type (mime) string from the name of a file 87 | * @param fileName The name of the file 88 | * @return The derived content-type string 89 | */ 90 | public static String fromFileName(String fileName) { 91 | int i = fileName.lastIndexOf('.'); 92 | if (i < 0) return DEFAULT_CONTENT_TYPE; 93 | 94 | int s = fileName.lastIndexOf('/'); 95 | if (i < s) return DEFAULT_CONTENT_TYPE; 96 | 97 | String suffix = fileName.substring(i + 1); 98 | return fromFileSuffix(suffix); 99 | } 100 | 101 | /** 102 | * Searches and returns the content-type for the provided file-suffix. 103 | * @param suffix The type-suffix of a file-name 104 | * @return The content-type string 105 | */ 106 | public static String fromFileSuffix(String suffix) { 107 | String contentType = SUFFIX_MAP.get(suffix); 108 | if (contentType != null) return contentType; 109 | return DEFAULT_CONTENT_TYPE; 110 | } 111 | 112 | /** 113 | * Registers a new file-suffix => content-type mapping to this registry. 114 | * @param fileSuffix The type-suffix of a file-name 115 | * @param contentType The content-type string 116 | */ 117 | public static void register(String fileSuffix, String contentType) { 118 | SUFFIX_MAP.put(fileSuffix, contentType); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/RenderManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api; 26 | 27 | import com.flowpowered.math.vector.Vector2i; 28 | 29 | import java.util.Collection; 30 | 31 | /** 32 | * The {@link RenderManager} is used to schedule tile-renders and process them on a number of different threads. 33 | */ 34 | @SuppressWarnings("unused") 35 | public interface RenderManager { 36 | 37 | /** 38 | * Schedules a task to update the given map. 39 | * @param map the map to be updated 40 | * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) 41 | */ 42 | default boolean scheduleMapUpdateTask(BlueMapMap map) { 43 | return scheduleMapUpdateTask(map, false); 44 | } 45 | 46 | /** 47 | * Schedules a task to update the given map. 48 | * @param map the map to be updated 49 | * @param force it this is true, the task will forcefully re-render all tiles, even if there are no changes since the last map-update. 50 | * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) 51 | */ 52 | boolean scheduleMapUpdateTask(BlueMapMap map, boolean force); 53 | 54 | /** 55 | * Schedules a task to update the given map. 56 | * @param map the map to be updated 57 | * @param regions The regions that should be updated ("region" refers to the coordinates of a minecraft region-file (32x32 chunks, 512x512 blocks))
58 | * BlueMaps updating-system works based on region-files. For this reason you can always only update a whole region-file at once. 59 | * @param force it this is true, the task will forcefully re-render all tiles, even if there are no changes since the last map-update. 60 | * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) 61 | */ 62 | boolean scheduleMapUpdateTask(BlueMapMap map, Collection regions, boolean force); 63 | 64 | /** 65 | * Schedules a task to purge the given map. 66 | * An update-task will be scheduled right after the purge, to get the map up-to-date again. 67 | * @param map the map to be purged 68 | * @return true if a new task has been scheduled, false if not (usually because there is already an update-task for this map scheduled) 69 | */ 70 | boolean scheduleMapPurgeTask(BlueMapMap map); 71 | 72 | /** 73 | * Getter for the current size of the render-queue. 74 | * @return the current size of the render-queue 75 | */ 76 | int renderQueueSize(); 77 | 78 | /** 79 | * Getter for the current count of render threads. 80 | * @return the count of render threads 81 | */ 82 | int renderThreadCount(); 83 | 84 | /** 85 | * Whether this {@link RenderManager} is currently running or stopped. 86 | * @return true if this renderer is running 87 | */ 88 | boolean isRunning(); 89 | 90 | /** 91 | * Starts the renderer if it is not already running. 92 | * The renderer will be started with the configured number of render threads. 93 | */ 94 | void start(); 95 | 96 | /** 97 | * Starts the renderer if it is not already running. 98 | * The renderer will be started with the given number of render threads. 99 | * @param threadCount the number of render threads to use, 100 | * must be greater than 0 and should be less than or equal to the number of available cpu-cores. 101 | */ 102 | void start(int threadCount); 103 | 104 | /** 105 | * Stops the renderer if it currently is running. 106 | */ 107 | void stop(); 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/WebApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api; 26 | 27 | import org.jetbrains.annotations.ApiStatus; 28 | 29 | import java.awt.image.BufferedImage; 30 | import java.io.IOException; 31 | import java.nio.file.Path; 32 | import java.util.Map; 33 | import java.util.UUID; 34 | import java.util.function.Consumer; 35 | 36 | @SuppressWarnings("unused") 37 | public interface WebApp { 38 | 39 | /** 40 | * Getter for the configured web-root folder 41 | * @return The {@link Path} of the web-root folder 42 | */ 43 | Path getWebRoot(); 44 | 45 | /** 46 | * Shows or hides the given player from being shown on the web-app. 47 | * @param player the UUID of the player 48 | * @param visible true if the player-marker should be visible, false if it should be hidden 49 | */ 50 | @ApiStatus.Experimental 51 | void setPlayerVisibility(UUID player, boolean visible); 52 | 53 | /** 54 | * Returns true if the given player is currently visible on the web-app. 55 | * @see #setPlayerVisibility(UUID, boolean) 56 | * @param player the UUID of the player 57 | */ 58 | @ApiStatus.Experimental 59 | boolean getPlayerVisibility(UUID player); 60 | 61 | /** 62 | * Registers a css-style so the webapp loads it.
63 | * This method should only be used inside the {@link Consumer} that got registered (before bluemap loaded, 64 | * pre server-start!) to {@link BlueMapAPI#onEnable(Consumer)}.
65 | * Invoking this method at any other time is not supported.
66 | * Style-registrations are not persistent, register your style each time bluemap enables!
67 | *
68 | * Example: 69 | *
 70 |      * BlueMapAPI.onEnable(api -> {
 71 |      *    api.getWebApp().registerStyle("js/my-custom-style.css");
 72 |      * });
 73 |      * 
74 | * @param url The (relative) URL that links to the style.css file. The {@link #getWebRoot()}-method can be used to 75 | * create the custom file in the correct location and make it available to the web-app. 76 | */ 77 | void registerStyle(String url); 78 | 79 | /** 80 | * Registers a js-script so the webapp loads it.
81 | * This method should only be used inside the {@link Consumer} that got registered (before bluemap loaded, 82 | * pre server-start!) to {@link BlueMapAPI#onEnable(Consumer)}.
83 | * Invoking this method at any other time is not supported.
84 | * Script-registrations are not persistent, register your script each time bluemap enables!
85 | *
86 | * Example: 87 | *
 88 |      * BlueMapAPI.onEnable(api -> {
 89 |      *    api.getWebApp().registerScript("js/my-custom-script.js");
 90 |      * });
 91 |      * 
92 | * @param url The (relative) URL that links to the script.js file. The {@link #getWebRoot()}-method can be used to 93 | * create the custom file in the correct location and make it available to the web-app. 94 | */ 95 | void registerScript(String url); 96 | 97 | // ------ 98 | 99 | /** 100 | * @deprecated You should use the {@link #getWebRoot()} method to create the image-files you need, or store map/marker 101 | * specific images in the map's storage (See: {@link BlueMapMap#getAssetStorage()})! 102 | */ 103 | @Deprecated(forRemoval = true) 104 | String createImage(BufferedImage image, String path) throws IOException; 105 | 106 | /** 107 | * @deprecated You should use the {@link #getWebRoot()} method to find the image-files you need, or read map/marker 108 | * specific images from the map's storage (See: {@link BlueMapMap#getAssetStorage()})! 109 | */ 110 | @Deprecated(forRemoval = true) 111 | Map availableImages() throws IOException; 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/debug/DebugDump.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.debug; 26 | 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @deprecated not implemented, unused 34 | */ 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Target({ 37 | ElementType.METHOD, 38 | ElementType.FIELD, 39 | ElementType.TYPE 40 | }) 41 | @Deprecated(forRemoval = true) 42 | public @interface DebugDump { 43 | 44 | String value() default ""; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/gson/MarkerGson.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.gson; 26 | 27 | import com.flowpowered.math.vector.Vector2d; 28 | import com.flowpowered.math.vector.Vector2i; 29 | import com.flowpowered.math.vector.Vector3d; 30 | import com.flowpowered.math.vector.Vector3i; 31 | import com.google.gson.*; 32 | import com.google.gson.stream.JsonReader; 33 | import com.google.gson.stream.JsonToken; 34 | import com.google.gson.stream.JsonWriter; 35 | import de.bluecolored.bluemap.api.markers.*; 36 | import de.bluecolored.bluemap.api.math.Color; 37 | import de.bluecolored.bluemap.api.math.Line; 38 | import de.bluecolored.bluemap.api.math.Shape; 39 | 40 | import java.io.IOException; 41 | import java.lang.reflect.Type; 42 | import java.util.LinkedList; 43 | import java.util.List; 44 | import java.util.Map; 45 | 46 | public final class MarkerGson { 47 | 48 | public static final Gson INSTANCE = addAdapters(new GsonBuilder()) 49 | .setLenient() 50 | .create(); 51 | 52 | private MarkerGson() { 53 | throw new UnsupportedOperationException("Utility class"); 54 | } 55 | 56 | public static GsonBuilder addAdapters(GsonBuilder builder) { 57 | return builder 58 | .registerTypeAdapter(Marker.class, new MarkerDeserializer()) 59 | .registerTypeAdapter(Marker.class, new MarkerSerializer()) 60 | .registerTypeAdapter(Line.class, new LineAdapter()) 61 | .registerTypeAdapter(Shape.class, new ShapeAdapter()) 62 | .registerTypeAdapter(Color.class, new ColorAdapter()) 63 | .registerTypeAdapter(Vector2d.class, new Vector2dAdapter()) 64 | .registerTypeAdapter(Vector3d.class, new Vector3dAdapter()) 65 | .registerTypeAdapter(Vector2i.class, new Vector2iAdapter()) 66 | .registerTypeAdapter(Vector3i.class, new Vector3iAdapter()); 67 | } 68 | 69 | static class MarkerDeserializer implements JsonDeserializer { 70 | 71 | private static final Map> MARKER_TYPES = Map.of( 72 | "html", HtmlMarker.class, 73 | "poi", POIMarker.class, 74 | "shape", ShapeMarker.class, 75 | "extrude", ExtrudeMarker.class, 76 | "line", LineMarker.class 77 | ); 78 | 79 | @Override 80 | public Marker deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { 81 | String markerType = jsonElement.getAsJsonObject().get("type").getAsString(); 82 | Class markerClass = MARKER_TYPES.get(markerType); 83 | if (markerClass == null) throw new JsonParseException("Unknown marker type: " + markerType); 84 | return context.deserialize(jsonElement, markerClass); 85 | } 86 | 87 | } 88 | 89 | static class MarkerSerializer implements JsonSerializer { 90 | 91 | @Override 92 | public JsonElement serialize(Marker src, Type typeOfSrc, JsonSerializationContext context) { 93 | return context.serialize(src, src.getClass()); // serialize the actual marker-subclass 94 | } 95 | 96 | } 97 | 98 | static class LineAdapter extends TypeAdapter { 99 | private static final Vector3dAdapter VEC3D_ADAPTER = new Vector3dAdapter(); 100 | 101 | @Override 102 | public void write(JsonWriter out, Line value) throws IOException { 103 | if (value == null) { 104 | out.nullValue(); 105 | return; 106 | } 107 | 108 | out.beginArray(); 109 | for (Vector3d point : value.getPoints()) { 110 | VEC3D_ADAPTER.write(out, point); 111 | } 112 | out.endArray(); 113 | } 114 | 115 | @Override 116 | public Line read(JsonReader in) throws IOException { 117 | if (in.peek() == JsonToken.NULL) { 118 | in.nextNull(); 119 | return null; 120 | } 121 | 122 | List points = new LinkedList<>(); 123 | 124 | in.beginArray(); 125 | while (in.peek() != JsonToken.END_ARRAY) { 126 | Vector3d point = VEC3D_ADAPTER.read(in); 127 | if (point == null) continue; 128 | points.add(point); 129 | } 130 | in.endArray(); 131 | 132 | return new Line(points.toArray(Vector3d[]::new)); 133 | } 134 | 135 | } 136 | 137 | static class ShapeAdapter extends TypeAdapter { 138 | private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter(true); 139 | 140 | @Override 141 | public void write(JsonWriter out, Shape value) throws IOException { 142 | if (value == null) { 143 | out.nullValue(); 144 | return; 145 | } 146 | 147 | out.beginArray(); 148 | for (Vector2d point : value.getPoints()) { 149 | VEC2D_ADAPTER.write(out, point); 150 | } 151 | out.endArray(); 152 | } 153 | 154 | @Override 155 | public Shape read(JsonReader in) throws IOException { 156 | if (in.peek() == JsonToken.NULL) { 157 | in.nextNull(); 158 | return null; 159 | } 160 | 161 | List points = new LinkedList<>(); 162 | 163 | in.beginArray(); 164 | while (in.peek() != JsonToken.END_ARRAY) { 165 | Vector2d point = VEC2D_ADAPTER.read(in); 166 | if (point == null) continue; 167 | points.add(point); 168 | } 169 | in.endArray(); 170 | 171 | return new Shape(points.toArray(Vector2d[]::new)); 172 | } 173 | 174 | } 175 | 176 | static class ColorAdapter extends TypeAdapter { 177 | 178 | @Override 179 | public void write(JsonWriter out, Color value) throws IOException { 180 | if (value == null) { 181 | out.nullValue(); 182 | return; 183 | } 184 | 185 | out.beginObject(); 186 | out.name("r"); out.value(value.getRed()); 187 | out.name("g"); out.value(value.getGreen()); 188 | out.name("b"); out.value(value.getBlue()); 189 | out.name("a"); out.value(value.getAlpha()); 190 | out.endObject(); 191 | } 192 | 193 | @Override 194 | public Color read(JsonReader in) throws IOException { 195 | if (in.peek() == JsonToken.NULL) { 196 | in.nextNull(); 197 | return null; 198 | } 199 | 200 | in.beginObject(); 201 | int r = 0, g = 0, b = 0; 202 | float a = 1; 203 | while (in.peek() != JsonToken.END_OBJECT) { 204 | switch (in.nextName()) { 205 | case "r" : r = in.nextInt(); break; 206 | case "g" : g = in.nextInt(); break; 207 | case "b" : b = in.nextInt(); break; 208 | case "a" : a = (float) in.nextDouble(); break; 209 | default : in.skipValue(); break; 210 | } 211 | } 212 | in.endObject(); 213 | 214 | return new Color(r, g, b, a); 215 | } 216 | 217 | } 218 | 219 | static class Vector2dAdapter extends TypeAdapter { 220 | 221 | private final boolean useZ; 222 | 223 | public Vector2dAdapter() { 224 | this.useZ = false; 225 | } 226 | 227 | public Vector2dAdapter(boolean useZ) { 228 | this.useZ = useZ; 229 | } 230 | 231 | @Override 232 | public void write(JsonWriter out, Vector2d value) throws IOException { 233 | if (value == null) { 234 | out.nullValue(); 235 | return; 236 | } 237 | 238 | out.beginObject(); 239 | out.name("x"); writeRounded(out, value.getX()); 240 | out.name(useZ ? "z" : "y"); writeRounded(out, value.getY()); 241 | out.endObject(); 242 | } 243 | 244 | @Override 245 | public Vector2d read(JsonReader in) throws IOException { 246 | if (in.peek() == JsonToken.NULL) { 247 | in.nextNull(); 248 | return null; 249 | } 250 | 251 | in.beginObject(); 252 | double x = 0, y = 0; 253 | while (in.peek() != JsonToken.END_OBJECT) { 254 | switch (in.nextName()) { 255 | case "x" : x = in.nextDouble(); break; 256 | case "y" : if (!useZ) y = in.nextDouble(); else in.skipValue(); break; 257 | case "z" : if (useZ) y = in.nextDouble(); else in.skipValue(); break; 258 | default : in.skipValue(); break; 259 | } 260 | } 261 | in.endObject(); 262 | 263 | return new Vector2d(x, y); 264 | } 265 | 266 | private void writeRounded(JsonWriter json, double value) throws IOException { 267 | // rounding and remove ".0" to save string space 268 | double d = Math.round(value * 10000d) / 10000d; 269 | if (d == (long) d) json.value((long) d); 270 | else json.value(d); 271 | } 272 | 273 | } 274 | 275 | static class Vector3dAdapter extends TypeAdapter { 276 | 277 | @Override 278 | public void write(JsonWriter out, Vector3d value) throws IOException { 279 | if (value == null) { 280 | out.nullValue(); 281 | return; 282 | } 283 | 284 | out.beginObject(); 285 | out.name("x"); writeRounded(out, value.getX()); 286 | out.name("y"); writeRounded(out, value.getY()); 287 | out.name("z"); writeRounded(out, value.getZ()); 288 | out.endObject(); 289 | } 290 | 291 | @Override 292 | public Vector3d read(JsonReader in) throws IOException { 293 | if (in.peek() == JsonToken.NULL) { 294 | in.nextNull(); 295 | return null; 296 | } 297 | 298 | in.beginObject(); 299 | double x = 0, y = 0, z = 0; 300 | while (in.peek() != JsonToken.END_OBJECT) { 301 | switch (in.nextName()) { 302 | case "x" : x = in.nextDouble(); break; 303 | case "y" : y = in.nextDouble(); break; 304 | case "z" : z = in.nextDouble(); break; 305 | default : in.skipValue(); break; 306 | } 307 | } 308 | in.endObject(); 309 | 310 | return new Vector3d(x, y, z); 311 | } 312 | 313 | private void writeRounded(JsonWriter json, double value) throws IOException { 314 | // rounding and remove ".0" to save string space 315 | double d = Math.round(value * 10000d) / 10000d; 316 | if (d == (long) d) json.value((long) d); 317 | else json.value(d); 318 | } 319 | 320 | } 321 | 322 | static class Vector2iAdapter extends TypeAdapter { 323 | 324 | @Override 325 | public void write(JsonWriter out, Vector2i value) throws IOException { 326 | if (value == null) { 327 | out.nullValue(); 328 | return; 329 | } 330 | 331 | out.beginObject(); 332 | out.name("x"); out.value(value.getX()); 333 | out.name("y"); out.value(value.getY()); 334 | out.endObject(); 335 | } 336 | 337 | @Override 338 | public Vector2i read(JsonReader in) throws IOException { 339 | if (in.peek() == JsonToken.NULL) { 340 | in.nextNull(); 341 | return null; 342 | } 343 | 344 | in.beginObject(); 345 | int x = 0, y = 0; 346 | while (in.peek() != JsonToken.END_OBJECT) { 347 | switch (in.nextName()) { 348 | case "x" : x = in.nextInt(); break; 349 | case "y" : y = in.nextInt(); break; 350 | default : in.skipValue(); break; 351 | } 352 | } 353 | in.endObject(); 354 | 355 | return new Vector2i(x, y); 356 | } 357 | 358 | } 359 | 360 | static class Vector3iAdapter extends TypeAdapter { 361 | 362 | @Override 363 | public void write(JsonWriter out, Vector3i value) throws IOException { 364 | if (value == null) { 365 | out.nullValue(); 366 | return; 367 | } 368 | 369 | out.beginObject(); 370 | out.name("x"); out.value(value.getX()); 371 | out.name("y"); out.value(value.getY()); 372 | out.name("z"); out.value(value.getZ()); 373 | out.endObject(); 374 | } 375 | 376 | @Override 377 | public Vector3i read(JsonReader in) throws IOException { 378 | if (in.peek() == JsonToken.NULL) { 379 | in.nextNull(); 380 | return null; 381 | } 382 | 383 | in.beginObject(); 384 | int x = 0, y = 0, z = 0; 385 | while (in.peek() != JsonToken.END_OBJECT) { 386 | switch (in.nextName()) { 387 | case "x" : x = in.nextInt(); break; 388 | case "y" : y = in.nextInt(); break; 389 | case "z" : z = in.nextInt(); break; 390 | default : in.skipValue(); break; 391 | } 392 | } 393 | in.endObject(); 394 | 395 | return new Vector3i(x, y, z); 396 | } 397 | 398 | } 399 | 400 | } 401 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/DetailMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | /** 28 | * @see POIMarker 29 | * @see ShapeMarker 30 | * @see ExtrudeMarker 31 | * @see LineMarker 32 | */ 33 | public interface DetailMarker { 34 | 35 | /** 36 | * Getter for the detail of this marker. The label can include html-tags. 37 | * @return the detail of this {@link Marker} 38 | */ 39 | String getDetail(); 40 | 41 | /** 42 | * Sets the detail of this {@link Marker}. The detail can include html-tags.
43 | * This is the text that will be displayed on the popup when you click on this marker. 44 | *

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

50 | * 51 | * @param detail the new detail for this {@link ObjectMarker} 52 | */ 53 | void setDetail(String detail); 54 | 55 | interface Builder { 56 | 57 | /** 58 | * Sets the detail of the {@link Marker}. The detail can include html-tags.
59 | * This is the text that will be displayed on the popup when you click on the marker. 60 | *

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

66 | * 67 | * @param detail the new detail for the {@link Marker} 68 | * @return this builder for chaining 69 | */ 70 | B detail(String detail); 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/DistanceRangedMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import com.flowpowered.math.vector.Vector3d; 28 | 29 | /** 30 | * @see HtmlMarker 31 | * @see POIMarker 32 | * @see ShapeMarker 33 | * @see ExtrudeMarker 34 | * @see LineMarker 35 | */ 36 | public abstract class DistanceRangedMarker extends Marker { 37 | 38 | private double minDistance, maxDistance; 39 | 40 | public DistanceRangedMarker(String type, String label, Vector3d position) { 41 | super(type, label, position); 42 | this.minDistance = 0.0; 43 | this.maxDistance = 10000000.0; 44 | } 45 | 46 | /** 47 | * Getter for the minimum distance of the camera to the position for this {@link Marker} to be displayed.
48 | * If the camera is closer to this {@link Marker} than this distance, it will be hidden! 49 | * 50 | * @return the minimum distance for this {@link Marker} to be displayed 51 | */ 52 | public double getMinDistance() { 53 | return minDistance; 54 | } 55 | 56 | /** 57 | * Sets the minimum distance of the camera to the position of the {@link Marker} for it to be displayed.
58 | * If the camera is closer to this {@link Marker} than this distance, it will be hidden! 59 | * 60 | * @param minDistance the new minimum distance 61 | */ 62 | public void setMinDistance(double minDistance) { 63 | this.minDistance = minDistance; 64 | } 65 | 66 | /** 67 | * Getter for the maximum distance of the camera to the position of the {@link Marker} for it to be displayed.
68 | * If the camera is further to this {@link Marker} than this distance, it will be hidden! 69 | * 70 | * @return the maximum distance for this {@link Marker} to be displayed 71 | */ 72 | public double getMaxDistance() { 73 | return maxDistance; 74 | } 75 | 76 | /** 77 | * Sets the maximum distance of the camera to the position of the {@link Marker} for it to be displayed.
78 | * If the camera is further to this {@link Marker} than this distance, it will be hidden! 79 | * 80 | * @param maxDistance the new maximum distance 81 | */ 82 | public void setMaxDistance(double maxDistance) { 83 | this.maxDistance = maxDistance; 84 | } 85 | 86 | @Override 87 | public boolean equals(Object o) { 88 | if (this == o) return true; 89 | if (o == null || getClass() != o.getClass()) return false; 90 | if (!super.equals(o)) return false; 91 | 92 | DistanceRangedMarker that = (DistanceRangedMarker) o; 93 | 94 | if (Double.compare(that.minDistance, minDistance) != 0) return false; 95 | return Double.compare(that.maxDistance, maxDistance) == 0; 96 | } 97 | 98 | @Override 99 | public int hashCode() { 100 | int result = super.hashCode(); 101 | long temp; 102 | temp = Double.doubleToLongBits(minDistance); 103 | result = 31 * result + (int) (temp ^ (temp >>> 32)); 104 | temp = Double.doubleToLongBits(maxDistance); 105 | result = 31 * result + (int) (temp ^ (temp >>> 32)); 106 | return result; 107 | } 108 | 109 | public static abstract class Builder> 110 | extends Marker.Builder { 111 | 112 | Double minDistance, maxDistance; 113 | 114 | /** 115 | * Sets the minimum distance of the camera to the position of the {@link Marker} for it to be displayed.
116 | * If the camera is closer to this {@link Marker} than this distance, it will be hidden! 117 | * 118 | * @param minDistance the new minimum distance 119 | * @return this builder for chaining 120 | */ 121 | public B minDistance(double minDistance) { 122 | this.minDistance = minDistance; 123 | return self(); 124 | } 125 | 126 | /** 127 | * Sets the maximum distance of the camera to the position of the {@link Marker} for it to be displayed.
128 | * If the camera is further to this {@link Marker} than this distance, it will be hidden! 129 | * 130 | * @param maxDistance the new maximum distance 131 | * @return this builder for chaining 132 | */ 133 | public B maxDistance(double maxDistance) { 134 | this.maxDistance = maxDistance; 135 | return self(); 136 | } 137 | 138 | @Override 139 | T build(T marker) { 140 | if (minDistance != null) marker.setMinDistance(minDistance); 141 | if (maxDistance != null) marker.setMaxDistance(maxDistance); 142 | return super.build(marker); 143 | } 144 | 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/ElementMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import com.flowpowered.math.vector.Vector2i; 28 | 29 | import java.util.Arrays; 30 | import java.util.Collection; 31 | import java.util.regex.Pattern; 32 | 33 | /** 34 | * @see HtmlMarker 35 | * @see POIMarker 36 | */ 37 | public interface ElementMarker { 38 | 39 | Pattern STYLE_CLASS_PATTERN = Pattern.compile("-?[_a-zA-Z]+[_a-zA-Z0-9-]*"); 40 | 41 | /** 42 | * Getter for the position (in pixels) where the element is anchored to the map. 43 | * @return the anchor-position in pixels 44 | */ 45 | Vector2i getAnchor(); 46 | 47 | /** 48 | * Sets the position (in pixels) where the element is anchored to the map. 49 | * @param anchor the anchor-position in pixels 50 | */ 51 | void setAnchor(Vector2i anchor); 52 | 53 | /** 54 | * Sets the position (in pixels) where the element is anchored to the map. 55 | * @param x the anchor-x-position in pixels 56 | * @param y the anchor-y-position in pixels 57 | */ 58 | default void setAnchor(int x, int y) { 59 | setAnchor(new Vector2i(x, y)); 60 | } 61 | 62 | /** 63 | * Getter for an (unmodifiable) collection of CSS-classed that the element of this marker will have. 64 | * @return the style-classes of this element-marker 65 | */ 66 | Collection getStyleClasses(); 67 | 68 | /** 69 | * Sets the CSS-classes that the element of this marker will have.
70 | * All classes must match -?[_a-zA-Z]+[_a-zA-Z0-9-]*
71 | * Any existing classes on this marker will be removed. 72 | * @param styleClasses the style-classes this element-marker will have 73 | */ 74 | default void setStyleClasses(String... styleClasses) { 75 | this.setStyleClasses(Arrays.asList(styleClasses)); 76 | } 77 | 78 | /** 79 | * Sets the CSS-classes that the element of this marker will have.
80 | * All classes must match -?[_a-zA-Z]+[_a-zA-Z0-9-]*
81 | * Any existing classes on this marker will be removed. 82 | * @param styleClasses the style-classes this element-marker will have 83 | */ 84 | void setStyleClasses(Collection styleClasses); 85 | 86 | /** 87 | * Adds the CSS-classes that the element of this marker will have.
88 | * All classes must match -?[_a-zA-Z]+[_a-zA-Z0-9-]*
89 | * @param styleClasses the style-classes this element-marker will have 90 | */ 91 | default void addStyleClasses(String... styleClasses) { 92 | this.setStyleClasses(Arrays.asList(styleClasses)); 93 | } 94 | 95 | /** 96 | * Adds the CSS-classes that the element of this marker will have.
97 | * All classes must match -?[_a-zA-Z]+[_a-zA-Z0-9-]*
98 | * @param styleClasses the style-classes this element-marker will have 99 | */ 100 | void addStyleClasses(Collection styleClasses); 101 | 102 | interface Builder { 103 | 104 | /** 105 | * Sets the position (in pixels) where the element is anchored to the map. 106 | * @param anchor the anchor-position in pixels 107 | * @return this builder for chaining 108 | */ 109 | B anchor(Vector2i anchor); 110 | 111 | /** 112 | * Adds the CSS-classes that the element of this marker will have.
113 | * All classes must match -?[_a-zA-Z]+[_a-zA-Z0-9-]*
114 | * @return this builder for chaining 115 | */ 116 | B styleClasses(String... styleClasses); 117 | 118 | /** 119 | * Removes any existing style-classes from this builder. 120 | * @see #styleClasses(String...) 121 | * @return this builder for chaining 122 | */ 123 | B clearStyleClasses(); 124 | 125 | /** 126 | * Sets the position (in pixels) where the element is anchored to the map. 127 | * @param x the anchor-x-position in pixels 128 | * @param y the anchor-y-position in pixels 129 | * @return this builder for chaining 130 | */ 131 | default B anchor(int x, int y) { 132 | return anchor(new Vector2i(x, y)); 133 | } 134 | 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/ExtrudeMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import com.flowpowered.math.vector.Vector2d; 28 | import com.flowpowered.math.vector.Vector3d; 29 | import de.bluecolored.bluemap.api.math.Color; 30 | import de.bluecolored.bluemap.api.math.Shape; 31 | 32 | import java.util.ArrayList; 33 | import java.util.Arrays; 34 | import java.util.Collection; 35 | import java.util.Objects; 36 | 37 | @SuppressWarnings("FieldMayBeFinal") 38 | public class ExtrudeMarker extends ObjectMarker { 39 | private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1); 40 | 41 | private Shape shape; 42 | private Collection holes = new ArrayList<>(); 43 | private float shapeMinY, shapeMaxY; 44 | private boolean depthTest = true; 45 | private int lineWidth = 2; 46 | private Color lineColor = new Color(255, 0, 0, 1f); 47 | private Color fillColor = new Color(200, 0, 0, 0.3f); 48 | 49 | /** 50 | * Empty constructor for deserialization. 51 | */ 52 | @SuppressWarnings("unused") 53 | private ExtrudeMarker() { 54 | this("", DEFAULT_SHAPE, 0, 0); 55 | } 56 | 57 | /** 58 | * Creates a new {@link ExtrudeMarker}. 59 | *

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

60 | * 61 | * @param label the label of the marker 62 | * @param shape the {@link Shape} of the marker 63 | * @param shapeMinY the minimum y-position of the extruded shape 64 | * @param shapeMaxY the maximum y-position of the extruded shape 65 | * 66 | * @see #setLabel(String) 67 | * @see #setShape(Shape, float, float) 68 | */ 69 | public ExtrudeMarker(String label, Shape shape, float shapeMinY, float shapeMaxY) { 70 | this( 71 | label, 72 | calculateShapeCenter(Objects.requireNonNull(shape, "shape must not be null"), shapeMinY, shapeMaxY), 73 | shape, shapeMinY, shapeMaxY 74 | ); 75 | } 76 | 77 | /** 78 | * Creates a new {@link ExtrudeMarker}. 79 | *

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

81 | * 82 | * @param label the label of the marker 83 | * @param position the coordinates of the marker 84 | * @param shape the shape of the marker 85 | * @param shapeMinY the minimum y-position of the extruded shape 86 | * @param shapeMaxY the maximum y-position of the extruded shape 87 | * 88 | * @see #setLabel(String) 89 | * @see #setPosition(Vector3d) 90 | * @see #setShape(Shape, float, float) 91 | */ 92 | public ExtrudeMarker(String label, Vector3d position, Shape shape, float shapeMinY, float shapeMaxY) { 93 | super("extrude", label, position); 94 | this.shape = Objects.requireNonNull(shape, "shape must not be null"); 95 | this.shapeMinY = shapeMinY; 96 | this.shapeMaxY = shapeMaxY; 97 | } 98 | 99 | /** 100 | * Getter for {@link Shape} of this {@link ExtrudeMarker}. 101 | *

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

103 | * @return the {@link Shape} 104 | */ 105 | public Shape getShape() { 106 | return shape; 107 | } 108 | 109 | /** 110 | * Getter for the minimum height (y-coordinate) of where the shape is displayed on the map.
111 | * (The shape will be extruded from this value to {@link #getShapeMaxY()} on the map) 112 | * @return the min-height of the shape on the map 113 | */ 114 | public float getShapeMinY() { 115 | return shapeMinY; 116 | } 117 | 118 | /** 119 | * Getter for the maximum height (y-coordinate) of where the shape is displayed on the map. 120 | * (The shape will be extruded from {@link #getShapeMinY()} to this value on the map) 121 | * @return the max-height of the shape on the map 122 | */ 123 | public float getShapeMaxY() { 124 | return shapeMaxY; 125 | } 126 | 127 | /** 128 | * Sets the {@link Shape} of this {@link ExtrudeMarker}. 129 | *

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

131 | * (The shape will be extruded from minY to maxY on the map) 132 | * @param shape the new {@link Shape} 133 | * @param minY the new min-height (y-coordinate) of the shape on the map 134 | * @param maxY the new max-height (y-coordinate) of the shape on the map 135 | * 136 | * @see #centerPosition() 137 | */ 138 | public void setShape(Shape shape, float minY, float maxY) { 139 | this.shape = Objects.requireNonNull(shape, "shape must not be null"); 140 | this.shapeMinY = minY; 141 | this.shapeMaxY = maxY; 142 | } 143 | 144 | /** 145 | * Getter for the mutable collection of holes in this {@link ExtrudeMarker}. 146 | *

Any shape in this collection will be a hole in the main {@link Shape} of this marker

147 | * @return A mutable collection of hole-shapes 148 | */ 149 | public Collection getHoles() { 150 | return holes; 151 | } 152 | 153 | /** 154 | * Sets the position of this {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box). 155 | *

(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)

156 | */ 157 | public void centerPosition() { 158 | setPosition(calculateShapeCenter(shape, shapeMinY, shapeMaxY)); 159 | } 160 | 161 | /** 162 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, 163 | * you'll only see the marker when it is not behind anything. 164 | * @return true if the depthTest is enabled 165 | */ 166 | public boolean isDepthTestEnabled() { 167 | return depthTest; 168 | } 169 | 170 | /** 171 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, 172 | * you'll only see the marker when it is not behind anything. 173 | * @param enabled if the depth-test should be enabled for this {@link ExtrudeMarker} 174 | */ 175 | public void setDepthTestEnabled(boolean enabled) { 176 | this.depthTest = enabled; 177 | } 178 | 179 | /** 180 | * Getter for the width of the lines of this {@link ExtrudeMarker}. 181 | * @return the width of the lines in pixels 182 | */ 183 | public int getLineWidth() { 184 | return lineWidth; 185 | } 186 | 187 | /** 188 | * Sets the width of the lines for this {@link ExtrudeMarker}. 189 | * @param width the new width in pixels 190 | */ 191 | public void setLineWidth(int width) { 192 | this.lineWidth = width; 193 | } 194 | 195 | /** 196 | * Getter for the {@link Color} of the border-line of the shape. 197 | * @return the line-color 198 | */ 199 | public Color getLineColor() { 200 | return lineColor; 201 | } 202 | 203 | /** 204 | * Sets the {@link Color} of the border-line of the shape. 205 | * @param color the new line-color 206 | */ 207 | public void setLineColor(Color color) { 208 | this.lineColor = Objects.requireNonNull(color, "color must not be null"); 209 | } 210 | 211 | /** 212 | * Getter for the fill-{@link Color} of the shape. 213 | * @return the fill-color 214 | */ 215 | public Color getFillColor() { 216 | return fillColor; 217 | } 218 | 219 | /** 220 | * Sets the fill-{@link Color} of the shape. 221 | * @param color the new fill-color 222 | */ 223 | public void setFillColor(Color color) { 224 | this.fillColor = Objects.requireNonNull(color, "color must not be null"); 225 | } 226 | 227 | /** 228 | * Sets the border- and fill- color. 229 | * @param lineColor the new border-color 230 | * @param fillColor the new fill-color 231 | * @see #setLineColor(Color) 232 | * @see #setFillColor(Color) 233 | */ 234 | public void setColors(Color lineColor, Color fillColor) { 235 | setLineColor(lineColor); 236 | setFillColor(fillColor); 237 | } 238 | 239 | @Override 240 | public boolean equals(Object o) { 241 | if (this == o) return true; 242 | if (o == null || getClass() != o.getClass()) return false; 243 | if (!super.equals(o)) return false; 244 | 245 | ExtrudeMarker that = (ExtrudeMarker) o; 246 | 247 | if (Float.compare(that.shapeMinY, shapeMinY) != 0) return false; 248 | if (Float.compare(that.shapeMaxY, shapeMaxY) != 0) return false; 249 | if (depthTest != that.depthTest) return false; 250 | if (lineWidth != that.lineWidth) return false; 251 | if (!shape.equals(that.shape)) return false; 252 | if (!lineColor.equals(that.lineColor)) return false; 253 | return fillColor.equals(that.fillColor); 254 | } 255 | 256 | @Override 257 | public int hashCode() { 258 | int result = super.hashCode(); 259 | result = 31 * result + shape.hashCode(); 260 | result = 31 * result + (shapeMinY != 0.0f ? Float.floatToIntBits(shapeMinY) : 0); 261 | result = 31 * result + (shapeMaxY != 0.0f ? Float.floatToIntBits(shapeMaxY) : 0); 262 | result = 31 * result + (depthTest ? 1 : 0); 263 | result = 31 * result + lineWidth; 264 | result = 31 * result + lineColor.hashCode(); 265 | result = 31 * result + fillColor.hashCode(); 266 | return result; 267 | } 268 | 269 | private static Vector3d calculateShapeCenter(Shape shape, float shapeMinY, float shapeMaxY) { 270 | Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5); 271 | float centerY = (shapeMinY + shapeMaxY) * 0.5f; 272 | return new Vector3d(center.getX(), centerY, center.getY()); 273 | } 274 | 275 | /** 276 | * Creates a Builder for {@link ExtrudeMarker}s. 277 | * @return a new Builder 278 | */ 279 | public static Builder builder() { 280 | return new Builder(); 281 | } 282 | 283 | public static class Builder extends ObjectMarker.Builder { 284 | 285 | Shape shape; 286 | float shapeMinY, shapeMaxY; 287 | Collection holes = new ArrayList<>(); 288 | Boolean depthTest; 289 | Integer lineWidth; 290 | Color lineColor; 291 | Color fillColor; 292 | 293 | /** 294 | * Sets the {@link Shape} of the {@link ExtrudeMarker}. 295 | *

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

297 | * (The shape will be extruded from minY to maxY on the map) 298 | * @param shape the new {@link Shape} 299 | * @param minY the new min-height (y-coordinate) of the shape on the map 300 | * @param maxY the new max-height (y-coordinate) of the shape on the map 301 | * @return this builder for chaining 302 | */ 303 | public Builder shape(Shape shape, float minY, float maxY) { 304 | this.shape = shape; 305 | this.shapeMinY = minY; 306 | this.shapeMaxY = maxY; 307 | return this; 308 | } 309 | 310 | /** 311 | * Adds some hole-{@link Shape}s. 312 | * @param holes the additional holes 313 | * @return this builder for chaining 314 | */ 315 | public Builder holes(Shape... holes) { 316 | this.holes.addAll(Arrays.asList(holes)); 317 | return this; 318 | } 319 | 320 | /** 321 | * Removes all hole-shapes from this Builder. 322 | * @return this builder for chaining 323 | */ 324 | public Builder clearHoles() { 325 | this.holes.clear(); 326 | return this; 327 | } 328 | 329 | /** 330 | * Sets the position of the {@link ExtrudeMarker} to the center of the {@link Shape} (it's bounding box). 331 | * @return this builder for chaining 332 | */ 333 | public Builder centerPosition() { 334 | position(null); 335 | return this; 336 | } 337 | 338 | /** 339 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, 340 | * you'll only see the marker when it is not behind anything. 341 | * @param enabled if the depth-test should be enabled for this {@link ExtrudeMarker} 342 | * @return this builder for chaining 343 | */ 344 | public Builder depthTestEnabled(boolean enabled) { 345 | this.depthTest = enabled; 346 | return this; 347 | } 348 | 349 | /** 350 | * Sets the width of the lines for the {@link ExtrudeMarker}. 351 | * @param width the new width in pixels 352 | * @return this builder for chaining 353 | */ 354 | public Builder lineWidth(int width) { 355 | this.lineWidth = width; 356 | return this; 357 | } 358 | 359 | /** 360 | * Sets the {@link Color} of the border-line of the shape. 361 | * @param color the new line-color 362 | * @return this builder for chaining 363 | */ 364 | public Builder lineColor(Color color) { 365 | this.lineColor = color; 366 | return this; 367 | } 368 | 369 | /** 370 | * Sets the fill-{@link Color} of the shape. 371 | * @param color the new fill-color 372 | * @return this builder for chaining 373 | */ 374 | public Builder fillColor(Color color) { 375 | this.fillColor = color; 376 | return this; 377 | } 378 | 379 | /** 380 | * Creates a new {@link ExtrudeMarker} with the current builder-settings.
381 | * The minimum required settings to build this marker are: 382 | *
    383 | *
  • {@link #label(String)}
  • 384 | *
  • {@link #shape(Shape, float, float)}
  • 385 | *
386 | * @return The new {@link ExtrudeMarker}-instance 387 | */ 388 | @Override 389 | public ExtrudeMarker build() { 390 | ExtrudeMarker marker = new ExtrudeMarker( 391 | checkNotNull(label, "label"), 392 | checkNotNull(shape, "shape"), 393 | shapeMinY, 394 | shapeMaxY 395 | ); 396 | marker.getHoles().addAll(holes); 397 | if (depthTest != null) marker.setDepthTestEnabled(depthTest); 398 | if (lineWidth != null) marker.setLineWidth(lineWidth); 399 | if (lineColor != null) marker.setLineColor(lineColor); 400 | if (fillColor != null) marker.setFillColor(fillColor); 401 | return build(marker); 402 | } 403 | 404 | } 405 | 406 | } 407 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/HtmlMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | 28 | import com.flowpowered.math.vector.Vector2i; 29 | import com.flowpowered.math.vector.Vector3d; 30 | 31 | import java.util.*; 32 | 33 | /** 34 | * A marker that is a html-element placed somewhere on the map. 35 | */ 36 | @SuppressWarnings("FieldMayBeFinal") 37 | public class HtmlMarker extends DistanceRangedMarker implements ElementMarker { 38 | 39 | private Set classes = new HashSet<>(); 40 | 41 | private Vector2i anchor; 42 | private String html; 43 | 44 | /** 45 | * Empty constructor for deserialization. 46 | */ 47 | @SuppressWarnings("unused") 48 | private HtmlMarker() { 49 | this("", Vector3d.ZERO, ""); 50 | } 51 | 52 | /** 53 | * Creates a new {@link HtmlMarker}. 54 | * 55 | * @param label the label of the marker 56 | * @param position the coordinates of the marker 57 | * @param html the html-content of the marker 58 | * 59 | * @see #setLabel(String) 60 | * @see #setPosition(Vector3d) 61 | * @see #setHtml(String) 62 | */ 63 | public HtmlMarker(String label, Vector3d position, String html) { 64 | this(label, position, html, new Vector2i(0, 0)); 65 | } 66 | 67 | /** 68 | * Creates a new {@link HtmlMarker}. 69 | * 70 | * @param label the label of the marker 71 | * @param position the coordinates of the marker 72 | * @param html the html-content of the marker 73 | * @param anchor the anchor-point of the html-content 74 | * 75 | * @see #setLabel(String) 76 | * @see #setPosition(Vector3d) 77 | * @see #setHtml(String) 78 | * @see #setAnchor(Vector2i) 79 | */ 80 | public HtmlMarker(String label, Vector3d position, String html, Vector2i anchor) { 81 | super("html", label, position); 82 | this.html = Objects.requireNonNull(html, "html must not be null"); 83 | this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); 84 | } 85 | 86 | @Override 87 | public Vector2i getAnchor() { 88 | return anchor; 89 | } 90 | 91 | @Override 92 | public void setAnchor(Vector2i anchor) { 93 | this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); 94 | } 95 | 96 | /** 97 | * Getter for the html-code of this HTML marker 98 | * @return the html-code 99 | */ 100 | public String getHtml() { 101 | return html; 102 | } 103 | 104 | /** 105 | * Sets the html for this {@link HtmlMarker}. 106 | * 107 | *

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

112 | * 113 | * @param html the html that will be inserted as the marker. 114 | */ 115 | public void setHtml(String html) { 116 | this.html = Objects.requireNonNull(html, "html must not be null"); 117 | } 118 | 119 | @Override 120 | public Collection getStyleClasses() { 121 | return Collections.unmodifiableCollection(this.classes); 122 | } 123 | 124 | @Override 125 | public void setStyleClasses(Collection styleClasses) { 126 | if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate())) 127 | throw new IllegalArgumentException("One of the provided style-classes has an invalid format!"); 128 | 129 | this.classes.clear(); 130 | this.classes.addAll(styleClasses); 131 | } 132 | 133 | @Override 134 | public void addStyleClasses(Collection styleClasses) { 135 | if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate())) 136 | throw new IllegalArgumentException("One of the provided style-classes has an invalid format!"); 137 | 138 | this.classes.addAll(styleClasses); 139 | } 140 | 141 | @Override 142 | public boolean equals(Object o) { 143 | if (this == o) return true; 144 | if (o == null || getClass() != o.getClass()) return false; 145 | if (!super.equals(o)) return false; 146 | 147 | HtmlMarker that = (HtmlMarker) o; 148 | 149 | if (!anchor.equals(that.anchor)) return false; 150 | return html.equals(that.html); 151 | } 152 | 153 | @Override 154 | public int hashCode() { 155 | int result = super.hashCode(); 156 | result = 31 * result + anchor.hashCode(); 157 | result = 31 * result + html.hashCode(); 158 | return result; 159 | } 160 | 161 | /** 162 | * Creates a Builder for {@link HtmlMarker}s. 163 | * @return a new Builder 164 | */ 165 | public static Builder builder() { 166 | return new Builder(); 167 | } 168 | 169 | public static class Builder extends DistanceRangedMarker.Builder 170 | implements ElementMarker.Builder { 171 | 172 | Set classes = new HashSet<>(); 173 | 174 | Vector2i anchor; 175 | String html; 176 | 177 | @Override 178 | public Builder anchor(Vector2i anchor) { 179 | this.anchor = anchor; 180 | return this; 181 | } 182 | 183 | /** 184 | * Sets the html for the {@link HtmlMarker}. 185 | * 186 | *

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

190 | * 191 | * @param html the html that will be inserted as the marker. 192 | * @return this builder for chaining 193 | */ 194 | public Builder html(String html) { 195 | this.html = html; 196 | return this; 197 | } 198 | 199 | @Override 200 | public Builder styleClasses(String... styleClasses) { 201 | Collection styleClassesCollection = Arrays.asList(styleClasses); 202 | if (!styleClassesCollection.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate())) 203 | throw new IllegalArgumentException("One of the provided style-classes has an invalid format!"); 204 | 205 | this.classes.addAll(styleClassesCollection); 206 | return this; 207 | } 208 | 209 | @Override 210 | public Builder clearStyleClasses() { 211 | this.classes.clear(); 212 | return this; 213 | } 214 | 215 | /** 216 | * Creates a new {@link HtmlMarker} with the current builder-settings.
217 | * The minimum required settings to build this marker are: 218 | *
    219 | *
  • {@link #setLabel(String)}
  • 220 | *
  • {@link #setPosition(Vector3d)}
  • 221 | *
  • {@link #setHtml(String)}
  • 222 | *
223 | * @return The new {@link HtmlMarker}-instance 224 | */ 225 | @Override 226 | public HtmlMarker build() { 227 | HtmlMarker marker = new HtmlMarker( 228 | checkNotNull(label, "label"), 229 | checkNotNull(position, "position"), 230 | checkNotNull(html, "html") 231 | ); 232 | if (anchor != null) marker.setAnchor(anchor); 233 | marker.setStyleClasses(classes); 234 | return build(marker); 235 | } 236 | 237 | } 238 | 239 | } 240 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/LineMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import com.flowpowered.math.vector.Vector3d; 28 | import de.bluecolored.bluemap.api.math.Color; 29 | import de.bluecolored.bluemap.api.math.Line; 30 | 31 | import java.util.Objects; 32 | 33 | public class LineMarker extends ObjectMarker { 34 | private static final Line DEFAULT_LINE = new Line(Vector3d.ZERO, Vector3d.ONE); 35 | 36 | private Line line; 37 | private boolean depthTest = true; 38 | private int lineWidth = 2; 39 | private Color lineColor = new Color(255, 0, 0, 1f); 40 | 41 | /** 42 | * Empty constructor for deserialization. 43 | */ 44 | @SuppressWarnings("unused") 45 | private LineMarker() { 46 | this("", DEFAULT_LINE); 47 | } 48 | 49 | /** 50 | * Creates a new {@link LineMarker}. 51 | *

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

52 | * 53 | * @param label the label of the marker 54 | * @param line the {@link Line} of the marker 55 | * 56 | * @see #setLabel(String) 57 | * @see #setLine(Line) 58 | */ 59 | public LineMarker(String label, Line line) { 60 | this(label, calculateLineCenter(Objects.requireNonNull(line, "line must not be null")), line); 61 | } 62 | 63 | /** 64 | * Creates a new {@link LineMarker}. 65 | *

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

67 | * 68 | * @param label the label of the marker 69 | * @param position the coordinates of the marker 70 | * @param line the {@link Line} of the marker 71 | * 72 | * @see #setLabel(String) 73 | * @see #setPosition(Vector3d) 74 | * @see #setLine(Line) 75 | */ 76 | public LineMarker(String label, Vector3d position, Line line) { 77 | super("line", label, position); 78 | this.line = Objects.requireNonNull(line, "line must not be null"); 79 | } 80 | 81 | /** 82 | * Getter for {@link Line} of this {@link LineMarker}. 83 | * @return the {@link Line} 84 | */ 85 | public Line getLine() { 86 | return line; 87 | } 88 | 89 | /** 90 | * Sets the {@link Line} of this {@link LineMarker}. 91 | * @param line the new {@link Line} 92 | * 93 | * @see #centerPosition() 94 | */ 95 | public void setLine(Line line) { 96 | this.line = Objects.requireNonNull(line, "line must not be null"); 97 | } 98 | 99 | /** 100 | * Sets the position of this {@link LineMarker} to the center of the {@link Line} (it's bounding box). 101 | *

(Invoke this after changing the {@link Line} to make sure the markers position gets updated as well)

102 | */ 103 | public void centerPosition() { 104 | setPosition(calculateLineCenter(line)); 105 | } 106 | 107 | /** 108 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, 109 | * you'll only see the marker when it is not behind anything. 110 | * @return true if the depthTest is enabled 111 | */ 112 | public boolean isDepthTestEnabled() { 113 | return depthTest; 114 | } 115 | 116 | /** 117 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, 118 | * you'll only see the marker when it is not behind anything. 119 | * @param enabled if the depth-test should be enabled for this {@link LineMarker} 120 | */ 121 | public void setDepthTestEnabled(boolean enabled) { 122 | this.depthTest = enabled; 123 | } 124 | 125 | /** 126 | * Getter for the width of the lines of this {@link LineMarker}. 127 | * @return the width of the lines in pixels 128 | */ 129 | public int getLineWidth() { 130 | return lineWidth; 131 | } 132 | 133 | /** 134 | * Sets the width of the lines for this {@link LineMarker}. 135 | * @param width the new width in pixels 136 | */ 137 | public void setLineWidth(int width) { 138 | this.lineWidth = width; 139 | } 140 | 141 | /** 142 | * Getter for the {@link Color} of the border-line of the shape. 143 | * @return the line-color 144 | */ 145 | public Color getLineColor() { 146 | return lineColor; 147 | } 148 | 149 | /** 150 | * Sets the {@link Color} of the border-line of the shape. 151 | * @param color the new line-color 152 | */ 153 | public void setLineColor(Color color) { 154 | this.lineColor = Objects.requireNonNull(color, "color must not be null"); 155 | } 156 | 157 | @Override 158 | public boolean equals(Object o) { 159 | if (this == o) return true; 160 | if (o == null || getClass() != o.getClass()) return false; 161 | if (!super.equals(o)) return false; 162 | 163 | LineMarker that = (LineMarker) o; 164 | 165 | if (depthTest != that.depthTest) return false; 166 | if (lineWidth != that.lineWidth) return false; 167 | if (!line.equals(that.line)) return false; 168 | return lineColor.equals(that.lineColor); 169 | } 170 | 171 | @Override 172 | public int hashCode() { 173 | int result = super.hashCode(); 174 | result = 31 * result + line.hashCode(); 175 | result = 31 * result + (depthTest ? 1 : 0); 176 | result = 31 * result + lineWidth; 177 | result = 31 * result + lineColor.hashCode(); 178 | return result; 179 | } 180 | 181 | private static Vector3d calculateLineCenter(Line line) { 182 | return line.getMin().add(line.getMax()).mul(0.5); 183 | } 184 | 185 | /** 186 | * Creates a Builder for {@link LineMarker}s. 187 | * @return a new Builder 188 | */ 189 | public static Builder builder() { 190 | return new Builder(); 191 | } 192 | 193 | public static class Builder extends ObjectMarker.Builder { 194 | 195 | Line line; 196 | Boolean depthTest; 197 | Integer lineWidth; 198 | Color lineColor; 199 | 200 | /** 201 | * Sets the {@link Line} of the {@link LineMarker}. 202 | * @param line the new {@link Line} 203 | * @return this builder for chaining 204 | */ 205 | public Builder line(Line line) { 206 | this.line = line; 207 | return this; 208 | } 209 | 210 | /** 211 | * Sets the position of the {@link LineMarker} to the center of the {@link Line} (it's bounding box). 212 | * @return this builder for chaining 213 | */ 214 | public Builder centerPosition() { 215 | position(null); 216 | return this; 217 | } 218 | 219 | /** 220 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. 221 | * If it is enabled, you'll only see the marker when it is not behind anything. 222 | * @param enabled if the depth-test should be enabled for the {@link LineMarker} 223 | * @return this builder for chaining 224 | */ 225 | public Builder depthTestEnabled(boolean enabled) { 226 | this.depthTest = enabled; 227 | return this; 228 | } 229 | 230 | /** 231 | * Sets the width of the lines for this {@link LineMarker}. 232 | * @param width the new width in pixels 233 | * @return this builder for chaining 234 | */ 235 | public Builder lineWidth(int width) { 236 | this.lineWidth = width; 237 | return this; 238 | } 239 | 240 | /** 241 | * Sets the {@link Color} of the border-line of the shape. 242 | * @param color the new line-color 243 | */ 244 | public Builder lineColor(Color color) { 245 | this.lineColor = color; 246 | return this; 247 | } 248 | 249 | /** 250 | * Creates a new {@link LineMarker} with the current builder-settings.
251 | * The minimum required settings to build this marker are: 252 | *
    253 | *
  • {@link #label(String)}
  • 254 | *
  • {@link #line(Line)}
  • 255 | *
256 | * @return The new {@link LineMarker}-instance 257 | */ 258 | public LineMarker build() { 259 | LineMarker marker = new LineMarker( 260 | checkNotNull(label, "label"), 261 | checkNotNull(line, "line") 262 | ); 263 | if (depthTest != null) marker.setDepthTestEnabled(depthTest); 264 | if (lineWidth != null) marker.setLineWidth(lineWidth); 265 | if (lineColor != null) marker.setLineColor(lineColor); 266 | return build(marker); 267 | } 268 | 269 | } 270 | 271 | } 272 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/Marker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import com.flowpowered.math.vector.Vector3d; 28 | 29 | import java.util.Objects; 30 | 31 | /** 32 | * The Base-Class for all markers that can be displayed in the web-app. 33 | * 34 | * @see HtmlMarker 35 | * @see POIMarker 36 | * @see ShapeMarker 37 | * @see ExtrudeMarker 38 | * @see LineMarker 39 | */ 40 | public abstract class Marker { 41 | 42 | private final String type; 43 | private String label; 44 | private Vector3d position; 45 | private int sorting; 46 | private boolean listed; 47 | 48 | public Marker(String type, String label, Vector3d position) { 49 | this.type = Objects.requireNonNull(type, "type cannot be null"); 50 | this.label = Objects.requireNonNull(label, "label cannot be null"); 51 | this.position = Objects.requireNonNull(position, "position cannot be null"); 52 | this.sorting = 0; 53 | this.listed = true; 54 | } 55 | 56 | /** 57 | * Returns the type of the marker. 58 | * @return the type-id of the marker. 59 | */ 60 | public String getType() { 61 | return type; 62 | } 63 | 64 | /** 65 | * Getter for the label of this marker. 66 | * @return the label of this {@link Marker} 67 | */ 68 | public String getLabel() { 69 | return label; 70 | } 71 | 72 | /** 73 | * Sets the label of this {@link Marker}. 74 | *

(HTML-Tags will be escaped.)

75 | * 76 | * @param label the new label for this {@link Marker} 77 | */ 78 | public void setLabel(String label) { 79 | //escape html-tags 80 | this.label = Objects.requireNonNull(label, "label cannot be null") 81 | .replace("&", "&") 82 | .replace("<", "<") 83 | .replace(">", ">"); 84 | } 85 | 86 | /** 87 | * Getter for the position of where this {@link Marker} lives on the map. 88 | * @return the position of this {@link Marker} 89 | */ 90 | public Vector3d getPosition() { 91 | return position; 92 | } 93 | 94 | /** 95 | * Sets the position of where this {@link Marker} lives on the map. 96 | * @param position the new position 97 | */ 98 | public void setPosition(Vector3d position) { 99 | this.position = Objects.requireNonNull(position, "position cannot be null"); 100 | } 101 | 102 | /** 103 | * Sets the position of where this {@link Marker} lives on the map. 104 | * @param x the x-coordinate of the new position 105 | * @param y the y-coordinate of the new position 106 | * @param z the z-coordinate of the new position 107 | */ 108 | public void setPosition(double x, double y, double z) { 109 | setPosition(new Vector3d(x, y, z)); 110 | } 111 | 112 | /** 113 | * Returns the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).
114 | * A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.
115 | * If multiple markers have the same sorting-value, their order will be arbitrary.
116 | * This value defaults to 0. 117 | * @return this markers sorting-value 118 | */ 119 | public int getSorting() { 120 | return sorting; 121 | } 122 | 123 | /** 124 | * Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).
125 | * A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.
126 | * If multiple markers have the same sorting-value, their order will be arbitrary.
127 | * This value defaults to 0. 128 | * @param sorting the new sorting-value for this marker 129 | */ 130 | public void setSorting(int sorting) { 131 | this.sorting = sorting; 132 | } 133 | 134 | /** 135 | * This value defines whether the marker will be listed (true) in markers and lists by the webapp (additionally to being 136 | * displayed on the map) or not (false). 137 | * @return whether the marker will be listed or not 138 | */ 139 | public boolean isListed() { 140 | return listed; 141 | } 142 | 143 | /** 144 | * Defines whether the marker will be listed (true) in markers and lists by the webapp (additionally to being 145 | * displayed on the map) or not (false). 146 | * @param listed whether the marker will be listed or not 147 | */ 148 | public void setListed(boolean listed) { 149 | this.listed = listed; 150 | } 151 | 152 | @Override 153 | public boolean equals(Object o) { 154 | if (this == o) return true; 155 | if (o == null || getClass() != o.getClass()) return false; 156 | 157 | Marker marker = (Marker) o; 158 | 159 | if (!type.equals(marker.type)) return false; 160 | if (!label.equals(marker.label)) return false; 161 | return position.equals(marker.position); 162 | } 163 | 164 | @Override 165 | public int hashCode() { 166 | int result = type.hashCode(); 167 | result = 31 * result + label.hashCode(); 168 | result = 31 * result + position.hashCode(); 169 | return result; 170 | } 171 | 172 | public static abstract class Builder> { 173 | 174 | String label; 175 | Vector3d position; 176 | Integer sorting; 177 | Boolean listed; 178 | 179 | /** 180 | * Sets the label of the {@link Marker}. 181 | *

(HTML-Tags will be escaped.)

182 | * @param label the new label for the {@link Marker} 183 | * @return this builder for chaining 184 | */ 185 | public B label(String label) { 186 | this.label = label; 187 | return self(); 188 | } 189 | 190 | /** 191 | * Sets the position of where the {@link Marker} lives on the map. 192 | * @param position the new position 193 | * @return this builder for chaining 194 | */ 195 | public B position(Vector3d position) { 196 | this.position = position; 197 | return self(); 198 | } 199 | 200 | /** 201 | * Sets the position of where the {@link Marker} lives on the map. 202 | * @param x the x-coordinate of the new position 203 | * @param y the y-coordinate of the new position 204 | * @param z the z-coordinate of the new position 205 | * @return this builder for chaining 206 | */ 207 | public B position(double x, double y, double z) { 208 | return position(new Vector3d(x, y, z)); 209 | } 210 | 211 | /** 212 | * Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).
213 | * A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.
214 | * If multiple markers have the same sorting-value, their order will be arbitrary.
215 | * This value defaults to 0. 216 | * @param sorting the new sorting-value for this marker 217 | */ 218 | public B sorting(Integer sorting) { 219 | this.sorting = sorting; 220 | return self(); 221 | } 222 | 223 | /** 224 | * Defines whether the marker will be listed (true) in markers and lists by the webapp (additionally to being 225 | * displayed on the map) or not (false). 226 | * @param listed whether the marker will be listed or not 227 | */ 228 | public B listed(Boolean listed) { 229 | this.listed = listed; 230 | return self(); 231 | } 232 | 233 | /** 234 | * Creates a new {@link Marker} with the current builder-settings 235 | * @return The new {@link Marker}-instance 236 | */ 237 | public abstract T build(); 238 | 239 | T build(T marker) { 240 | if (label != null) marker.setLabel(label); 241 | if (position != null) marker.setPosition(position); 242 | if (sorting != null) marker.setSorting(sorting); 243 | if (listed != null) marker.setListed(listed); 244 | return marker; 245 | } 246 | 247 | @SuppressWarnings("unchecked") 248 | B self() { 249 | return (B) this; 250 | } 251 | 252 | O checkNotNull(O object, String name) { 253 | if (object == null) throw new IllegalStateException(name + " has to be set and cannot be null"); 254 | return object; 255 | } 256 | 257 | // ----- 258 | 259 | /** 260 | * @deprecated use {@link #position(double, double, double)} instead 261 | */ 262 | @Deprecated(forRemoval = true) 263 | public B position(int x, int y, int z) { 264 | return position(new Vector3d(x, y, z)); 265 | } 266 | 267 | } 268 | 269 | // ----- 270 | 271 | /** 272 | * @deprecated use {@link #setPosition(double, double, double)} instead 273 | */ 274 | @Deprecated(forRemoval = true) 275 | public void setPosition(int x, int y, int z) { 276 | setPosition(new Vector3d(x, y, z)); 277 | } 278 | 279 | } 280 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/MarkerSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import java.util.Map; 28 | import java.util.Objects; 29 | import java.util.concurrent.ConcurrentHashMap; 30 | 31 | /** 32 | * A set of {@link Marker}s that are displayed on the maps in the web-app. 33 | */ 34 | public class MarkerSet { 35 | 36 | private String label; 37 | private boolean toggleable, defaultHidden; 38 | private int sorting; 39 | private final ConcurrentHashMap markers; 40 | 41 | /** 42 | * Empty constructor for deserialization. 43 | */ 44 | @SuppressWarnings("unused") 45 | private MarkerSet() { 46 | this(""); 47 | } 48 | 49 | /** 50 | * Creates a new {@link MarkerSet}. 51 | * 52 | * @param label the label of the {@link MarkerSet} 53 | * 54 | * @see #setLabel(String) 55 | */ 56 | public MarkerSet(String label) { 57 | this(label, true, false); 58 | } 59 | 60 | /** 61 | * Creates a new {@link MarkerSet}. 62 | * 63 | * @param label the label of the {@link MarkerSet} 64 | * @param toggleable if the {@link MarkerSet} is toggleable 65 | * @param defaultHidden the default visibility of the {@link MarkerSet} 66 | * 67 | * @see #setLabel(String) 68 | * @see #setToggleable(boolean) 69 | * @see #setDefaultHidden(boolean) 70 | */ 71 | public MarkerSet(String label, boolean toggleable, boolean defaultHidden) { 72 | this.label = Objects.requireNonNull(label); 73 | this.toggleable = toggleable; 74 | this.defaultHidden = defaultHidden; 75 | this.sorting = 0; 76 | this.markers = new ConcurrentHashMap<>(); 77 | } 78 | 79 | /** 80 | * Getter for the label of this {@link MarkerSet}. 81 | *

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

83 | * 84 | * @return the label of this {@link MarkerSet} 85 | */ 86 | public String getLabel() { 87 | return label; 88 | } 89 | 90 | /** 91 | * Sets the label of this {@link MarkerSet}. 92 | *

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

94 | * 95 | * @param label the new label 96 | */ 97 | public void setLabel(String label) { 98 | this.label = Objects.requireNonNull(label); 99 | } 100 | 101 | /** 102 | * Checks if the {@link MarkerSet} is toggleable. 103 | *

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

105 | * 106 | * @return whether this {@link MarkerSet} is toggleable 107 | */ 108 | public boolean isToggleable() { 109 | return toggleable; 110 | } 111 | 112 | /** 113 | * Changes if this {@link MarkerSet} is toggleable. 114 | *

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

116 | * 117 | * @param toggleable whether this {@link MarkerSet} should be toggleable 118 | */ 119 | public void setToggleable(boolean toggleable) { 120 | this.toggleable = toggleable; 121 | } 122 | 123 | /** 124 | * Checks if this {@link MarkerSet} is hidden by default. 125 | *

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

128 | * 129 | * @return whether this {@link MarkerSet} is hidden by default 130 | * @see #isToggleable() 131 | */ 132 | public boolean isDefaultHidden() { 133 | return defaultHidden; 134 | } 135 | 136 | /** 137 | * Sets if this {@link MarkerSet} is hidden by default. 138 | *

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

140 | * 141 | * @param defaultHidden whether this {@link MarkerSet} should be hidden by default 142 | * @see #isToggleable() 143 | */ 144 | public void setDefaultHidden(boolean defaultHidden) { 145 | this.defaultHidden = defaultHidden; 146 | } 147 | 148 | /** 149 | * Returns the sorting-value that will be used by the webapp to sort the marker-sets.
150 | * A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.
151 | * If multiple marker-sets have the same sorting-value, their order will be arbitrary.
152 | * This value defaults to 0. 153 | * @return This marker-sets sorting-value 154 | */ 155 | public int getSorting() { 156 | return sorting; 157 | } 158 | 159 | /** 160 | * Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).
161 | * A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.
162 | * If multiple marker-sets have the same sorting-value, their order will be arbitrary.
163 | * This value defaults to 0. 164 | * @param sorting the new sorting-value for this marker-set 165 | */ 166 | public void setSorting(int sorting) { 167 | this.sorting = sorting; 168 | } 169 | 170 | /** 171 | * Getter for a (modifiable) {@link Map} of all {@link Marker}s in this {@link MarkerSet}. 172 | * The keys of the map are the id's of the {@link Marker}s. 173 | * 174 | * @return a {@link Map} of all {@link Marker}s of this {@link MarkerSet}. 175 | */ 176 | public Map getMarkers() { 177 | return markers; 178 | } 179 | 180 | /** 181 | * Convenience method to add a {@link Marker} to this {@link MarkerSet}.
182 | * Shortcut for: getMarkers().get(String) 183 | * @see Map#get(Object) 184 | */ 185 | public Marker get(String key) { 186 | return getMarkers().get(key); 187 | } 188 | 189 | /** 190 | * Convenience method to add a {@link Marker} to this {@link MarkerSet}.
191 | * Shortcut for: getMarkers().put(String,Marker) 192 | * @see Map#put(Object, Object) 193 | */ 194 | public Marker put(String key, Marker marker) { 195 | return getMarkers().put(key, marker); 196 | } 197 | 198 | /** 199 | * Convenience method to remove a {@link Marker} from this {@link MarkerSet}.
200 | * Shortcut for: getMarkers().remove(String) 201 | * @see Map#remove(Object) 202 | */ 203 | public Marker remove(String key) { 204 | return getMarkers().remove(key); 205 | } 206 | 207 | @Override 208 | public boolean equals(Object o) { 209 | if (this == o) return true; 210 | if (o == null || getClass() != o.getClass()) return false; 211 | 212 | MarkerSet markerSet = (MarkerSet) o; 213 | 214 | if (toggleable != markerSet.toggleable) return false; 215 | if (defaultHidden != markerSet.defaultHidden) return false; 216 | if (!label.equals(markerSet.label)) return false; 217 | return markers.equals(markerSet.markers); 218 | } 219 | 220 | @Override 221 | public int hashCode() { 222 | int result = label.hashCode(); 223 | result = 31 * result + (toggleable ? 1 : 0); 224 | result = 31 * result + (defaultHidden ? 1 : 0); 225 | result = 31 * result + markers.hashCode(); 226 | return result; 227 | } 228 | 229 | /** 230 | * Creates a Builder for {@link MarkerSet}s. 231 | * @return a new Builder 232 | */ 233 | public static Builder builder() { 234 | return new Builder(); 235 | } 236 | 237 | public static class Builder { 238 | 239 | private String label; 240 | private Boolean toggleable, defaultHidden; 241 | private Integer sorting; 242 | 243 | /** 244 | * Sets the label of the {@link MarkerSet}. 245 | *

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

247 | * 248 | * @param label the new label 249 | * @return this builder for chaining 250 | */ 251 | public Builder label(String label) { 252 | this.label = label; 253 | return this; 254 | } 255 | 256 | /** 257 | * Changes if the {@link MarkerSet} is toggleable. 258 | *

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

260 | * 261 | * @param toggleable whether the {@link MarkerSet} should be toggleable 262 | * @return this builder for chaining 263 | */ 264 | public Builder toggleable(Boolean toggleable) { 265 | this.toggleable = toggleable; 266 | return this; 267 | } 268 | 269 | /** 270 | * Sets if this {@link MarkerSet} is hidden by default. 271 | *

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

274 | * 275 | * @param defaultHidden whether this {@link MarkerSet} should be hidden by default 276 | * @return this builder for chaining 277 | * @see #isToggleable() 278 | */ 279 | public Builder defaultHidden(Boolean defaultHidden) { 280 | this.defaultHidden = defaultHidden; 281 | return this; 282 | } 283 | 284 | /** 285 | * Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).
286 | * A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.
287 | * If multiple marker-sets have the same sorting-value, their order will be arbitrary.
288 | * This value defaults to 0. 289 | * @param sorting the new sorting-value for this marker-set 290 | */ 291 | public Builder sorting(Integer sorting) { 292 | this.sorting = sorting; 293 | return this; 294 | } 295 | 296 | /** 297 | * Creates a new {@link MarkerSet} with the current builder-settings.
298 | * The minimum required settings to build this marker-set are: 299 | *
    300 | *
  • {@link #setLabel(String)}
  • 301 | *
302 | * @return The new {@link MarkerSet}-instance 303 | */ 304 | public MarkerSet build() { 305 | MarkerSet markerSet = new MarkerSet( 306 | checkNotNull(label, "label") 307 | ); 308 | if (toggleable != null) markerSet.setToggleable(toggleable); 309 | if (defaultHidden != null) markerSet.setDefaultHidden(defaultHidden); 310 | if (sorting != null) markerSet.setSorting(sorting); 311 | return markerSet; 312 | } 313 | 314 | @SuppressWarnings("SameParameterValue") 315 | O checkNotNull(O object, String name) { 316 | if (object == null) throw new IllegalStateException(name + " has to be set and cannot be null"); 317 | return object; 318 | } 319 | 320 | } 321 | 322 | } 323 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/ObjectMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import com.flowpowered.math.vector.Vector3d; 28 | import org.jetbrains.annotations.Nullable; 29 | 30 | import java.util.Objects; 31 | import java.util.Optional; 32 | 33 | /** 34 | * @see ShapeMarker 35 | * @see ExtrudeMarker 36 | * @see LineMarker 37 | */ 38 | public abstract class ObjectMarker extends DistanceRangedMarker implements DetailMarker { 39 | 40 | private String detail; 41 | 42 | @Nullable 43 | private String link; 44 | private boolean newTab; 45 | 46 | public ObjectMarker(String type, String label, Vector3d position) { 47 | super(type, label, position); 48 | this.detail = Objects.requireNonNull(label, "label must not be null"); 49 | } 50 | 51 | @Override 52 | public String getDetail() { 53 | return detail; 54 | } 55 | 56 | @Override 57 | public void setDetail(String detail) { 58 | this.detail = Objects.requireNonNull(detail); 59 | } 60 | 61 | /** 62 | * Gets the link-address of this {@link Marker}.
63 | * If a link is present, this link will be followed when the user clicks on the marker in the web-app. 64 | * 65 | * @return the {@link Optional} link 66 | */ 67 | public Optional getLink() { 68 | return Optional.ofNullable(link); 69 | } 70 | 71 | /** 72 | * If this is true the link ({@link #getLink()}) will be opened in a new tab. 73 | * @return whether the link will be opened in a new tab 74 | * @see #getLink() 75 | */ 76 | public boolean isNewTab() { 77 | return newTab; 78 | } 79 | 80 | /** 81 | * Sets the link-address of this {@link Marker}.
82 | * If a link is present, this link will be followed when the user clicks on the marker in the web-app. 83 | * 84 | * @param link the link, or null to disable the link 85 | * @param newTab whether the link should be opened in a new tab 86 | */ 87 | public void setLink(String link, boolean newTab) { 88 | this.link = Objects.requireNonNull(link, "link must not be null"); 89 | this.newTab = newTab; 90 | } 91 | 92 | /** 93 | * Removes the link of this {@link Marker}. 94 | */ 95 | public void removeLink() { 96 | this.link = null; 97 | this.newTab = false; 98 | } 99 | 100 | @Override 101 | public boolean equals(Object o) { 102 | if (this == o) return true; 103 | if (o == null || getClass() != o.getClass()) return false; 104 | if (!super.equals(o)) return false; 105 | 106 | ObjectMarker that = (ObjectMarker) o; 107 | 108 | if (newTab != that.newTab) return false; 109 | if (!detail.equals(that.detail)) return false; 110 | return Objects.equals(link, that.link); 111 | } 112 | 113 | @Override 114 | public int hashCode() { 115 | int result = super.hashCode(); 116 | result = 31 * result + detail.hashCode(); 117 | result = 31 * result + (link != null ? link.hashCode() : 0); 118 | result = 31 * result + (newTab ? 1 : 0); 119 | return result; 120 | } 121 | 122 | public static abstract class Builder> 123 | extends DistanceRangedMarker.Builder 124 | implements DetailMarker.Builder { 125 | 126 | String detail; 127 | String link; 128 | boolean newTab; 129 | 130 | @Override 131 | public B detail(String detail) { 132 | this.detail = detail; 133 | return self(); 134 | } 135 | 136 | /** 137 | * Sets the link-address of the {@link Marker}.
138 | * If a link is present, this link will be followed when the user clicks on the marker in the web-app. 139 | * 140 | * @param link the link, or null to disable the link 141 | * @param newTab whether the link should be opened in a new tab 142 | * @return this builder for chaining 143 | */ 144 | public B link(String link, boolean newTab) { 145 | this.link = link; 146 | this.newTab = newTab; 147 | return self(); 148 | } 149 | 150 | /** 151 | * The {@link Marker} will have no link. (See: {@link #link(String, boolean)}) 152 | * @return this builder for chaining 153 | */ 154 | public B noLink() { 155 | this.link = null; 156 | this.newTab = false; 157 | return self(); 158 | } 159 | 160 | T build(T marker) { 161 | if (detail != null) marker.setDetail(detail); 162 | if (link != null) marker.setLink(link, newTab); 163 | return super.build(marker); 164 | } 165 | 166 | } 167 | 168 | } 169 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/POIMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | import com.flowpowered.math.vector.Vector2i; 28 | import com.flowpowered.math.vector.Vector3d; 29 | import de.bluecolored.bluemap.api.BlueMapMap; 30 | 31 | import java.util.*; 32 | 33 | @SuppressWarnings("FieldMayBeFinal") 34 | public class POIMarker extends DistanceRangedMarker implements DetailMarker, ElementMarker { 35 | 36 | private Set classes = new HashSet<>(); 37 | 38 | private String detail; 39 | 40 | private String icon; 41 | private Vector2i anchor; 42 | 43 | /** 44 | * Empty constructor for deserialization. 45 | */ 46 | @SuppressWarnings("unused") 47 | private POIMarker() { 48 | this("", Vector3d.ZERO); 49 | } 50 | 51 | /** 52 | * Creates a new {@link POIMarker} with the standard icon. 53 | * 54 | * @param label the label of the marker 55 | * @param position the coordinates of the marker 56 | * 57 | * @see #setLabel(String) 58 | * @see #setPosition(Vector3d) 59 | */ 60 | public POIMarker(String label, Vector3d position) { 61 | this(label, position, "assets/poi.svg", new Vector2i(25, 45)); 62 | } 63 | 64 | /** 65 | * Creates a new {@link POIMarker}. 66 | * 67 | * @param label the label of the marker 68 | * @param position the coordinates of the marker 69 | * @param iconAddress the html-content of the marker 70 | * @param anchor the anchor-point of the html-content 71 | * 72 | * @see #setLabel(String) 73 | * @see #setPosition(Vector3d) 74 | * @see #setIcon(String, Vector2i) 75 | */ 76 | public POIMarker(String label, Vector3d position, String iconAddress, Vector2i anchor) { 77 | super("poi", label, position); 78 | this.detail = Objects.requireNonNull(label, "label must not be null"); 79 | this.icon = Objects.requireNonNull(iconAddress, "iconAddress must not be null"); 80 | this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); 81 | } 82 | 83 | @Override 84 | public String getDetail() { 85 | return detail; 86 | } 87 | 88 | @Override 89 | public void setDetail(String detail) { 90 | this.detail = detail; 91 | } 92 | 93 | /** 94 | * Getter for the relative address of the icon used to display this {@link POIMarker} 95 | * @return the relative web-address of the icon 96 | */ 97 | public String getIconAddress() { 98 | return icon; 99 | } 100 | 101 | @Override 102 | public Vector2i getAnchor() { 103 | return anchor; 104 | } 105 | 106 | @Override 107 | public void setAnchor(Vector2i anchor) { 108 | this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); 109 | } 110 | 111 | /** 112 | * Sets the icon for this {@link POIMarker}. 113 | * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. 114 | * (See: {@link BlueMapMap#getAssetStorage()}) 115 | * @param anchorX the x-position of the position (in pixels) where the icon is anchored to the map 116 | * @param anchorY the y-position of the position (in pixels) where the icon is anchored to the map 117 | */ 118 | public void setIcon(String iconAddress, int anchorX, int anchorY) { 119 | setIcon(iconAddress, new Vector2i(anchorX, anchorY)); 120 | } 121 | 122 | /** 123 | * Sets the icon for this {@link POIMarker}. 124 | * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. 125 | * (See: {@link BlueMapMap#getAssetStorage()}) 126 | * @param anchor the position of the position (in pixels) where the icon is anchored to the map 127 | */ 128 | public void setIcon(String iconAddress, Vector2i anchor) { 129 | this.icon = Objects.requireNonNull(iconAddress, "iconAddress must not be null"); 130 | this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); 131 | } 132 | 133 | @Override 134 | public Collection getStyleClasses() { 135 | return Collections.unmodifiableCollection(this.classes); 136 | } 137 | 138 | @Override 139 | public void setStyleClasses(Collection styleClasses) { 140 | if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate())) 141 | throw new IllegalArgumentException("One of the provided style-classes has an invalid format!"); 142 | 143 | this.classes.clear(); 144 | this.classes.addAll(styleClasses); 145 | } 146 | 147 | @Override 148 | public void addStyleClasses(Collection styleClasses) { 149 | if (!styleClasses.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate())) 150 | throw new IllegalArgumentException("One of the provided style-classes has an invalid format!"); 151 | 152 | this.classes.addAll(styleClasses); 153 | } 154 | 155 | @Override 156 | public boolean equals(Object o) { 157 | if (this == o) return true; 158 | if (o == null || getClass() != o.getClass()) return false; 159 | if (!super.equals(o)) return false; 160 | 161 | POIMarker poiMarker = (POIMarker) o; 162 | 163 | if (!icon.equals(poiMarker.icon)) return false; 164 | return anchor.equals(poiMarker.anchor); 165 | } 166 | 167 | @Override 168 | public int hashCode() { 169 | int result = super.hashCode(); 170 | result = 31 * result + icon.hashCode(); 171 | result = 31 * result + anchor.hashCode(); 172 | return result; 173 | } 174 | 175 | /** 176 | * Creates a Builder for {@link POIMarker}s. 177 | * @return a new Builder 178 | */ 179 | public static Builder builder() { 180 | return new Builder(); 181 | } 182 | 183 | public static class Builder extends DistanceRangedMarker.Builder 184 | implements DetailMarker.Builder, ElementMarker.Builder { 185 | 186 | Set classes = new HashSet<>(); 187 | 188 | String detail; 189 | String icon; 190 | Vector2i anchor; 191 | 192 | @Override 193 | public Builder detail(String detail) { 194 | this.detail = detail; 195 | return this; 196 | } 197 | 198 | /** 199 | * Sets the icon for the {@link POIMarker}. 200 | * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. 201 | * (See: {@link BlueMapMap#getAssetStorage()}) 202 | * @param anchorX the x-position of the position (in pixels) where the icon is anchored to the map 203 | * @param anchorY the y-position of the position (in pixels) where the icon is anchored to the map 204 | * @return this builder for chaining 205 | */ 206 | public Builder icon(String iconAddress, int anchorX, int anchorY) { 207 | return icon(iconAddress, new Vector2i(anchorX, anchorY)); 208 | } 209 | 210 | /** 211 | * Sets the icon for the {@link POIMarker}. 212 | * @param iconAddress the web-address of the icon-image. Can be an absolute or relative. 213 | * (See: {@link BlueMapMap#getAssetStorage()}) 214 | * @param anchor the position of the position (in pixels) where the icon is anchored to the map 215 | * @return this builder for chaining 216 | */ 217 | public Builder icon(String iconAddress, Vector2i anchor) { 218 | this.icon = Objects.requireNonNull(iconAddress, "iconAddress must not be null"); 219 | this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); 220 | return this; 221 | } 222 | 223 | @Override 224 | public Builder anchor(Vector2i anchor) { 225 | this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); 226 | return this; 227 | } 228 | 229 | /** 230 | * The {@link POIMarker} will use the default icon. (See: {@link #icon(String, Vector2i)}) 231 | * @return this builder for chaining 232 | */ 233 | public Builder defaultIcon() { 234 | this.icon = null; 235 | this.anchor = null; 236 | return this; 237 | } 238 | 239 | @Override 240 | public Builder styleClasses(String... styleClasses) { 241 | Collection styleClassesCollection = Arrays.asList(styleClasses); 242 | if (!styleClassesCollection.stream().allMatch(STYLE_CLASS_PATTERN.asMatchPredicate())) 243 | throw new IllegalArgumentException("One of the provided style-classes has an invalid format!"); 244 | 245 | this.classes.addAll(styleClassesCollection); 246 | return this; 247 | } 248 | 249 | @Override 250 | public Builder clearStyleClasses() { 251 | this.classes.clear(); 252 | return this; 253 | } 254 | 255 | /** 256 | * Creates a new {@link POIMarker} with the current builder-settings.
257 | * The minimum required settings to build this marker are: 258 | *
    259 | *
  • {@link #setLabel(String)}
  • 260 | *
  • {@link #setPosition(Vector3d)}
  • 261 | *
262 | * @return The new {@link POIMarker}-instance 263 | */ 264 | public POIMarker build() { 265 | POIMarker marker = new POIMarker( 266 | checkNotNull(label, "label"), 267 | checkNotNull(position, "position") 268 | ); 269 | if (detail != null) marker.setDetail(detail); 270 | if (icon != null) marker.setIcon(icon, anchor); 271 | else if (anchor != null) marker.setAnchor(anchor); 272 | marker.setStyleClasses(classes); 273 | return build(marker); 274 | } 275 | 276 | } 277 | 278 | // ------ 279 | 280 | /** 281 | * @deprecated use {@link #builder()} instead. 282 | */ 283 | @Deprecated(forRemoval = true) 284 | public static Builder toBuilder() { 285 | return new Builder(); 286 | } 287 | 288 | } 289 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.markers; 26 | 27 | 28 | import com.flowpowered.math.vector.Vector2d; 29 | import com.flowpowered.math.vector.Vector3d; 30 | import de.bluecolored.bluemap.api.math.Color; 31 | import de.bluecolored.bluemap.api.math.Shape; 32 | 33 | import java.util.ArrayList; 34 | import java.util.Arrays; 35 | import java.util.Collection; 36 | import java.util.Objects; 37 | 38 | @SuppressWarnings("FieldMayBeFinal") 39 | public class ShapeMarker extends ObjectMarker { 40 | private static final Shape DEFAULT_SHAPE = Shape.createRect(0, 0, 1, 1); 41 | 42 | private Shape shape; 43 | private Collection holes = new ArrayList<>(); 44 | private float shapeY; 45 | private boolean depthTest = true; 46 | private int lineWidth = 2; 47 | private Color lineColor = new Color(255, 0, 0, 1f); 48 | private Color fillColor = new Color(200, 0, 0, 0.3f); 49 | 50 | /** 51 | * Empty constructor for deserialization. 52 | */ 53 | @SuppressWarnings("unused") 54 | private ShapeMarker() { 55 | this("", DEFAULT_SHAPE, 0); 56 | } 57 | 58 | /** 59 | * Creates a new {@link ShapeMarker}. 60 | *

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

61 | * 62 | * @param label the label of the marker 63 | * @param shape the {@link Shape} of the marker 64 | * @param shapeY the y-position of the shape 65 | * 66 | * @see #setLabel(String) 67 | * @see #setShape(Shape, float) 68 | */ 69 | public ShapeMarker(String label, Shape shape, float shapeY) { 70 | this(label, calculateShapeCenter(Objects.requireNonNull(shape, "shape must not be null"), shapeY), shape, shapeY); 71 | } 72 | 73 | /** 74 | * Creates a new {@link ShapeMarker}. 75 | *

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

77 | * 78 | * @param label the label of the marker 79 | * @param position the coordinates of the marker 80 | * @param shape the shape of the marker 81 | * @param shapeY the y-position of the shape 82 | * 83 | * @see #setLabel(String) 84 | * @see #setPosition(Vector3d) 85 | * @see #setShape(Shape, float) 86 | */ 87 | public ShapeMarker(String label, Vector3d position, Shape shape, float shapeY) { 88 | super("shape", label, position); 89 | this.shape = Objects.requireNonNull(shape, "shape must not be null"); 90 | this.shapeY = shapeY; 91 | } 92 | 93 | /** 94 | * Getter for {@link Shape} of this {@link ShapeMarker}. 95 | *

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

97 | * @return the {@link Shape} 98 | */ 99 | public Shape getShape() { 100 | return shape; 101 | } 102 | 103 | /** 104 | * Getter for the height (y-coordinate) of where the shape is displayed on the map. 105 | * @return the height of the shape on the map 106 | */ 107 | public float getShapeY() { 108 | return shapeY; 109 | } 110 | 111 | /** 112 | * Sets the {@link Shape} of this {@link ShapeMarker}. 113 | *

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

115 | * @param shape the new {@link Shape} 116 | * @param y the new height (y-coordinate) of the shape on the map 117 | * 118 | * @see #centerPosition() 119 | */ 120 | public void setShape(Shape shape, float y) { 121 | this.shape = Objects.requireNonNull(shape, "shape must not be null"); 122 | this.shapeY = y; 123 | } 124 | 125 | /** 126 | * Getter for the mutable collection of holes in this {@link ShapeMarker}. 127 | *

Any shape in this collection will be a hole in the main {@link Shape} of this marker

128 | * @return A mutable collection of hole-shapes 129 | */ 130 | public Collection getHoles() { 131 | return holes; 132 | } 133 | 134 | /** 135 | * Sets the position of this {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box). 136 | *

(Invoke this after changing the {@link Shape} to make sure the markers position gets updated as well)

137 | */ 138 | public void centerPosition() { 139 | setPosition(calculateShapeCenter(shape, shapeY)); 140 | } 141 | 142 | /** 143 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, 144 | * you'll only see the marker when it is not behind anything. 145 | * @return true if the depthTest is enabled 146 | */ 147 | public boolean isDepthTestEnabled() { 148 | return depthTest; 149 | } 150 | 151 | /** 152 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. If it is enabled, 153 | * you'll only see the marker when it is not behind anything. 154 | * @param enabled if the depth-test should be enabled for this {@link ShapeMarker} 155 | */ 156 | public void setDepthTestEnabled(boolean enabled) { 157 | this.depthTest = enabled; 158 | } 159 | 160 | /** 161 | * Getter for the width of the border-line of this {@link ShapeMarker}. 162 | * @return the width of the line in pixels 163 | */ 164 | public int getLineWidth() { 165 | return lineWidth; 166 | } 167 | 168 | /** 169 | * Sets the width of the border-line for this {@link ShapeMarker}. 170 | * @param width the new width in pixels 171 | */ 172 | public void setLineWidth(int width) { 173 | this.lineWidth = width; 174 | } 175 | 176 | /** 177 | * Getter for the {@link Color} of the border-line of the shape. 178 | * @return the line-color 179 | */ 180 | public Color getLineColor() { 181 | return lineColor; 182 | } 183 | 184 | /** 185 | * Sets the {@link Color} of the border-line of the shape. 186 | * @param color the new line-color 187 | */ 188 | public void setLineColor(Color color) { 189 | this.lineColor = Objects.requireNonNull(color, "color must not be null"); 190 | } 191 | 192 | /** 193 | * Getter for the fill-{@link Color} of the shape. 194 | * @return the fill-color 195 | */ 196 | public Color getFillColor() { 197 | return fillColor; 198 | } 199 | 200 | /** 201 | * Sets the fill-{@link Color} of the shape. 202 | * @param color the new fill-color 203 | */ 204 | public void setFillColor(Color color) { 205 | this.fillColor = Objects.requireNonNull(color, "color must not be null"); 206 | } 207 | 208 | /** 209 | * Sets the border- and fill- color. 210 | * @param lineColor the new border-color 211 | * @param fillColor the new fill-color 212 | * @see #setLineColor(Color) 213 | * @see #setFillColor(Color) 214 | */ 215 | public void setColors(Color lineColor, Color fillColor) { 216 | setLineColor(lineColor); 217 | setFillColor(fillColor); 218 | } 219 | 220 | @Override 221 | public boolean equals(Object o) { 222 | if (this == o) return true; 223 | if (o == null || getClass() != o.getClass()) return false; 224 | if (!super.equals(o)) return false; 225 | 226 | ShapeMarker that = (ShapeMarker) o; 227 | 228 | if (Float.compare(that.shapeY, shapeY) != 0) return false; 229 | if (depthTest != that.depthTest) return false; 230 | if (lineWidth != that.lineWidth) return false; 231 | if (!shape.equals(that.shape)) return false; 232 | if (!lineColor.equals(that.lineColor)) return false; 233 | return fillColor.equals(that.fillColor); 234 | } 235 | 236 | @Override 237 | public int hashCode() { 238 | int result = super.hashCode(); 239 | result = 31 * result + shape.hashCode(); 240 | result = 31 * result + (shapeY != 0.0f ? Float.floatToIntBits(shapeY) : 0); 241 | result = 31 * result + (depthTest ? 1 : 0); 242 | result = 31 * result + lineWidth; 243 | result = 31 * result + lineColor.hashCode(); 244 | result = 31 * result + fillColor.hashCode(); 245 | return result; 246 | } 247 | 248 | private static Vector3d calculateShapeCenter(Shape shape, float shapeY) { 249 | Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5); 250 | return new Vector3d(center.getX(), shapeY, center.getY()); 251 | } 252 | 253 | /** 254 | * Creates a Builder for {@link ShapeMarker}s. 255 | * @return a new Builder 256 | */ 257 | public static Builder builder() { 258 | return new Builder(); 259 | } 260 | 261 | public static class Builder extends ObjectMarker.Builder { 262 | 263 | Shape shape; 264 | float shapeY; 265 | Collection holes = new ArrayList<>(); 266 | Boolean depthTest; 267 | Integer lineWidth; 268 | Color lineColor; 269 | Color fillColor; 270 | 271 | /** 272 | * Sets the {@link Shape} of the {@link ShapeMarker}. 273 | *

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

275 | * @param shape the new {@link Shape} 276 | * @param y the new height (y-coordinate) of the shape on the map 277 | * @return this builder for chaining 278 | */ 279 | public Builder shape(Shape shape, float y) { 280 | this.shape = shape; 281 | this.shapeY = y; 282 | return this; 283 | } 284 | 285 | /** 286 | * Adds some hole-{@link Shape}s. 287 | * @param holes the additional holes 288 | * @return this builder for chaining 289 | */ 290 | public Builder holes(Shape... holes) { 291 | this.holes.addAll(Arrays.asList(holes)); 292 | return this; 293 | } 294 | 295 | /** 296 | * Removes all hole-shapes from this Builder. 297 | * @return this builder for chaining 298 | */ 299 | public Builder clearHoles() { 300 | this.holes.clear(); 301 | return this; 302 | } 303 | 304 | /** 305 | * Sets the position of the {@link ShapeMarker} to the center of the {@link Shape} (it's bounding box). 306 | * @return this builder for chaining 307 | */ 308 | public Builder centerPosition() { 309 | position(null); 310 | return this; 311 | } 312 | 313 | /** 314 | * If the depth-test is disabled, you can see the marker fully through all objects on the map. 315 | * If it is enabled, you'll only see the marker when it is not behind anything. 316 | * @param enabled if the depth-test should be enabled for the {@link ShapeMarker} 317 | * @return this builder for chaining 318 | */ 319 | public Builder depthTestEnabled(boolean enabled) { 320 | this.depthTest = enabled; 321 | return this; 322 | } 323 | 324 | /** 325 | * Sets the width of the border-line for the {@link ShapeMarker}. 326 | * @param width the new width in pixels 327 | * @return this builder for chaining 328 | */ 329 | public Builder lineWidth(int width) { 330 | this.lineWidth = width; 331 | return this; 332 | } 333 | 334 | /** 335 | * Sets the {@link Color} of the border-line of the shape. 336 | * @param color the new line-color 337 | * @return this builder for chaining 338 | */ 339 | public Builder lineColor(Color color) { 340 | this.lineColor = color; 341 | return this; 342 | } 343 | 344 | /** 345 | * Sets the fill-{@link Color} of the shape. 346 | * @param color the new fill-color 347 | * @return this builder for chaining 348 | */ 349 | public Builder fillColor(Color color) { 350 | this.fillColor = color; 351 | return this; 352 | } 353 | 354 | /** 355 | * Creates a new {@link ShapeMarker} with the current builder-settings.
356 | * The minimum required settings to build this marker are: 357 | *
    358 | *
  • {@link #label(String)}
  • 359 | *
  • {@link #shape(Shape, float)}
  • 360 | *
361 | * @return The new {@link ShapeMarker}-instance 362 | */ 363 | public ShapeMarker build() { 364 | ShapeMarker marker = new ShapeMarker( 365 | checkNotNull(label, "label"), 366 | checkNotNull(shape, "shape"), 367 | shapeY 368 | ); 369 | marker.getHoles().addAll(holes); 370 | if (depthTest != null) marker.setDepthTestEnabled(depthTest); 371 | if (lineWidth != null) marker.setLineWidth(lineWidth); 372 | if (lineColor != null) marker.setLineColor(lineColor); 373 | if (fillColor != null) marker.setFillColor(fillColor); 374 | return build(marker); 375 | } 376 | 377 | } 378 | 379 | } 380 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/math/Color.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.math; 26 | 27 | import java.util.Objects; 28 | 29 | public class Color { 30 | 31 | private final int r, g, b; 32 | private final float a; 33 | 34 | /** 35 | * Creates a new color with the given red, green and blue values. 36 | * 37 | * @param red the red value in range 0-255 38 | * @param green the green value in range 0-255 39 | * @param blue the blue value in range 0-255 40 | */ 41 | public Color(int red, int green, int blue) { 42 | this(red, green, blue, 1); 43 | } 44 | 45 | /** 46 | * Creates a new color with the given red, green, blue and alpha values. 47 | * 48 | * @param red the red value in range 0-255 49 | * @param green the green value in range 0-255 50 | * @param blue the blue value in range 0-255 51 | * @param alpha the alpha value in range 0-1 52 | */ 53 | public Color(int red, int green, int blue, float alpha) { 54 | this.r = red; 55 | this.g = green; 56 | this.b = blue; 57 | this.a = alpha; 58 | } 59 | 60 | /** 61 | * Creates a new color from the given integer in the format 0xAARRGGBB. 62 | * @param i the integer to create the color from 63 | */ 64 | public Color(int i) { 65 | this((i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF, ((i >> 24) & 0xFF) / 255f); 66 | } 67 | 68 | /** 69 | * Creates a new color from the given integer in the format 0xRRGGBB. 70 | * @param i the integer to create the color from 71 | * @param alpha the alpha value in range 0-1 72 | */ 73 | public Color(int i, float alpha) { 74 | this((i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF, alpha); 75 | } 76 | 77 | /** 78 | * Creates a new color from the given integer in the format 0xRRGGBB. 79 | * @param i the integer to create the color from 80 | * @param alpha the alpha value in range 0-255 81 | */ 82 | public Color(int i, int alpha) { 83 | this((i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF, (float) alpha / 255f); 84 | } 85 | 86 | /** 87 | * The value can be an integer in String-Format (see {@link #Color(int)}) or a string in hexadecimal format 88 | * prefixed with # (css-style: e.g. #f16 becomes #ff1166). 89 | * @param cssColorString The string to parse to a color 90 | * @throws NumberFormatException If the value is not formatted correctly. 91 | */ 92 | public Color(String cssColorString) { 93 | this(parseColorString(Objects.requireNonNull(cssColorString))); 94 | } 95 | 96 | /** 97 | * Getter for the red-component of the color. 98 | * @return the red-component of the color in range 0-255 99 | */ 100 | public int getRed() { 101 | return r; 102 | } 103 | 104 | /** 105 | * Getter for the green-component of the color. 106 | * @return the green-component of the color in range 0-255 107 | */ 108 | public int getGreen() { 109 | return g; 110 | } 111 | 112 | /** 113 | * Getter for the blue-component of the color. 114 | * @return the blue-component of the color in range 0-255 115 | */ 116 | public int getBlue() { 117 | return b; 118 | } 119 | 120 | /** 121 | * Getter for the alpha-component of the color. 122 | * @return the alpha-component of the color in range 0-1 123 | */ 124 | public float getAlpha() { 125 | return a; 126 | } 127 | 128 | private static int parseColorString(String value) { 129 | String val = value; 130 | if (val.charAt(0) == '#') { 131 | val = val.substring(1); 132 | if (val.length() == 3) val = val + "f"; 133 | if (val.length() == 4) val = "" + 134 | val.charAt(0) + val.charAt(0) + val.charAt(1) + val.charAt(1) + 135 | val.charAt(2) + val.charAt(2) + val.charAt(3) + val.charAt(3); 136 | if (val.length() == 6) val = val + "ff"; 137 | if (val.length() != 8) throw new NumberFormatException("Invalid color format: '" + value + "'!"); 138 | val = val.substring(6, 8) + val.substring(0, 6); // move alpha to front 139 | return Integer.parseUnsignedInt(val, 16); 140 | } 141 | 142 | return Integer.parseInt(val); 143 | } 144 | 145 | @Override 146 | public boolean equals(Object o) { 147 | if (this == o) return true; 148 | if (o == null || getClass() != o.getClass()) return false; 149 | 150 | Color color = (Color) o; 151 | 152 | if (r != color.r) return false; 153 | if (g != color.g) return false; 154 | if (b != color.b) return false; 155 | return Float.compare(color.a, a) == 0; 156 | } 157 | 158 | @Override 159 | public int hashCode() { 160 | int result = r; 161 | result = 31 * result + g; 162 | result = 31 * result + b; 163 | result = 31 * result + (a != +0.0f ? Float.floatToIntBits(a) : 0); 164 | return result; 165 | } 166 | 167 | @Override 168 | public String toString() { 169 | return "Color{" + 170 | "r=" + r + 171 | ", g=" + g + 172 | ", b=" + b + 173 | ", a=" + a + 174 | '}'; 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/math/Line.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.math; 26 | 27 | import com.flowpowered.math.vector.Vector3d; 28 | import org.jetbrains.annotations.Nullable; 29 | 30 | import java.util.ArrayList; 31 | import java.util.Arrays; 32 | import java.util.Collection; 33 | import java.util.List; 34 | 35 | /** 36 | * A line consisting of 2 or more {@link Vector3d}-points. 37 | */ 38 | public class Line { 39 | 40 | private final Vector3d[] points; 41 | 42 | @Nullable 43 | private Vector3d min = null, max = null; 44 | 45 | public Line(Vector3d... points) { 46 | if (points.length < 2) throw new IllegalArgumentException("A line has to have at least 2 points!"); 47 | this.points = points; 48 | } 49 | 50 | public Line(Collection points) { 51 | this(points.toArray(Vector3d[]::new)); 52 | } 53 | 54 | /** 55 | * Getter for the amount of points in this line. 56 | * @return the amount of points 57 | */ 58 | public int getPointCount() { 59 | return points.length; 60 | } 61 | 62 | /** 63 | * Getter for the point at the given index. 64 | * @param i the index 65 | * @return the point at the given index 66 | */ 67 | public Vector3d getPoint(int i) { 68 | return points[i]; 69 | } 70 | 71 | /** 72 | * Getter for a copy of the points array.
73 | * (A line is immutable once created) 74 | * @return the points of this line 75 | */ 76 | public Vector3d[] getPoints() { 77 | return Arrays.copyOf(points, points.length); 78 | } 79 | 80 | /** 81 | * Calculates and returns the minimum corner of the axis-aligned-bounding-box of this line. 82 | * @return the min of the AABB of this line 83 | */ 84 | public Vector3d getMin() { 85 | if (this.min == null) { 86 | Vector3d min = points[0]; 87 | for (int i = 1; i < points.length; i++) { 88 | min = min.min(points[i]); 89 | } 90 | this.min = min; 91 | } 92 | return this.min; 93 | } 94 | 95 | /** 96 | * Calculates and returns the maximum corner of the axis-aligned-bounding-box of this line. 97 | * @return the max of the AABB of this line 98 | */ 99 | public Vector3d getMax() { 100 | if (this.max == null) { 101 | Vector3d max = points[0]; 102 | for (int i = 1; i < points.length; i++) { 103 | max = max.max(points[i]); 104 | } 105 | this.max = max; 106 | } 107 | return this.max; 108 | } 109 | 110 | @Override 111 | public boolean equals(Object o) { 112 | if (this == o) return true; 113 | if (o == null || getClass() != o.getClass()) return false; 114 | 115 | Line line = (Line) o; 116 | 117 | return Arrays.equals(points, line.points); 118 | } 119 | 120 | @Override 121 | public int hashCode() { 122 | return Arrays.hashCode(points); 123 | } 124 | 125 | /** 126 | * Creates a builder to build {@link Line}s. 127 | * @return a new builder 128 | */ 129 | public static Builder builder() { 130 | return new Builder(); 131 | } 132 | 133 | public static class Builder { 134 | 135 | List points; 136 | 137 | public Builder() { 138 | this.points = new ArrayList<>(); 139 | } 140 | 141 | /** 142 | * Adds a point to the end of line. 143 | * @param point the point to be added. 144 | * @return this builder for chaining 145 | */ 146 | public Builder addPoint(Vector3d point) { 147 | this.points.add(point); 148 | return this; 149 | } 150 | 151 | /** 152 | * Adds multiple points to the end of line. 153 | * @param points the points to be added. 154 | * @return this builder for chaining 155 | */ 156 | public Builder addPoints(Vector3d... points) { 157 | this.points.addAll(Arrays.asList(points)); 158 | return this; 159 | } 160 | 161 | /** 162 | * Adds multiple points to the end of line. 163 | * @param points the points to be added. 164 | * @return this builder for chaining 165 | */ 166 | public Builder addPoints(Collection points) { 167 | this.points.addAll(points); 168 | return this; 169 | } 170 | 171 | /** 172 | * Builds a new {@link Line} with the points set in this builder.
173 | * There need to be at least 2 points to build a {@link Line}. 174 | * @return the new {@link Line} 175 | * @throws IllegalStateException if there are less than 2 points added to this builder 176 | */ 177 | public Line build() { 178 | if (points.size() < 2) throw new IllegalStateException("A line has to have at least 2 points!"); 179 | return new Line(points); 180 | } 181 | 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/math/Shape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.math; 26 | 27 | import com.flowpowered.math.vector.Vector2d; 28 | import org.jetbrains.annotations.Nullable; 29 | 30 | import java.util.ArrayList; 31 | import java.util.Arrays; 32 | import java.util.Collection; 33 | import java.util.List; 34 | 35 | /** 36 | * A shape consisting of 3 or more {@link Vector2d}-points on a plane. 37 | */ 38 | public class Shape { 39 | 40 | private final Vector2d[] points; 41 | 42 | @Nullable 43 | private Vector2d min = null, max = null; 44 | 45 | public Shape(Vector2d... points) { 46 | if (points.length < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!"); 47 | this.points = points; 48 | } 49 | 50 | public Shape(Collection points) { 51 | this(points.toArray(Vector2d[]::new)); 52 | } 53 | 54 | /** 55 | * Getter for the amount of points in this shape. 56 | * @return the amount of points 57 | */ 58 | public int getPointCount() { 59 | return points.length; 60 | } 61 | 62 | /** 63 | * Getter for the point at the given index. 64 | * @param i the index 65 | * @return the point at the given index 66 | */ 67 | public Vector2d getPoint(int i) { 68 | return points[i]; 69 | } 70 | 71 | /** 72 | * Getter for a copy of the points array.
73 | * (A shape is immutable once created) 74 | * @return the points of this shape 75 | */ 76 | public Vector2d[] getPoints() { 77 | return Arrays.copyOf(points, points.length); 78 | } 79 | 80 | /** 81 | * Calculates and returns the minimum corner of the axis-aligned-bounding-box of this shape. 82 | * @return the min of the AABB of this shape 83 | */ 84 | public Vector2d getMin() { 85 | if (this.min == null) { 86 | Vector2d min = points[0]; 87 | for (int i = 1; i < points.length; i++) { 88 | min = min.min(points[i]); 89 | } 90 | this.min = min; 91 | } 92 | return this.min; 93 | } 94 | 95 | /** 96 | * Calculates and returns the maximum corner of the axis-aligned-bounding-box of this shape. 97 | * @return the max of the AABB of this shape 98 | */ 99 | public Vector2d getMax() { 100 | if (this.max == null) { 101 | Vector2d max = points[0]; 102 | for (int i = 1; i < points.length; i++) { 103 | max = max.max(points[i]); 104 | } 105 | this.max = max; 106 | } 107 | return this.max; 108 | } 109 | 110 | @Override 111 | public boolean equals(Object o) { 112 | if (this == o) return true; 113 | if (o == null || getClass() != o.getClass()) return false; 114 | 115 | Shape shape = (Shape) o; 116 | 117 | return Arrays.equals(points, shape.points); 118 | } 119 | 120 | @Override 121 | public int hashCode() { 122 | return Arrays.hashCode(points); 123 | } 124 | 125 | /** 126 | * Creates a {@link Shape} representing a rectangle spanning over pos1 and pos2 127 | * @param pos1 one corner of the rectangle 128 | * @param pos2 the opposite corner of the rectangle 129 | * @return the created {@link Shape} 130 | */ 131 | public static Shape createRect(Vector2d pos1, Vector2d pos2) { 132 | Vector2d min = pos1.min(pos2); 133 | Vector2d max = pos1.max(pos2); 134 | 135 | return new Shape( 136 | min, 137 | new Vector2d(max.getX(), min.getY()), 138 | max, 139 | new Vector2d(min.getX(), max.getY()) 140 | ); 141 | } 142 | 143 | /** 144 | * Creates a {@link Shape} representing a rectangle spanning over two points 145 | * @param x1 x position of one corner of the rectangle 146 | * @param y1 y position of one corner of the rectangle 147 | * @param x2 x position of the opposite corner of the rectangle 148 | * @param y2 y position of the opposite corner of the rectangle 149 | * @return the created {@link Shape} 150 | */ 151 | public static Shape createRect(double x1, double y1, double x2, double y2) { 152 | return createRect(new Vector2d(x1, y1), new Vector2d(x2, y2)); 153 | } 154 | 155 | /** 156 | * Creates a {@link Shape} representing an ellipse. 157 | * @param centerPos the center of the ellipse 158 | * @param radiusX the x radius of the ellipse 159 | * @param radiusY the y radius of the ellipse 160 | * @param points the amount of points used to create the ellipse (at least 3) 161 | * @return the created {@link Shape} 162 | */ 163 | public static Shape createEllipse(Vector2d centerPos, double radiusX, double radiusY, int points) { 164 | if (points < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!"); 165 | 166 | Vector2d[] pointArray = new Vector2d[points]; 167 | double segmentAngle = 2 * Math.PI / points; 168 | double angle = 0d; 169 | for (int i = 0; i < points; i++) { 170 | pointArray[i] = centerPos.add(Math.sin(angle) * radiusX, Math.cos(angle) * radiusY); 171 | angle += segmentAngle; 172 | } 173 | 174 | return new Shape(pointArray); 175 | } 176 | 177 | /** 178 | * Creates a {@link Shape} representing an ellipse. 179 | * @param centerX the x-position of the center of the ellipse 180 | * @param centerY the y-position of the center of the ellipse 181 | * @param radiusX the x radius of the ellipse 182 | * @param radiusY the y radius of the ellipse 183 | * @param points the amount of points used to create the ellipse (at least 3) 184 | * @return the created {@link Shape} 185 | */ 186 | public static Shape createEllipse(double centerX, double centerY, double radiusX, double radiusY, int points) { 187 | return createEllipse(new Vector2d(centerX, centerY), radiusX, radiusY, points); 188 | } 189 | 190 | /** 191 | * Creates a {@link Shape} representing a circle. 192 | * @param centerPos the center of the circle 193 | * @param radius the radius of the circle 194 | * @param points the amount of points used to create the circle (at least 3) 195 | * @return the created {@link Shape} 196 | */ 197 | public static Shape createCircle(Vector2d centerPos, double radius, int points) { 198 | return createEllipse(centerPos, radius, radius, points); 199 | } 200 | 201 | /** 202 | * Creates a {@link Shape} representing a circle. 203 | * @param centerX the x-position of the center of the circle 204 | * @param centerY the y-position of the center of the circle 205 | * @param radius the radius of the circle 206 | * @param points the amount of points used to create the circle (at least 3) 207 | * @return the created {@link Shape} 208 | */ 209 | public static Shape createCircle(double centerX, double centerY, double radius, int points) { 210 | return createCircle(new Vector2d(centerX, centerY), radius, points); 211 | } 212 | 213 | /** 214 | * Creates a builder to build {@link Shape}s. 215 | * @return a new builder 216 | */ 217 | public static Builder builder() { 218 | return new Builder(); 219 | } 220 | 221 | public static class Builder { 222 | 223 | List points; 224 | 225 | public Builder() { 226 | this.points = new ArrayList<>(); 227 | } 228 | 229 | /** 230 | * Adds a point to the end of line. 231 | * @param point the point to be added. 232 | * @return this builder for chaining 233 | */ 234 | public Builder addPoint(Vector2d point) { 235 | this.points.add(point); 236 | return this; 237 | } 238 | 239 | /** 240 | * Adds multiple points to the end of line. 241 | * @param points the points to be added. 242 | * @return this builder for chaining 243 | */ 244 | public Builder addPoints(Vector2d... points) { 245 | this.points.addAll(Arrays.asList(points)); 246 | return this; 247 | } 248 | 249 | /** 250 | * Adds multiple points to the end of line. 251 | * @param points the points to be added. 252 | * @return this builder for chaining 253 | */ 254 | public Builder addPoints(Collection points) { 255 | this.points.addAll(points); 256 | return this; 257 | } 258 | 259 | /** 260 | * Builds a new {@link Shape} with the points set in this builder.
261 | * There need to be at least 3 points to build a {@link Shape}. 262 | * @return the new {@link Shape} 263 | * @throws IllegalStateException if there are less than 3 points added to this builder 264 | */ 265 | public Shape build() { 266 | if (points.size() < 3) throw new IllegalStateException("A shape has to have at least 3 points!"); 267 | return new Shape(points); 268 | } 269 | 270 | } 271 | 272 | } 273 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/plugin/PlayerIconFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.plugin; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.util.UUID; 29 | import java.util.function.BiFunction; 30 | 31 | @FunctionalInterface 32 | public interface PlayerIconFactory extends BiFunction { 33 | 34 | /** 35 | * Takes a players UUID and skin-image and creates an icon 36 | * @param playerUuid the players UUID 37 | * @param playerSkin the input image 38 | * @return a new {@link BufferedImage} generated based on the input image 39 | */ 40 | BufferedImage apply(UUID playerUuid, BufferedImage playerSkin); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/plugin/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.plugin; 26 | 27 | @SuppressWarnings("unused") 28 | public interface Plugin { 29 | 30 | /** 31 | * Get the {@link SkinProvider} that bluemap is using to fetch player-skins 32 | * @return the {@link SkinProvider} instance bluemap is using 33 | */ 34 | SkinProvider getSkinProvider(); 35 | 36 | /** 37 | * Sets the {@link SkinProvider} that bluemap will use to fetch new player-skins. 38 | * @param skinProvider The new {@link SkinProvider} bluemap should use 39 | */ 40 | void setSkinProvider(SkinProvider skinProvider); 41 | 42 | /** 43 | * Get the {@link PlayerIconFactory} that bluemap is using to convert a player-skin into the icon-image that is used 44 | * for the Player-Markers 45 | * @return The {@link PlayerIconFactory} bluemap uses to convert skins into player-marker icons 46 | */ 47 | PlayerIconFactory getPlayerMarkerIconFactory(); 48 | 49 | /** 50 | * Set the {@link PlayerIconFactory} that bluemap will use to convert a player-skin into the icon-image that is used 51 | * for the Player-Markers 52 | * @param playerMarkerIconFactory The {@link PlayerIconFactory} bluemap uses to convert skins into player-marker icons 53 | */ 54 | void setPlayerMarkerIconFactory(PlayerIconFactory playerMarkerIconFactory); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/de/bluecolored/bluemap/api/plugin/SkinProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of BlueMap, licensed under the MIT License (MIT). 3 | * 4 | * Copyright (c) Blue (Lukas Rieger) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | package de.bluecolored.bluemap.api.plugin; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | import java.util.Optional; 30 | import java.util.UUID; 31 | 32 | /** 33 | * A skin-provider capable of loading minecraft player-skins for a given UUID 34 | */ 35 | @FunctionalInterface 36 | public interface SkinProvider { 37 | 38 | /** 39 | * Attempts to load a minecraft-skin from this skin-provider. 40 | * @return an {@link Optional} containing a {@link BufferedImage} with the skin-image or an empty Optional if there is no 41 | * skin for this UUID 42 | * @throws IOException if something went wrong trying to load the skin 43 | */ 44 | Optional load(UUID playerUUID) throws IOException; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/resources/de/bluecolored/bluemap/api/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "${version}", 3 | "git-hash": "${gitHash}" 4 | } --------------------------------------------------------------------------------