### getInstance() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of how to get the BlueMapAPI instance. ```java Optional optionalApi = BlueMapAPI.getInstance(); if (optionalApi.isPresent()) { BlueMapAPI api = optionalApi.get(); // Use the API } ``` -------------------------------- ### getPlugin() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of how to get the Plugin instance and access its SkinProvider. ```java BlueMapAPI.getInstance().ifPresent(api -> { Plugin plugin = api.getPlugin(); SkinProvider provider = plugin.getSkinProvider(); }); ``` -------------------------------- ### API Entry-Point Examples Source: https://github.com/bluemap-minecraft/bluemapapi/wiki/Home Demonstrates how to get the BlueMapAPI instance and use listeners. ```java // Directly getting the api (wrapped in an Optional) Optional optionalApi = BlueMapAPI.getInstance(); // Directly using the API if it is enabled BlueMapAPI.getInstance().ifPresent(api -> { //code executed when the api is enabled (skipped if the api is not enabled) }); // Using a listener to do something as soon as the API is available BlueMapAPI.onEnable(api -> { //code executed when the api got enabled }); BlueMapAPI.onDisable(api -> { //code executed right before the api gets disabled }); ``` -------------------------------- ### getBlueMapVersion() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of getting the installed BlueMap version string. ```java BlueMapAPI.getInstance().ifPresent(api -> { System.out.println("BlueMap version: " + api.getBlueMapVersion()); }); ``` -------------------------------- ### getWebApp() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of how to get the WebApp instance and register a script. ```java BlueMapAPI.getInstance().ifPresent(api -> { api.getWebApp().registerScript("js/my-script.js"); }); ``` -------------------------------- ### ShapeMarker Constructor Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of creating a ShapeMarker. ```java Shape rect = Shape.createRect(100, 100, 200, 200); ShapeMarker marker = new ShapeMarker("Territory", rect, 64); ``` -------------------------------- ### Complete Integration Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/README.md An example demonstrating how to integrate BlueMap API into a Minecraft plugin, including setting up markers, registering web content, and starting the rendering process. ```java import de.bluecolored.bluemap.api.*; import de.bluecolored.bluemap.api.markers.*; import de.bluecolored.bluemap.api.math.*; import com.flowpowered.math.vector.*; public class BlueMapPlugin { public static void initialize() { // Register initialization listener BlueMapAPI.onEnable(api -> { System.out.println("BlueMap " + api.getBlueMapVersion() + " loaded"); setupMarkers(api); registerWebContent(api); startRendering(api); }); // Register shutdown listener BlueMapAPI.onDisable(api -> { System.out.println("BlueMap is shutting down"); }); } private static void setupMarkers(BlueMapAPI api) { for (BlueMapMap map : api.getMaps()) { // Create marker set MarkerSet markerSet = MarkerSet.builder() .label("Plugin Markers") .toggleable(true) .build(); map.getMarkerSets().put("plugin-markers", markerSet); // Add POI marker POIMarker poi = new POIMarker("Landmark", new Vector3d(100, 64, 200)); poi.setDetail("A notable location"); markerSet.put("landmark", poi); // Add shape marker Shape territory = Shape.createCircle(150, 150, 50, 16); ShapeMarker shape = new ShapeMarker("Territory", territory, 0); shape.setLineColor(new Color(0, 255, 0, 1)); shape.setFillColor(new Color(0, 255, 0, 0.2f)); markerSet.put("territory", shape); } } private static void registerWebContent(BlueMapAPI api) { BlueMapAPI.onEnable(a -> { WebApp webApp = a.getWebApp(); Path webRoot = webApp.getWebRoot(); try { // Register custom styles Path cssFile = webRoot.resolve("custom/plugin.css"); Files.createDirectories(cssFile.getParent()); Files.write(cssFile, ".plugin-marker { color: blue; }".getBytes()); webApp.registerStyle("custom/plugin.css"); System.out.println("Web content registered"); } catch (Exception e) { System.err.println("Failed to register web content: " + e.getMessage()); } }); } private static void startRendering(BlueMapAPI api) { RenderManager manager = api.getRenderManager(); if (!manager.isRunning()) { int cores = Runtime.getRuntime().availableProcessors(); manager.start(cores); // Schedule all maps for (BlueMapMap map : api.getMaps()) { manager.scheduleMapUpdateTask(map); } System.out.println("Rendering started"); } } } ``` -------------------------------- ### Complete Usage Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/render-manager.md Demonstrates various functionalities of the RenderManager, including starting the renderer, scheduling updates for all maps, updating specific regions, purging and re-rendering, and monitoring progress. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.RenderManager; import de.bluecolored.bluemap.api.BlueMapMap; import com.flowpowered.math.vector.Vector2i; import java.util.Arrays; public class RenderManagerExample { public static void manageRendering() { BlueMapAPI.getInstance().ifPresent(api -> { RenderManager manager = api.getRenderManager(); // Start rendering if not running if (!manager.isRunning()) { int cores = Runtime.getRuntime().availableProcessors(); manager.start(cores); System.out.println("Started renderer with " + cores + " threads"); } // Schedule updates for all maps for (BlueMapMap map : api.getMaps()) { if (manager.scheduleMapUpdateTask(map)) { System.out.println("Scheduled update for: " + map.getName()); } else { System.out.println("Update already queued for: " + map.getName()); } } // Check rendering progress monitorRenderProgress(manager); }); } public static void updateSpecificRegions() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { RenderManager manager = api.getRenderManager(); // Update specific regions (region coordinates) java.util.Collection regions = Arrays.asList( new Vector2i(0, 0), new Vector2i(1, 0), new Vector2i(0, 1) ); boolean scheduled = manager.scheduleMapUpdateTask(map, regions, false); if (scheduled) { System.out.println("Scheduled update for 3 regions"); } }); }); } public static void purgeAndRender() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { RenderManager manager = api.getRenderManager(); System.out.println("Purging map..."); if (manager.scheduleMapPurgeTask(map)) { System.out.println("Purge scheduled (map will be re-rendered)"); } }); }); } public static void monitorRenderProgress(RenderManager manager) { System.out.println("Renderer status:"); System.out.println(" Running: " + manager.isRunning()); System.out.println(" Threads: " + manager.renderThreadCount()); System.out.println(" Queue size: " + manager.renderQueueSize()); // Monitor queue periodically if (manager.renderQueueSize() > 0) { System.out.println("Rendering in progress..."); } else if (manager.isRunning()) { System.out.println("Rendering complete!"); } } public static void forceFullRender() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { RenderManager manager = api.getRenderManager(); // Force re-render all tiles System.out.println("Starting full map re-render (forced)..."); if (manager.scheduleMapUpdateTask(map, true)) { System.out.println("Full re-render scheduled"); } }); }); } } ``` -------------------------------- ### Example of building a MarkerSet Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example demonstrating the fluent API for building a MarkerSet. ```java MarkerSet set = MarkerSet.builder() .label("Cities") .toggleable(true) .defaultHidden(false) .sorting(10) .build(); ``` -------------------------------- ### getRenderManager() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of how to get the RenderManager and schedule a map update task. ```java BlueMapAPI.getInstance().ifPresent(api -> { RenderManager manager = api.getRenderManager(); api.getMaps().forEach(map -> manager.scheduleMapUpdateTask(map)); }); ``` -------------------------------- ### getMarkers() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Demonstrates how to get and modify the map of markers in a MarkerSet. ```java MarkerSet set = /* ... */; set.getMarkers().put("marker-1", marker); set.getMarkers().remove("marker-1"); ``` -------------------------------- ### LineMarker Constructor Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of creating a LineMarker with a specified line. ```java Line line = new Line( new Vector3d(100, 64, 100), new Vector3d(200, 80, 200) ); LineMarker marker = new LineMarker("Path", line); ``` -------------------------------- ### onEnable() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of registering a listener for when BlueMap is enabled. ```java BlueMapAPI.onEnable(api -> { System.out.println("BlueMap enabled!"); api.getMaps().forEach(map -> { MarkerSet markers = new MarkerSet("my-markers"); map.getMarkerSets().put("my-markers", markers); }); }); ``` -------------------------------- ### getAPIVersion() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of how to get the BlueMapAPI version string. ```java BlueMapAPI.getInstance().ifPresent(api -> { System.out.println("API version: " + api.getAPIVersion()); }); ``` -------------------------------- ### Example of adding a marker Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example demonstrating how to create a MarkerSet and add a POIMarker to it. ```java MarkerSet set = new MarkerSet("Locations"); POIMarker marker = new POIMarker("Home", position); set.put("home", marker); ``` -------------------------------- ### HtmlMarker Builder Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of creating an HtmlMarker using its builder. ```java HtmlMarker marker = HtmlMarker.builder() .label("Info") .position(100, 64, 200) .html("

Information here

") .anchor(50, 100) .styleClasses("info-box") .build(); ``` -------------------------------- ### Complete Usage Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/asset-storage.md This example shows how to manage custom assets, including creating and storing an icon, using it in markers, and storing/reading configuration data. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.BlueMapMap; import de.bluecolored.bluemap.api.AssetStorage; import de.bluecolored.bluemap.api.markers.POIMarker; import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3d; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.*; import java.nio.charset.StandardCharsets; public class AssetStorageExample { public static void manageAssets() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { AssetStorage storage = map.getAssetStorage(); try { // Check if icon exists if (!storage.assetExists("custom-icon.png")) { System.out.println("Creating custom icon..."); createAndStoreIcon(storage); } else { System.out.println("Icon already exists"); } // Use the icon in markers String iconUrl = storage.getAssetUrl("custom-icon.png"); POIMarker marker = new POIMarker("Location", new Vector3d(100, 64, 200)); marker.setIcon(iconUrl, new Vector2i(16, 32)); } catch (IOException e) { System.err.println("Asset storage error: " + e.getMessage()); } }); }); } private static void createAndStoreIcon(AssetStorage storage) throws IOException { // Create a simple 32x32 red square image BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { image.setRGB(x, y, 0xFFFF0000); // Red with full alpha } } // Write to storage try (OutputStream out = storage.writeAsset("custom-icon.png")) { ImageIO.write(image, "png", out); } System.out.println("Icon stored as: " + storage.getAssetUrl("custom-icon.png")); } public static void storeConfigData() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { AssetStorage storage = map.getAssetStorage(); try { // Store JSON configuration String jsonConfig = "{\"version\": 1,\n" + "\"author\": \"MyPlugin\",\n" + "\"settings\": {\n" + "\"showMarkers\": true,\n" + "\"updateInterval\": 60000\n" + "}" + "}"; try (OutputStream out = storage.writeAsset("config.json")) { out.write(jsonConfig.getBytes(StandardCharsets.UTF_8)); } System.out.println("Config stored"); // Read it back Optional optIn = storage.readAsset("config.json"); if (optIn.isPresent()) { try (InputStream in = optIn.get(); BufferedReader reader = new BufferedReader( new InputStreamReader(in, StandardCharsets.UTF_8))) { String content = reader.readLine(); System.out.println("Config content: " + content); } } } catch (IOException e) { System.err.println("Error managing config: " + e.getMessage()); } }); }); } public static void storeMultipleAssets() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { AssetStorage storage = map.getAssetStorage(); try { // Store CSS stylesheet String css = ".marker-custom { color: blue; font-weight: bold; }"; try (OutputStream out = storage.writeAsset("styles.css")) { out.write(css.getBytes(StandardCharsets.UTF_8)); } System.out.println("CSS stored: " + storage.getAssetUrl("styles.css")); // Store JavaScript String js = "console.log('Custom script loaded');"; try (OutputStream out = storage.writeAsset("script.js")) { out.write(js.getBytes(StandardCharsets.UTF_8)); } System.out.println("JS stored: " + storage.getAssetUrl("script.js")); ``` -------------------------------- ### getMaps() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of iterating through all loaded maps and printing their names. ```java BlueMapAPI.getInstance().ifPresent(api -> { for (BlueMapMap map : api.getMaps()) { System.out.println("Map: " + map.getName()); } }); ``` -------------------------------- ### Full Usage Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md An example demonstrating how to integrate with the BlueMap API, including registering listeners, accessing maps, creating marker sets, adding markers, and scheduling renders. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.BlueMapMap; import de.bluecolored.bluemap.api.markers.MarkerSet; import de.bluecolored.bluemap.api.markers.POIMarker; import com.flowpowered.math.vector.Vector3d; public class BlueMapIntegration { public static void initializeBlueMap() { // Register listener for when BlueMap loads BlueMapAPI.onEnable(api -> { System.out.println("BlueMap loaded: " + api.getBlueMapVersion()); // Get all maps for (BlueMapMap map : api.getMaps()) { System.out.println("Processing map: " + map.getName()); // Create or get marker set MarkerSet markerSet = map.getMarkerSets() .computeIfAbsent("my-markers", k -> new MarkerSet("My Markers")); // Add a marker POIMarker marker = new POIMarker("Test Point", new Vector3d(100, 64, 200)); markerSet.put("test-marker", marker); } // Schedule renders api.getRenderManager().start(); }); // Register cleanup listener BlueMapAPI.onDisable(api -> { System.out.println("BlueMap is shutting down"); }); } // Check if API is available at any time public static void checkStatus() { BlueMapAPI.getInstance().ifPresent(api -> { System.out.println("API is ready!"); System.out.println("Maps: " + api.getMaps().size()); System.out.println("Worlds: " + api.getWorlds().size()); }); } } ``` -------------------------------- ### setMinDistance Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of setting the minimum camera distance for marker visibility. ```java marker.setMinDistance(50); // Hide if camera closer than 50 blocks ``` -------------------------------- ### getWorlds() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of iterating through all loaded worlds and printing their IDs. ```java BlueMapAPI.getInstance().ifPresent(api -> { for (BlueMapWorld world : api.getWorlds()) { System.out.println("World: " + world.getId()); } }); ``` -------------------------------- ### PlayerDisplayNameProvider get method Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md Example implementation of the get method for providing custom player display names. ```java String get(UUID playerUUID) { // Return custom display name return "Player_" + playerUUID.toString().substring(0, 8); } ``` -------------------------------- ### setIcon() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of setting a custom icon and its anchor point for a POIMarker. ```java marker.setIcon("assets/custom.png", new Vector2i(16, 32)); ``` -------------------------------- ### start() method Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/render-manager.md Starts the renderer with the configured number of render threads. Has no effect if already running. ```java void start() ``` ```java RenderManager manager = api.getRenderManager(); if (!manager.isRunning()) { manager.start(); System.out.println("Renderer started"); } ``` -------------------------------- ### POIMarker Builder Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of using the POIMarker builder to create a marker. ```java POIMarker marker = POIMarker.builder() .label("Town Hall") .position(100, 64, 200) .detail("Main government building") .icon("assets/building.png", 25, 45) .styleClasses("important") .build(); ``` -------------------------------- ### setMaxDistance Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of setting the maximum camera distance for marker visibility. ```java marker.setMaxDistance(200); // Hide if camera farther than 200 blocks ``` -------------------------------- ### setDetail() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of setting the detail text for a POIMarker. ```java marker.setDetail("Important location"); ``` -------------------------------- ### POIMarker Example 2 Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of creating a POI marker with a custom icon. ```java POIMarker marker = new POIMarker("Castle", position, "assets/castle-icon.png", new Vector2i(25, 45) ); ``` -------------------------------- ### unregisterListener() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of unregistering a previously registered listener. ```java Consumer listener = api -> System.out.println("Enabled"); BlueMapAPI.onEnable(listener); // Later... BlueMapAPI.unregisterListener(listener); ``` -------------------------------- ### onDisable() Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of registering a listener for when BlueMap is disabled. ```java BlueMapAPI.onDisable(api -> { System.out.println("BlueMap is disabling!"); }); ``` -------------------------------- ### getHoles Method Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of adding a hole to a ShapeMarker. ```java ShapeMarker marker = /* ... */; Shape hole = Shape.createCircle(150, 150, 20, 8); marker.getHoles().add(hole); ``` -------------------------------- ### POIMarker Example 1 Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Example of creating a POI marker with the standard default icon. ```java POIMarker marker = new POIMarker("Village", new Vector3d(100, 64, 200)); ``` -------------------------------- ### Get Player Visibility Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/webapp.md Example of checking if a player is currently visible on the web app. ```java BlueMapAPI.getInstance().ifPresent(api -> { UUID playerUuid = UUID.fromString("550e8400-e29b-41d4-a716-446655440000"); if (api.getWebApp().getPlayerVisibility(playerUuid)) { System.out.println("Player is visible on map"); } else { System.out.println("Player is hidden from map"); } }); ``` -------------------------------- ### Get Web Root and Create Custom Directory/File Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/webapp.md Demonstrates how to get the web root path, create a custom directory, and write a custom CSS file. ```java BlueMapAPI.getInstance().ifPresent(api -> { Path webRoot = api.getWebApp().getWebRoot(); Path customDir = webRoot.resolve("custom"); // Create directory if needed if (!Files.exists(customDir)) { Files.createDirectories(customDir); } // Write custom style file Path cssFile = customDir.resolve("style.css"); String css = ".my-custom-class { color: red; }"; Files.write(cssFile, css.getBytes()); }); ``` -------------------------------- ### Complete Usage Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/maps.md Demonstrates how to interact with BlueMap's API to manage worlds, maps, markers, and assets. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.BlueMapMap; import de.bluecolored.bluemap.api.BlueMapWorld; import de.bluecolored.bluemap.api.markers.MarkerSet; import de.bluecolored.bluemap.api.markers.POIMarker; import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3d; public class MapManagement { public static void exploreWorlds() { BlueMapAPI.getInstance().ifPresent(api -> { // Iterate all worlds for (BlueMapWorld world : api.getWorlds()) { System.out.println("World: " + world.getId()); // Iterate maps in world for (BlueMapMap map : world.getMaps()) { System.out.println(" Map: " + map.getName() + " (ID: " + map.getId() + ")"); System.out.println(" Tile size: " + map.getTileSize()); System.out.println(" Frozen: " + map.isFrozen()); } } }); } public static void manageMarkers() { BlueMapAPI.getInstance().ifPresent(api -> { // Find a specific map api.getMap("world").ifPresent(map -> { // Create marker set MarkerSet markerSet = new MarkerSet("Locations"); markerSet.setToggleable(true); map.getMarkerSets().put("locations", markerSet); // Convert block pos to tile Vector3d blockPos = new Vector3d(100, 64, 200); Vector2i tile = map.posToTile(blockPos); System.out.println("Tile: " + tile); // Add marker POIMarker marker = new POIMarker("Home", blockPos); markerSet.put("home", marker); }); }); } public static void manageAssets() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { AssetStorage storage = map.getAssetStorage(); // Check asset existence try { if (!storage.assetExists("my-icon.png")) { // Write asset (simplified - real code would read from file) try (OutputStream out = storage.writeAsset("my-icon.png")) { // Write image data } } // Get URL for web use String url = storage.getAssetUrl("my-icon.png"); System.out.println("Asset URL: " + url); } catch (IOException e) { System.err.println("Failed to manage asset: " + e.getMessage()); } }); }); } } ``` -------------------------------- ### writeAsset Method Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/asset-storage.md Demonstrates how to write a PNG image and JSON data to the asset storage. ```java AssetStorage storage = map.getAssetStorage(); // Write a PNG image try (OutputStream out = storage.writeAsset("my-icon.png")) { BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); // ... draw on image ... ImageIO.write(image, "png", out); } catch (IOException e) { System.err.println("Failed to write asset: " + e.getMessage()); } // Write JSON data try (OutputStream out = storage.writeAsset("config.json")) { String json = "{\"key\": \"value\"}"; out.write(json.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { System.err.println("Failed to write JSON: " + e.getMessage()); } ``` -------------------------------- ### getWorld(Object world) Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of retrieving a BlueMapWorld by its string ID or path. ```java BlueMapAPI.getInstance().ifPresent(api -> { // By string ID Optional world = api.getWorld("world"); // By path Path worldPath = Paths.get("/path/to/world"); Optional worldByPath = api.getWorld(worldPath); }); ``` -------------------------------- ### readAsset Method Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/asset-storage.md Demonstrates how to read a PNG image and JSON data from the asset storage. ```java AssetStorage storage = map.getAssetStorage(); // Read PNG image Optional optIn = storage.readAsset("my-icon.png"); if (optIn.isPresent()) { try (InputStream in = optIn.get()) { BufferedImage image = ImageIO.read(in); System.out.println("Loaded image: " + image.getWidth() + "x" + image.getHeight()); } catch (IOException e) { System.err.println("Failed to read asset: " + e.getMessage()); } } else { System.out.println("Asset not found"); } // Read JSON data Optional optJson = storage.readAsset("config.json"); if (optJson.isPresent()) { try (InputStream in = optJson.get()) { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = reader.readLine(); System.out.println("Config: " + line); } catch (IOException e) { System.err.println("Failed to read JSON: " + e.getMessage()); } } ``` -------------------------------- ### Maven Setup Source: https://github.com/bluemap-minecraft/bluemapapi/wiki/Home Adds BlueMapAPI to a Maven project. ```xml bluecolored https://repo.bluecolored.de/releases de.bluecolored bluemap-api 2.7.7 provided ``` -------------------------------- ### getMap(String id) Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/bluemapapi.md Example of retrieving a BlueMapMap by its configured ID and printing its name. ```java BlueMapAPI.getInstance().ifPresent(api -> { Optional map = api.getMap("world"); map.ifPresent(m -> { System.out.println("Found map: " + m.getName()); }); }); ``` -------------------------------- ### Line Class Examples Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/types.md Examples demonstrating the creation of a simple 3D line and a more complex path using the Line builder. ```java Line line = new Line( new Vector3d(0, 0, 0), new Vector3d(100, 50, 100) ); Line path = Line.builder() .addPoint(new Vector3d(0, 64, 0)) .addPoint(new Vector3d(50, 70, 50)) .addPoint(new Vector3d(100, 64, 100)) .build(); ``` -------------------------------- ### start(int threadCount) method Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/render-manager.md Starts the renderer with a specific number of threads. The thread count should generally not exceed the number of available CPU cores. Has no effect if already running. ```java void start(int threadCount) ``` ```java int cores = Runtime.getRuntime().availableProcessors(); renderManager.start(Math.max(1, cores - 1)); // Use all but one core ``` -------------------------------- ### Color Class Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/types.md Examples demonstrating how to create Color objects using different constructors and formats. ```java Color red = new Color(255, 0, 0); Color transparent = new Color(255, 0, 0, 0.5f); Color fromCSS = new Color("#ff0000"); Color fromInt = new Color(0xFF0000FF); // ARGB format ``` -------------------------------- ### Custom SkinProvider Implementation Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md An example implementation of the SkinProvider interface for custom skin loading logic. ```java public class CustomSkinProvider implements SkinProvider { @Override public Optional load(UUID playerUUID) throws IOException { // Fetch skin from custom source // Return Optional.of(bufferedImage) or Optional.empty() return Optional.empty(); } } ``` -------------------------------- ### Complete Plugin Configuration Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md An example showing how to integrate custom providers into the BlueMap plugin during initialization. ```java import de.bluecolored.bluemap.api.BlueMapAPI; public class PluginConfiguration { public static void configureOnEnable() { BlueMapAPI.onEnable(api -> { System.out.println("Configuring BlueMap plugin customizations..."); // Set custom skin provider api.getPlugin().setSkinProvider(new CustomSkinProviderExample()); // Set custom icon factory api.getPlugin().setPlayerMarkerIconFactory(new CustomPlayerIconFactoryExample()); // Set custom display name provider CustomDisplayNameProviderExample displayProvider = new CustomDisplayNameProviderExample(); api.getPlugin().setPlayerDisplayNameProvider(displayProvider); System.out.println("Plugin customizations configured"); }); } // Call this during plugin initialization public static void init() { configureOnEnable(); } } ``` -------------------------------- ### Gradle Kotlin Setup Source: https://github.com/bluemap-minecraft/bluemapapi/wiki/Home Adds BlueMapAPI to a Gradle project using Kotlin. ```kotlin repositories { maven ( "https://repo.bluecolored.de/releases" ) } dependencies { compileOnly ("de.bluecolored:bluemap-api:2.7.7") } ``` -------------------------------- ### Gradle Groovy Setup Source: https://github.com/bluemap-minecraft/bluemapapi/wiki/Home Adds BlueMapAPI to a Gradle project using Groovy. ```groovy repositories { maven { url 'https://repo.bluecolored.de/releases' } } dependencies { compileOnly 'de.bluecolored:bluemap-api:2.7.7' } ``` -------------------------------- ### assetExists Method Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/asset-storage.md Demonstrates how to check if an asset exists in the storage before attempting to read or write it. ```java AssetStorage storage = map.getAssetStorage(); try { if (storage.assetExists("my-icon.png")) { System.out.println("Icon already exists"); } else { System.out.println("Icon needs to be created"); // Write new icon } } catch (IOException e) { System.err.println("Error checking asset: " + e.getMessage()); } ``` -------------------------------- ### Shape Class Examples Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/types.md Examples showing how to create rectangular and circular shapes, as well as a custom shape using the builder pattern. ```java Shape rect = Shape.createRect(0, 0, 100, 100); Shape circle = Shape.createCircle(50, 50, 25, 16); Shape custom = Shape.builder() .addPoint(new Vector2d(0, 0)) .addPoint(new Vector2d(100, 0)) .addPoint(new Vector2d(50, 100)) .build(); ``` -------------------------------- ### Complete Marker Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md This Java code snippet demonstrates how to create and add different types of markers (POI, HTML, Shape, Line) to a BlueMap map. It includes creating a marker set and then populating it with various marker instances, configuring their labels, positions, details, and visual styles. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.BlueMapMap; import de.bluecolored.bluemap.api.markers.*; import de.bluecolored.bluemap.api.math.Color; import de.bluecolored.bluemap.api.math.Shape; import de.bluecolored.bluemap.api.math.Line; import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3d; public class MarkerExample { public static void addMarkers() { BlueMapAPI.getInstance().ifPresent(api -> { api.getMap("world").ifPresent(map -> { // Create marker set MarkerSet markerSet = MarkerSet.builder() .label("Points of Interest") .toggleable(true) .defaultHidden(false) .build(); map.getMarkerSets().put("poi", markerSet); // Add POI marker POIMarker poi = new POIMarker( "Village", new Vector3d(100, 64, 200) ); poi.setDetail("A small village"); markerSet.put("village", poi); // Add HTML marker HtmlMarker html = HtmlMarker.builder() .label("Sign") .position(150, 64, 250) .html("Welcome!") .anchor(new Vector2i(50, 25)) .styleClasses("welcome-sign") .build(); markerSet.put("sign", html); // Add shape marker Shape territory = Shape.createRect(50, 50, 300, 300); ShapeMarker shape = new ShapeMarker("Protected Area", territory, 0); shape.setLineColor(new Color(0, 255, 0, 1)); shape.setFillColor(new Color(0, 255, 0, 0.2f)); shape.setLineWidth(3); markerSet.put("territory", shape); // Add line marker Line path = Line.builder() .addPoint(new Vector3d(100, 64, 200)) .addPoint(new Vector3d(150, 70, 250)) .addPoint(new Vector3d(200, 65, 300)) .build(); LineMarker line = new LineMarker("Path", path); line.setDetail("Trade route"); markerSet.put("trade-route", line); }); }); } } ``` -------------------------------- ### Schedule Rendering Updates Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/README.md Provides examples of how to schedule rendering updates for maps, including full re-renders and updates for specific regions. ```java RenderManager manager = api.getRenderManager(); // Update all changed tiles api.getMaps().forEach(map -> { manager.scheduleMapUpdateTask(map); }); // Force full re-render manager.scheduleMapUpdateTask(map, true); // Update specific regions Collection regions = Arrays.asList(new Vector2i(0, 0)); manager.scheduleMapUpdateTask(map, regions, false); ``` -------------------------------- ### Get Asset URL Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/asset-storage.md Demonstrates how to get the relative URL for an asset and use it in markers or HTML content. ```java AssetStorage storage = map.getAssetStorage(); // Get URL (works even if asset doesn't exist yet) String iconUrl = storage.getAssetUrl("my-icon.png"); System.out.println("Asset URL: " + iconUrl); // e.g., "assets/my-icon.png" // Use in marker POIMarker marker = new POIMarker("Location", position); marker.setIcon(iconUrl, new Vector2i(16, 32)); // Use in HTML String html = "Icon"; HtmlMarker htmlMarker = new HtmlMarker("Info", position, html); ``` -------------------------------- ### Store and Use Custom Assets Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/README.md Shows how to store custom assets like images within a map's asset storage and then reference them, for example, in markers. ```java api.getMap("world").ifPresent(map -> { AssetStorage storage = map.getAssetStorage(); // Store asset try (OutputStream out = storage.writeAsset("icon.png")) { ImageIO.write(image, "png", out); } // Use in marker String url = storage.getAssetUrl("icon.png"); marker.setIcon(url, new Vector2i(16, 32)); }); ``` -------------------------------- ### Store HTML Template Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/asset-storage.md Example of storing an HTML template as an asset and retrieving its URL. ```java // Store HTML template String html = "

{{title}}

{{content}}

"; try (OutputStream out = storage.writeAsset("template.html")) { out.write(html.getBytes(StandardCharsets.UTF_8)); } System.out.println("HTML stored: " + storage.getAssetUrl("template.html")); ``` -------------------------------- ### Set Player Visibility Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/webapp.md Example of hiding and then showing a player in the web app. ```java BlueMapAPI.getInstance().ifPresent(api -> { UUID playerUuid = UUID.fromString("550e8400-e29b-41d4-a716-446655440000"); // Hide player from web app api.getWebApp().setPlayerVisibility(playerUuid, false); // Later, show player again api.getWebApp().setPlayerVisibility(playerUuid, true); }); ``` -------------------------------- ### CustomSkinProviderExample Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md An example implementation of the SkinProvider interface to load custom player skins from Mojang's API. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.plugin.SkinProvider; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Optional; import java.util.UUID; public class CustomSkinProviderExample implements SkinProvider { private static final String SKIN_API = "https://sessionserver.mojang.com/session/minecraft/profile/"; @Override public Optional load(UUID playerUUID) throws IOException { try { // Get skin URL from Mojang API String uuidStr = playerUUID.toString().replace("-", ""); URL url = new URL(SKIN_API + uuidStr); // Fetch and parse response (simplified) // In real code, parse the JSON response // Load skin image from URL InputStream in = url.openStream(); BufferedImage skin = ImageIO.read(in); return Optional.ofNullable(skin); } catch (IOException e) { System.err.println("Failed to load skin for " + playerUUID + ": " + e.getMessage()); return Optional.empty(); } } public static void register() { BlueMapAPI.getInstance().ifPresent(api -> { SkinProvider provider = new CustomSkinProviderExample(); api.getPlugin().setSkinProvider(provider); System.out.println("Custom skin provider registered"); }); } } ``` -------------------------------- ### HtmlMarker setHtml Example Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Sets the HTML content. It's important to escape user input to prevent XSS attacks. ```java // Safe: HTML escaped String userInput = "Player's claim"; String escaped = userInput.replace("&", "&").replace("<", "<").replace(">", ">"); marker.setHtml("

Owned by: " + escaped + "

"); ``` -------------------------------- ### PlayerIconFactory apply method Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md Example implementation of the apply method for creating custom player marker icons. ```java BufferedImage apply(UUID playerUuid, BufferedImage playerSkin) { // Create icon from skin BufferedImage icon = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); // ... custom icon generation ... return icon; } ``` -------------------------------- ### Delete Old Assets Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/asset-storage.md Example of deleting old or unused assets from storage. ```java String[] oldAssets = {"old-icon-v1.png", "deprecated-script.js", "unused-config.json"}; for (String assetName : oldAssets) { try { if (storage.assetExists(assetName)) { storage.deleteAsset(assetName); System.out.println("Deleted: " + assetName); } } catch (IOException e) { System.err.println("Error deleting " + assetName + ": " + e.getMessage()); } } ``` -------------------------------- ### Custom Player Icon Factory Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md An example implementation of a PlayerIconFactory to create custom player icons from their skins. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.plugin.PlayerIconFactory; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.util.UUID; public class CustomPlayerIconFactoryExample implements PlayerIconFactory { @Override public BufferedImage apply(UUID playerUuid, BufferedImage playerSkin) { // Create 32x32 icon from skin BufferedImage icon = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); // Draw skin face (8x8 from skin, scaled to 32x32) Graphics2D g2d = icon.createGraphics(); // Get face region from skin (top-left 8x8 pixels) BufferedImage face = playerSkin.getSubimage(8, 8, 8, 8); // Scale face to fill icon java.awt.Image scaled = face.getScaledInstance(32, 32, java.awt.Image.SCALE_FAST); g2d.drawImage(scaled, 0, 0, null); // Optional: Add overlay BufferedImage overlay = playerSkin.getSubimage(40, 8, 8, 8); java.awt.Image scaledOverlay = overlay.getScaledInstance(32, 32, java.awt.Image.SCALE_FAST); g2d.drawImage(scaledOverlay, 0, 0, null); g2d.dispose(); return icon; } public static void register() { BlueMapAPI.getInstance().ifPresent(api -> { PlayerIconFactory factory = new CustomPlayerIconFactoryExample(); api.getPlugin().setPlayerMarkerIconFactory(factory); System.out.println("Custom player icon factory registered"); }); } } ``` -------------------------------- ### Custom Display Name Provider Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md An example implementation of a PlayerDisplayNameProvider to set custom display names for players. ```java import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.plugin.PlayerDisplayNameProvider; import java.util.HashMap; import java.util.Map; import java.util.UUID; public class CustomDisplayNameProviderExample implements PlayerDisplayNameProvider { private final Map customNames = new HashMap<>(); public CustomDisplayNameProviderExample() { // Initialize with some mappings // In real code, load from config, database, etc. } @Override public String get(UUID playerUUID) { // Return custom name if exists, otherwise return UUID return customNames.getOrDefault(playerUUID, playerUUID.toString()); } public void setDisplayName(UUID playerUUID, String displayName) { customNames.put(playerUUID, displayName); } public static void register() { BlueMapAPI.getInstance().ifPresent(api -> { CustomDisplayNameProviderExample provider = new CustomDisplayNameProviderExample(); // Set some custom names provider.setDisplayName( UUID.fromString("550e8400-e29b-41d4-a716-446655440000"), "Admin Player" ); provider.setDisplayName( UUID.fromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8"), "Moderator" ); api.getPlugin().setPlayerDisplayNameProvider(provider); System.out.println("Custom display name provider registered"); }); } } ``` -------------------------------- ### Register a JavaScript file Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/webapp.md Registers a JavaScript file for the web app to load. This method must only be called inside the Consumer registered to BlueMapAPI.onEnable(), before the server starts. Script registrations are not persistent — register your scripts each time BlueMap enables. ```java void registerScript(String url) ``` ```java BlueMapAPI.onEnable(api -> { WebApp webApp = api.getWebApp(); Path webRoot = webApp.getWebRoot(); // Create custom script file Path jsDir = webRoot.resolve("custom"); Files.createDirectories(jsDir); Path jsFile = jsDir.resolve("custom.js"); String js = "console.log('Custom script loaded');\n" + "bluemap.addEventListener('mapLoad', function(event) {\n" + " console.log('Map loaded:', event.map); });"; Files.write(jsFile, js.getBytes(StandardCharsets.UTF_8)); // Register the script webApp.registerScript("custom/custom.js"); }); ``` -------------------------------- ### Initialize and Listen for BlueMap Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/README.md This snippet shows how to initialize the BlueMap API and listen for its readiness, allowing access to its features. ```java BlueMapAPI.onEnable(api -> { System.out.println("BlueMap is ready!"); // Access maps, configure rendering, etc. }); BlueMapAPI.getInstance().ifPresent(api -> { // Use API at any time }); ``` -------------------------------- ### Build BlueMapAPI Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/README.md Command to build BlueMapAPI using Gradle. ```bash ./gradlew build ``` -------------------------------- ### Get Marker Position Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Returns the world position of this marker. ```java Vector3d getPosition() ``` -------------------------------- ### Get Marker Type Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Returns the type identifier of this marker. ```java String getType() ``` -------------------------------- ### Create a builder for MarkerSets Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Creates a builder for constructing MarkerSets with a fluent API. ```java static Builder builder() ``` -------------------------------- ### Clone BlueMapAPI Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/README.md Command to clone the BlueMapAPI repository using Git. ```bash git clone https://github.com/BlueMap-Minecraft/BlueMapAPI.git ``` -------------------------------- ### Get Marker Label Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/markers.md Returns the display label of this marker. HTML tags are escaped. ```java String getLabel() ``` -------------------------------- ### Get Current Skin Provider Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/plugin-interfaces.md Retrieves the currently active SkinProvider used by BlueMap. ```java BlueMapAPI.getInstance().ifPresent(api -> { SkinProvider provider = api.getPlugin().getSkinProvider(); System.out.println("Current skin provider: " + provider.getClass().getName()); }); ``` -------------------------------- ### Get Render Thread Count Source: https://github.com/bluemap-minecraft/bluemapapi/blob/master/_autodocs/api-reference/render-manager.md Returns the number of active render threads currently processing tasks. ```java int threads = renderManager.renderThreadCount(); System.out.println("Render threads: " + threads); ```