Skip to content

API Basics

Jason edited this page May 7, 2022 · 1 revision

To get an instance of the squaremap API:

Squaremap api = SquaremapProvider.get();

To get a MapWorld from the API:

World world = Bukkit.getWorld("world");
MapWorld mapWorld = api.getWorldIfEnabled(BukkitAdapter.worldIdentifier(world)).orElse(null);

To create a LayerProvider:

SimpleLayerProvider provider = SimpleLayerProvider.builder("Layer Label")
  .showControls(true)
  .defaultHidden(false)
  .layerPriority(5);
  .zIndex(250);
  .build();

To register your LayerProvider to a MapWorld:

api.getWorldIfEnabled(world).ifPresent(mapWorld -> {
  Key key = Key.of("my_unique_layer_key");
  SimpleLayerProvider provider = SimpleLayerProvider.builder("My Layer")
    .showControls(true)
    .build();
  mapWorld.layerRegistry().register(key, provider);
});

To add Markers to your LayerProvider:

Key key = Key.of("my_unique_marker_key");

Point p1 = Point.of(100, 150);
Point p2 = Point.of(200, 250)

Rectangle marker = Marker.rectangle(p1, p2);

provider.addMarker(key, marker);