Skip to content

Commit 29a99a9

Browse files
committed
Add MarkerAPI and rename the Renderer to RenderAPI
1 parent 1d7495d commit 29a99a9

File tree

8 files changed

+790
-8
lines changed

8 files changed

+790
-8
lines changed

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

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

27+
import java.awt.image.BufferedImage;
28+
import java.io.IOException;
2729
import java.util.ArrayList;
2830
import java.util.Collection;
2931
import java.util.Optional;
3032
import java.util.UUID;
3133

34+
import de.bluecolored.bluemap.api.marker.Marker;
35+
import de.bluecolored.bluemap.api.marker.MarkerAPI;
3236
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
3337
import de.bluecolored.bluemap.api.renderer.BlueMapWorld;
34-
import de.bluecolored.bluemap.api.renderer.Renderer;
38+
import de.bluecolored.bluemap.api.renderer.RenderAPI;
3539

40+
/**
41+
* An API to control the running instance of BlueMap.
42+
* <p>This API is thread-save, so you <b>can</b> use it async, off the main-server-thread, to save performance!</p>
43+
*/
3644
public abstract class BlueMapAPI {
3745
private static BlueMapAPI instance;
3846
private static Collection<BlueMapAPIListener> listener = new ArrayList<>();
3947

4048
/**
41-
* Getter for the {@link Renderer} instance.
42-
* @return the {@link Renderer}
49+
* Getter for the {@link RenderAPI}.
50+
* @return the {@link RenderAPI}
4351
*/
44-
public abstract Renderer getRenderer();
52+
public abstract RenderAPI getRenderAPI();
53+
54+
/**
55+
* Getter for the {@link MarkerAPI}.<br>
56+
* Calling this gives you a fresh loaded {@link MarkerAPI}, so you don't have to call {@link MarkerAPI#load()} right away!
57+
* @return the {@link MarkerAPI}
58+
*/
59+
public abstract MarkerAPI getMarkerAPI() throws IOException;
4560

4661
/**
4762
* Getter for all {@link BlueMapMap}s loaded by BlueMap.
@@ -75,6 +90,18 @@ public abstract class BlueMapAPI {
7590
*/
7691
public abstract Optional<BlueMapMap> getMap(String id);
7792

93+
/**
94+
* 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).
95+
*
96+
* <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>
97+
* <p>If the image file with the given path already exists, it will be replaced.</p>
98+
*
99+
* @param image the image to create
100+
* @param path the path/name of this image, the separator-char is '/'
101+
* @return the relative address of the image in the web-app
102+
*/
103+
public abstract String createImage(BufferedImage image, String path);
104+
78105
/**
79106
* Getter for the installed BlueMap version
80107
* @return the version-string
@@ -132,7 +159,7 @@ protected static synchronized boolean unregisterInstance(BlueMapAPI instance) {
132159

133160
for (BlueMapAPIListener listener : BlueMapAPI.listener) {
134161
listener.onDisable(BlueMapAPI.instance);
135-
}
162+
}
136163

137164
BlueMapAPI.instance = null;
138165

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
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.marker;
26+
27+
import java.util.Optional;
28+
29+
import com.flowpowered.math.vector.Vector3d;
30+
31+
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
32+
33+
/**
34+
* A marker that is displayed on one of the maps in the web-app.
35+
* <p>Each marker has an id that is unique in the {@link MarkerSet} that it is in.</p>
36+
*/
37+
public interface Marker {
38+
39+
/**
40+
* Getter for the id of this {@link Marker}.
41+
* <p>The id is unique in the {@link MarkerSet} that this marker is in.</p>
42+
* @return the id of this {@link Marker}
43+
*/
44+
String getId();
45+
46+
/**
47+
* Getter for the {@link BlueMapMap} this {@link Marker} lives in.
48+
* @return the {@link BlueMapMap} this {@link Marker} lives in
49+
*/
50+
BlueMapMap getMap();
51+
52+
/**
53+
* Sets the {@link BlueMapMap} this {@link Marker} lives in
54+
* @param map the new {@link BlueMapMap}
55+
*/
56+
void setMap(BlueMapMap map);
57+
58+
/**
59+
* Getter for the position of where this {@link Marker} lives on the map.
60+
* @return the position of this {@link Marker}
61+
*/
62+
Vector3d getPosition();
63+
64+
/**
65+
* Sets the position of where this {@link Marker} lives on the map.
66+
* @param position the new position
67+
*/
68+
void setPosition(Vector3d position);
69+
70+
/**
71+
* Getter for the minimum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.<br>
72+
* If the camera is closer to this {@link Marker} than this distance, it will be hidden!
73+
*
74+
* @return the minimum distance for this {@link Marker} to be displayed
75+
*/
76+
double getMinDistance();
77+
78+
/**
79+
* Sets the minimum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.<br>
80+
* If the camera is closer to this {@link Marker} than this distance, it will be hidden!
81+
*
82+
* @param minDistance the new minimum distance
83+
*/
84+
void setMinDistance(double minDistance);
85+
86+
/**
87+
* Getter for the maximum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.<br>
88+
* If the camera is further to this {@link Marker} than this distance, it will be hidden!
89+
*
90+
* @return the maximum distance for this {@link Marker} to be displayed
91+
*/
92+
double getMaxDistance();
93+
94+
/**
95+
* Sets the maximum distance of the camera to the position ({@link #getPosition()} of the {@link Marker} for it to be displayed.<br>
96+
* If the camera is closer to this {@link Marker} than this distance, it will be hidden!
97+
*
98+
* @param maxDistance the new maximum distance
99+
*/
100+
void setMaxDistance(double maxDistance);
101+
102+
/**
103+
* Getter for the label of this marker. The label can include html-tags.
104+
* @return the label of this
105+
*/
106+
String getLabel();
107+
108+
/**
109+
* Sets the label of this {@link Marker}. The label can include html-tags.
110+
* <p>
111+
* <b>Important:</b><br>
112+
* Html-tags in the label will not be escaped, so you can use them to style the {@link Marker}-labels.<br>
113+
* Make sure you escape all html-tags from possible user inputs to prevent possible <a href="https://en.wikipedia.org/wiki/Cross-site_scripting">XSS-Attacks</a> on the web-client!
114+
* </p>
115+
*
116+
* @param label the new label for this {@link Marker}
117+
*/
118+
void setLabel(String label);
119+
120+
/**
121+
* Gets the link-adress of this {@link Marker}.<br>
122+
* If a link is present, this link will be followed when the user clicks on the marker in the web-app.
123+
*
124+
* @return the {@link Optional} link
125+
*/
126+
Optional<String> getLink();
127+
128+
/**
129+
* If this is <code>true</code> the link ({@link #getLink()}) will be opened in a new tab.
130+
* @return whether the link will be opened in a new tab
131+
* @see #getLink()
132+
*/
133+
boolean isNewTab();
134+
135+
/**
136+
* Sets the link-adress of this {@link Marker}.<br>
137+
* If a link is present, this link will be followed when the user clicks on the marker in the web-app.
138+
*
139+
* @param link the link, or <code>null</code> to disable the link
140+
* @param newTab whether the link should be opened in a new tab
141+
*/
142+
void setLink(String link, boolean newTab);
143+
144+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
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.marker;
26+
27+
import java.io.IOException;
28+
import java.util.Collection;
29+
import java.util.Optional;
30+
31+
import de.bluecolored.bluemap.api.BlueMapAPI;
32+
33+
/**
34+
* The {@link MarkerAPI} for easy manipulation of the <code>markers.json</code> that is used to display different Markers on the map.
35+
* <p>
36+
* <b>Important:</b><br>
37+
* If you made changes to any {@link MarkerSet} or {@link Marker} including creations and deletions, you need to finally save your changes by calling {@link #save()}!<br>
38+
* </p>
39+
* <p>To avoid any concurrent modifications to the <code>markers.json</code>, make sure your {@link MarkerAPI} is always loaded before making any changes, and saved right after the changes.</p>
40+
*
41+
* @see BlueMapAPI#getMarkerAPI()
42+
*/
43+
public interface MarkerAPI {
44+
45+
/**
46+
* Getter for an <i>unmodifiable</i> {@link Collection} containing all {@link MarkerSet}s that are currently loaded with BlueMap.
47+
*
48+
* @return a {@link Collection} with all loaded {@link MarkerSet}s
49+
*/
50+
Collection<MarkerSet> getMarkerSets();
51+
52+
/**
53+
* Getter for a loaded {@link MarkerSet} with the given id.<br>
54+
* Returns an empty {@link Optional} if no {@link MarkerSet} with that id is loaded.
55+
*
56+
* @param id the id of the {@link MarkerSet}
57+
* @return an {@link Optional}&lt;{@link MarkerSet}&gt; with the given id
58+
*/
59+
Optional<MarkerSet> getMarkerSet(String id);
60+
61+
/**
62+
* Created a new {@link MarkerSet} with the given id.<br>
63+
* If there is already a {@link MarkerSet} with that id loaded, no new {@link MarkerSet} is created and the existing one is returned.
64+
*
65+
* @param id the id of the {@link MarkerSet}
66+
* @return a {@link MarkerSet} with the given id
67+
*/
68+
MarkerSet createMarkerSet(String id);
69+
70+
/**
71+
* Adds the given {@link MarkerSet}.<br>
72+
* If a {@link MarkerSet} with the id of the given {@link MarkerSet} already exists it will be replaced!
73+
* @param markerSet the {@link MarkerSet} to be added
74+
*/
75+
void addMarkerSet(MarkerSet markerSet);
76+
77+
/**
78+
* Removes the given {@link MarkerSet}.<br>
79+
* This is equivalent to calling <code>removeMarkerSet(markerSet.getId())</code>.
80+
*
81+
* @param markerSet the {@link MarkerSet} to be removed
82+
* @return <code>true</code> if the {@link MarkerSet} was removed, <code>false</code> if that {@link MarkerSet} didn't exist
83+
*/
84+
default boolean removeMarkerSet(MarkerSet markerSet) {
85+
return removeMarkerSet(markerSet.getId());
86+
}
87+
88+
/**
89+
* Removes the {@link MarkerSet} with the given id.
90+
*
91+
* @param id the id of the {@link MarkerSet} to be removed
92+
* @return <code>true</code> if the {@link MarkerSet} was removed, <code>false</code> if there was no {@link MarkerSet} with that id
93+
*/
94+
boolean removeMarkerSet(String id);
95+
96+
/**
97+
* Loads changes made by others, changes could be from other plugin's using the API or external changes to the <code>markers.json</code>.<br>
98+
* Calling this will <b>override all unsaved changes</b> you made with this instance!
99+
*
100+
* @throws IOException if an {@link IOException} occurred while loading the <code>markers.json</code>
101+
*/
102+
void load() throws IOException;
103+
104+
/**
105+
* Saves all changes made with this instance to the <code>markers.json</code>.<br>
106+
*
107+
* @throws IOException if an {@link IOException} occurred while saving the <code>markers.json</code>
108+
*/
109+
void save() throws IOException;
110+
111+
}

0 commit comments

Comments
 (0)