Skip to content

Commit 6e9415e

Browse files
committed
First changes towards API 2
1 parent 938621d commit 6e9415e

23 files changed

+841
-911
lines changed

build.gradle.kts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
2-
java
3-
`java-library`
4-
id("com.diffplug.spotless") version "6.1.2"
2+
java
3+
`java-library`
4+
id("com.diffplug.spotless") version "6.1.2"
55
}
66

77
group = "de.bluecolored.bluemap.api"
@@ -11,46 +11,47 @@ version = apiVersion
1111

1212
val javaTarget = 11
1313
java {
14-
sourceCompatibility = JavaVersion.toVersion(javaTarget)
15-
targetCompatibility = JavaVersion.toVersion(javaTarget)
14+
sourceCompatibility = JavaVersion.toVersion(javaTarget)
15+
targetCompatibility = JavaVersion.toVersion(javaTarget)
1616
}
1717

1818
repositories {
19-
mavenCentral()
19+
mavenCentral()
2020
}
2121

2222
dependencies {
23-
api ("com.flowpowered:flow-math:1.0.3")
23+
api ("com.flowpowered:flow-math:1.0.3")
24+
implementation ("com.google.code.gson:gson:2.8.0")
25+
compileOnly ("org.jetbrains:annotations:23.0.0")
2426
}
2527

2628
spotless {
27-
java {
28-
target ("src/*/java/**/*.java")
29+
java {
30+
target ("src/*/java/**/*.java")
2931

30-
licenseHeaderFile("LICENSE_HEADER")
31-
indentWithSpaces()
32-
trimTrailingWhitespace()
33-
}
32+
licenseHeaderFile("LICENSE_HEADER")
33+
indentWithSpaces()
34+
trimTrailingWhitespace()
35+
}
3436
}
3537

3638
tasks.withType(JavaCompile::class).configureEach {
37-
options.apply {
38-
encoding = "utf-8"
39-
}
39+
options.apply {
40+
encoding = "utf-8"
41+
}
4042
}
4143

4244
tasks.withType(AbstractArchiveTask::class).configureEach {
43-
isReproducibleFileOrder = true
44-
isPreserveFileTimestamps = false
45+
isReproducibleFileOrder = true
46+
isPreserveFileTimestamps = false
4547
}
4648

4749
tasks.javadoc {
48-
options {
49-
(this as? StandardJavadocDocletOptions)?.apply {
50-
links(
51-
"https://docs.oracle.com/javase/8/docs/api/",
52-
"https://javadoc.io/doc/com.flowpowered/flow-math/1.0.3/"
53-
)
54-
}
55-
}
50+
options {
51+
(this as? StandardJavadocDocletOptions)?.apply {
52+
links(
53+
"https://docs.oracle.com/javase/8/docs/api/"
54+
)
55+
}
56+
}
5657
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
org.gradle.jvmargs=-Xmx3G
22
org.gradle.daemon=false
33

4-
apiVersion=1.7.0
4+
apiVersion=2.0.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java

Lines changed: 54 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
*/
2525
package de.bluecolored.bluemap.api;
2626

27-
import com.flowpowered.math.vector.Vector2i;
28-
import de.bluecolored.bluemap.api.marker.Marker;
29-
import de.bluecolored.bluemap.api.marker.MarkerAPI;
30-
import de.bluecolored.bluemap.api.renderer.RenderAPI;
31-
32-
import java.awt.image.BufferedImage;
3327
import java.io.IOException;
28+
import java.io.InputStream;
29+
import java.net.URL;
3430
import java.nio.file.Path;
3531
import java.util.*;
3632
import java.util.concurrent.ExecutionException;
@@ -41,27 +37,48 @@
4137
* <p>This API is thread-save, so you <b>can</b> use it async, off the main-server-thread, to save performance!</p>
4238
*/
4339
public abstract class BlueMapAPI {
44-
private static BlueMapAPI instance;
4540

46-
@Deprecated
47-
private static final Collection<BlueMapAPIListener> listener = new HashSet<>(2);
41+
@SuppressWarnings("unused")
42+
private static final String VERSION, GIT_HASH, GIT_CLEAN;
43+
static {
44+
String version = "DEV", gitHash = "DEV", gitClean = "DEV";
45+
URL url = BlueMapAPI.class.getResource("/de/bluecolored/bluemap/api/version");
46+
if (url != null) {
47+
try (InputStream in = url.openStream(); Scanner scanner = new Scanner(in)) {
48+
version = scanner.nextLine();
49+
gitHash = scanner.nextLine();
50+
gitClean = scanner.nextLine();
51+
} catch (IOException ex) {
52+
System.err.println("Failed to load version from resources!");
53+
ex.printStackTrace();
54+
}
55+
}
56+
57+
if (version.equals("${version}")) version = "DEV";
58+
if (gitHash.equals("${gitHash}")) version = "DEV";
59+
if (gitClean.equals("${gitClean}")) version = "DEV";
60+
61+
VERSION = version;
62+
GIT_HASH = gitHash;
63+
GIT_CLEAN = gitClean;
64+
}
65+
66+
private static BlueMapAPI instance;
4867

4968
private static final Collection<Consumer<BlueMapAPI>> onEnableConsumers = new HashSet<>(2);
5069
private static final Collection<Consumer<BlueMapAPI>> onDisableConsumers = new HashSet<>(2);
5170

5271
/**
53-
* Getter for the {@link RenderAPI}.
54-
* @return the {@link RenderAPI}
72+
* Getter for the {@link RenderManager}.
73+
* @return the {@link RenderManager}
5574
*/
56-
public abstract RenderAPI getRenderAPI();
75+
public abstract RenderManager getRenderManager();
5776

5877
/**
59-
* Getter for the {@link MarkerAPI}.<br>
60-
* Calling this gives you a fresh loaded {@link MarkerAPI}, so you don't have to call {@link MarkerAPI#load()} right away!
61-
* @return the {@link MarkerAPI}
62-
* @throws IOException if there was an IOException loading the marker.json
78+
* Getter for the {@link WebApp}.
79+
* @return the {@link WebApp}
6380
*/
64-
public abstract MarkerAPI getMarkerAPI() throws IOException;
81+
public abstract WebApp getWebApp();
6582

6683
/**
6784
* Getter for all {@link BlueMapMap}s loaded by BlueMap.
@@ -76,17 +93,23 @@ public abstract class BlueMapAPI {
7693
public abstract Collection<BlueMapWorld> getWorlds();
7794

7895
/**
79-
* Getter for a {@link BlueMapWorld} loaded by BlueMap with the given {@link UUID}.
80-
*
81-
* <p><i>See the documentation of {@link BlueMapWorld#getUuid()} for more information about the nature of the worlds {@link UUID}s!</i></p>
82-
*
83-
* @see BlueMapWorld#getUuid()
84-
*
85-
* @param uuid the {@link UUID} of the world
96+
* Getter for a {@link BlueMapWorld} loaded by BlueMap.
8697
*
98+
* @param world Any object that BlueMap can use to identify a world.
99+
* <p>
100+
* <b>This could be:</b>
101+
* <ul>
102+
* <li>A {@link String} that is the id of the world</li>
103+
* <li>A {@link Path} that is the path to the world-folder</li>
104+
* <li>A Resource-Key object, {@link UUID} or anything that your platform uses to identify worlds</li>
105+
* <li>The actual world-object, any object directly representing the a world on your platform</li>
106+
* </ul>
107+
* <i>("Platform" here stands for the mod/plugin-loader or server-implementation you are using,
108+
* e.g. Spigot, Forge, Fabric or Sponge)</i>
109+
* </p>
87110
* @return an {@link Optional} with the {@link BlueMapWorld} if it exists
88111
*/
89-
public abstract Optional<BlueMapWorld> getWorld(UUID uuid);
112+
public abstract Optional<BlueMapWorld> getWorld(Object world);
90113

91114
/**
92115
* Getter for a {@link BlueMapMap} loaded by BlueMap with the given id.
@@ -95,69 +118,18 @@ public abstract class BlueMapAPI {
95118
*/
96119
public abstract Optional<BlueMapMap> getMap(String id);
97120

98-
/**
99-
* Creates an image-file with the given {@link BufferedImage} somewhere in the web-root, so it can be used in the web-app (e.g. for {@link Marker}-icons).
100-
*
101-
* <p>The given <code>path</code> is used as file-name and (separated with '/') optional folders to organize the image-files. Do NOT include the file-ending! (e.g. <code>"someFolder/somePOIIcon"</code> will result in a file "somePOIIcon.png" in a folder "someFolder").</p>
102-
* <p>If the image file with the given path already exists, it will be replaced.</p>
103-
*
104-
* @param image the image to create
105-
* @param path the path/name of this image, the separator-char is '/'
106-
* @return the relative address of the image in the web-app,
107-
* which can be used as it is e.g. in the {@link de.bluecolored.bluemap.api.marker.POIMarker#setIcon(String, Vector2i)} method
108-
* @throws IOException If an {@link IOException} is thrown while writing the image
109-
*/
110-
public abstract String createImage(BufferedImage image, String path) throws IOException;
111-
112-
/**
113-
* Lists all images that are available. This includes all images previously created with the {@link #createImage(BufferedImage, String)}
114-
* function, but might include more.
115-
* @return A map of available images where:
116-
* <ul>
117-
* <li>the <b>key</b> is the image path how it would be used in the "path" parameter of the {@link #createImage(BufferedImage, String)} method</li>
118-
* <li>and the <b>value</b> is the relative address of the image. The same ones that are returned from the {@link #createImage(BufferedImage, String)} method</li>
119-
* </ul>
120-
* @throws IOException If an {@link IOException} is thrown while reading the images
121-
*/
122-
public abstract Map<String, String> availableImages() throws IOException;
123-
124-
/**
125-
* Getter for the configured web-root folder
126-
* @return The {@link Path} of the web-root folder
127-
*/
128-
public abstract Path getWebRoot();
129-
130121
/**
131122
* Getter for the installed BlueMap version
132123
* @return the version-string
133124
*/
134125
public abstract String getBlueMapVersion();
135126

136127
/**
137-
* Register a listener that will be called when the API enables/disables
138-
* @param listener the {@link BlueMapAPIListener}
139-
*
140-
* @deprecated Implementing {@link BlueMapAPIListener} can cause a ClassNotFoundException when you soft-depend on BlueMap and your plugin/mod gets used without BlueMap.
141-
* Use {@link BlueMapAPI#onEnable(Consumer)} and {@link BlueMapAPI#onDisable(Consumer)} instead.
142-
*/
143-
@Deprecated
144-
public static synchronized void registerListener(BlueMapAPIListener listener) {
145-
BlueMapAPI.listener.add(listener);
146-
if (BlueMapAPI.instance != null) listener.onEnable(BlueMapAPI.instance);
147-
}
148-
149-
/**
150-
* Removes/Unregisters a previously registered listener
151-
* @param listener the {@link BlueMapAPIListener} instance that has been registered previously
152-
*
153-
* @return <code>true</code> if a listener was removed as a result of this call
154-
*
155-
* @deprecated Implementing {@link BlueMapAPIListener} can cause a ClassNotFoundException when you soft-depend on BlueMap and your plugin/mod gets used without BlueMap.
156-
* Use {@link BlueMapAPI#onEnable(Consumer)} and {@link BlueMapAPI#onDisable(Consumer)} instead.
128+
* Getter for the installed BlueMapAPI version
129+
* @return the version-string
157130
*/
158-
@Deprecated
159-
public static synchronized boolean unregisterListener(BlueMapAPIListener listener) {
160-
return BlueMapAPI.listener.remove(listener);
131+
public String getAPIVersion() {
132+
return VERSION;
161133
}
162134

163135
/**
@@ -206,9 +178,8 @@ public static synchronized boolean unregisterListener(Consumer<BlueMapAPI> consu
206178
* Used by BlueMap to register the API and call the listeners properly.
207179
* @param instance the {@link BlueMapAPI}-instance
208180
* @return <code>true</code> if the instance has been registered, <code>false</code> if there already was an instance registered
209-
* @throws ExecutionException if a {@link BlueMapAPIListener} threw an exception during the registration
181+
* @throws ExecutionException if a listener threw an exception during the registration
210182
*/
211-
@SuppressWarnings("deprecation")
212183
protected static synchronized boolean registerInstance(BlueMapAPI instance) throws ExecutionException {
213184
if (BlueMapAPI.instance != null) return false;
214185

@@ -224,15 +195,6 @@ protected static synchronized boolean registerInstance(BlueMapAPI instance) thro
224195
}
225196
}
226197

227-
// backwards compatibility
228-
for (BlueMapAPIListener listener : BlueMapAPI.listener) {
229-
try {
230-
listener.onEnable(BlueMapAPI.instance);
231-
} catch (Throwable ex) {
232-
thrownExceptions.add(ex);
233-
}
234-
}
235-
236198
if (!thrownExceptions.isEmpty()) {
237199
ExecutionException ex = new ExecutionException(thrownExceptions.get(0));
238200
for (int i = 1; i < thrownExceptions.size(); i++) {
@@ -248,9 +210,8 @@ protected static synchronized boolean registerInstance(BlueMapAPI instance) thro
248210
* Used by BlueMap to unregister the API and call the listeners properly.
249211
* @param instance the {@link BlueMapAPI} instance
250212
* @return <code>true</code> if the instance was unregistered, <code>false</code> if there was no or an other instance registered
251-
* @throws ExecutionException if a {@link BlueMapAPIListener} threw an exception during the un-registration
213+
* @throws ExecutionException if a listener threw an exception during the un-registration
252214
*/
253-
@SuppressWarnings("deprecation")
254215
protected static synchronized boolean unregisterInstance(BlueMapAPI instance) throws ExecutionException {
255216
if (BlueMapAPI.instance != instance) return false;
256217

@@ -264,15 +225,6 @@ protected static synchronized boolean unregisterInstance(BlueMapAPI instance) th
264225
}
265226
}
266227

267-
// backwards compatibility
268-
for (BlueMapAPIListener listener : BlueMapAPI.listener) {
269-
try {
270-
listener.onDisable(BlueMapAPI.instance);
271-
} catch (Exception ex) {
272-
thrownExceptions.add(ex);
273-
}
274-
}
275-
276228
BlueMapAPI.instance = null;
277229

278230
if (!thrownExceptions.isEmpty()) {

src/main/java/de/bluecolored/bluemap/api/BlueMapAPIListener.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)