44import java .util .Map ;
55
66import org .bukkit .Bukkit ;
7+ import org .bukkit .Location ;
78import org .bukkit .Material ;
89import org .bukkit .World ;
910import org .bukkit .event .EventHandler ;
1617import de .bluecolored .bluemap .api .markers .MarkerSet ;
1718import de .bluecolored .bluemap .api .markers .POIMarker ;
1819import de .bluecolored .bluemap .api .markers .ShapeMarker ;
19- import de .bluecolored .bluemap .api .math .Color ;
2020import de .bluecolored .bluemap .api .math .Shape ;
2121import world .bentobox .bentobox .BentoBox ;
2222import world .bentobox .bentobox .api .addons .GameModeAddon ;
2323import world .bentobox .bentobox .api .events .island .IslandDeleteEvent ;
2424import world .bentobox .bentobox .api .events .island .IslandNameEvent ;
2525import world .bentobox .bentobox .api .events .island .IslandNewIslandEvent ;
2626import world .bentobox .bentobox .api .events .island .IslandResettedEvent ;
27- import world .bentobox .bentobox .api .hooks .Hook ;
27+ import world .bentobox .bentobox .api .hooks .MapHook ;
2828import world .bentobox .bentobox .api .user .User ;
2929import world .bentobox .bentobox .database .objects .Island ;
3030
3333 * @author tastybento
3434 * @since 2.1.0
3535 */
36- public class BlueMapHook extends Hook implements Listener {
36+ public class BlueMapHook extends MapHook implements Listener {
3737
3838 private final BentoBox plugin ;
3939 private BlueMapAPI api ;
@@ -118,8 +118,8 @@ private void setMarker(MarkerSet markerSet, Island island) {
118118 .shape (Shape .createRect (island .getMinProtectedX (), island .getMinProtectedZ (),
119119 island .getMaxProtectedX (), island .getMaxProtectedZ ()),
120120 (float ) island .getCenter ().getY ())
121- .lineColor (new Color (51 , 136 , 255 ))
122- .fillColor (new Color (51 , 136 , 255 , 0.15f ))
121+ .lineColor (new de . bluecolored . bluemap . api . math . Color (51 , 136 , 255 ))
122+ .fillColor (new de . bluecolored . bluemap . api . math . Color (51 , 136 , 255 , 0.15f ))
123123 .lineWidth (2 )
124124 .build ();
125125 markerSet .put (id + "_area" , area );
@@ -156,10 +156,10 @@ private void remove(String islandUniqueId, GameModeAddon addon) {
156156 }
157157 }
158158
159- // --- Public addon API ---
159+ // --- Native API for direct BlueMap access ---
160160
161161 /**
162- * Returns the BlueMapAPI instance for addons to create custom markers.
162+ * Returns the BlueMapAPI instance for addons to create custom markers directly .
163163 * @return the BlueMapAPI instance
164164 */
165165 @ NonNull
@@ -168,27 +168,99 @@ public BlueMapAPI getBlueMapAPI() {
168168 }
169169
170170 /**
171- * Gets the marker set for the given game mode addon, if one has been registered .
171+ * Gets the native BlueMap marker set for the given game mode addon.
172172 * @param addon the game mode addon
173173 * @return the MarkerSet, or null if not registered
174174 */
175175 public MarkerSet getMarkerSet (@ NonNull GameModeAddon addon ) {
176176 return markerSets .get (addon .getWorldSettings ().getFriendlyName ());
177177 }
178178
179- /**
180- * Creates or retrieves a custom marker set and attaches it to all BlueMap maps.
181- * Useful for addons like Warps that want to display their own markers.
182- * @param id unique identifier for the marker set
183- * @param label display label for the marker set
184- * @return the MarkerSet
185- */
186- @ NonNull
187- public MarkerSet createMarkerSet (@ NonNull String id , @ NonNull String label ) {
188- MarkerSet markerSet = MarkerSet .builder ().label (label ).toggleable (true ).defaultHidden (false ).build ();
189- // Attach to all known BlueMap maps
179+ // --- MapHook abstract method implementations ---
180+
181+ @ Override
182+ public void createMarkerSet (@ NonNull String id , @ NonNull String label ) {
183+ MarkerSet markerSet = markerSets .computeIfAbsent (id ,
184+ k -> MarkerSet .builder ().label (label ).toggleable (true ).defaultHidden (false ).build ());
190185 api .getMaps ().forEach (map -> map .getMarkerSets ().put (id , markerSet ));
191- return markerSet ;
186+ }
187+
188+ @ Override
189+ public void removeMarkerSet (@ NonNull String id ) {
190+ markerSets .remove (id );
191+ api .getMaps ().forEach (map -> map .getMarkerSets ().remove (id ));
192+ }
193+
194+ @ Override
195+ public void clearMarkerSet (@ NonNull String id ) {
196+ MarkerSet markerSet = markerSets .get (id );
197+ if (markerSet != null ) {
198+ markerSet .getMarkers ().clear ();
199+ }
200+ }
201+
202+ @ Override
203+ public void addPointMarker (@ NonNull String markerSetId , @ NonNull String markerId , @ NonNull String label ,
204+ @ NonNull Location location ) {
205+ MarkerSet markerSet = markerSets .get (markerSetId );
206+ if (markerSet != null ) {
207+ POIMarker marker = POIMarker .builder ().label (label ).listed (true ).defaultIcon ()
208+ .position (location .getX (), location .getY (), location .getZ ()).build ();
209+ markerSet .put (markerId , marker );
210+ }
211+ }
212+
213+ @ Override
214+ public void removePointMarker (@ NonNull String markerSetId , @ NonNull String markerId ) {
215+ MarkerSet markerSet = markerSets .get (markerSetId );
216+ if (markerSet != null ) {
217+ markerSet .remove (markerId );
218+ }
219+ }
220+
221+ @ Override
222+ public void addAreaMarker (@ NonNull String markerSetId , @ NonNull String markerId , @ NonNull String label ,
223+ @ NonNull World world , double minX , double minZ , double maxX , double maxZ ,
224+ java .awt .Color lineColor , java .awt .Color fillColor , int lineWidth ) {
225+ MarkerSet markerSet = markerSets .get (markerSetId );
226+ if (markerSet != null ) {
227+ ShapeMarker area = ShapeMarker .builder ().label (label )
228+ .shape (Shape .createRect (minX , minZ , maxX , maxZ ), 64 )
229+ .lineColor (toBlueMapColor (lineColor )).fillColor (toBlueMapColor (fillColor )).lineWidth (lineWidth )
230+ .build ();
231+ markerSet .put (markerId , area );
232+ }
233+ }
234+
235+ @ Override
236+ public void addPolygonMarker (@ NonNull String markerSetId , @ NonNull String markerId , @ NonNull String label ,
237+ @ NonNull World world , @ NonNull double [] xPoints , @ NonNull double [] zPoints ,
238+ java .awt .Color lineColor , java .awt .Color fillColor , int lineWidth ) {
239+ MarkerSet markerSet = markerSets .get (markerSetId );
240+ if (markerSet != null && xPoints .length == zPoints .length && xPoints .length >= 3 ) {
241+ com .flowpowered .math .vector .Vector2d [] points = new com .flowpowered .math .vector .Vector2d [xPoints .length ];
242+ for (int i = 0 ; i < xPoints .length ; i ++) {
243+ points [i ] = new com .flowpowered .math .vector .Vector2d (xPoints [i ], zPoints [i ]);
244+ }
245+ Shape shape = new Shape (points );
246+ ShapeMarker area = ShapeMarker .builder ().label (label ).shape (shape , 64 )
247+ .lineColor (toBlueMapColor (lineColor )).fillColor (toBlueMapColor (fillColor )).lineWidth (lineWidth )
248+ .build ();
249+ markerSet .put (markerId , area );
250+ }
251+ }
252+
253+ @ Override
254+ public void removeAreaMarker (@ NonNull String markerSetId , @ NonNull String markerId ) {
255+ MarkerSet markerSet = markerSets .get (markerSetId );
256+ if (markerSet != null ) {
257+ markerSet .remove (markerId );
258+ }
259+ }
260+
261+ private static de .bluecolored .bluemap .api .math .Color toBlueMapColor (java .awt .Color c ) {
262+ return new de .bluecolored .bluemap .api .math .Color (c .getRed (), c .getGreen (), c .getBlue (),
263+ c .getAlpha () / 255.0f );
192264 }
193265
194266 // --- Event handlers ---
0 commit comments