Interface MapManager


public interface MapManager
Creates and finds maps, and makes what plugins draw on them: canvases, images, fonts and layers.

Maps are saved with the world, in data/minecraft/maps, under the same ids and in the same format as vanilla, so maps made on a vanilla server keep working. They are loaded the first time someone needs them and unloaded once nobody has looked at them for a while.

Since:
0.1.0
See Also:
  • Method Details

    • create

      MapView create(World world, int centerX, int centerZ, MapScale scale)
      Creates a map of the terrain of a world, drawn as players carrying it explore.
      Parameters:
      world - the world
      centerX - the X coordinate of the block at the center
      centerZ - the Z coordinate of the block at the center
      scale - how many blocks a pixel covers
      Returns:
      the new map, saved with the world
      Since:
      0.1.0
      See Also:
    • createBlank

      MapView createBlank()
      Creates a map that shows no world: a blank canvas for plugins to draw on.
      Returns:
      the new map, saved with the world
      Since:
      0.1.0
    • createTemporary

      MapView createTemporary()
      Creates a blank map that is never saved, for content that only makes sense while the server runs: a game screen, a live chart. Its id is taken from the top of the id range, far from the ids of saved maps, and given back by delete(MapView).
      Returns:
      the new map
      Since:
      0.1.0
    • get

      Optional<MapView> get(int id)
      Finds a map, loading it from disk if needed.
      Parameters:
      id - the id
      Returns:
      the map, or empty if no map has this id
      Since:
      0.1.0
    • of

      Finds the map an item shows.
      Parameters:
      stack - an item; only a filled_map with a minecraft:map_id shows one
      Returns:
      the map, or empty if the item shows none, or one that does not exist
      Since:
      0.1.0
    • loaded

      Collection<MapView> loaded()
      Returns the maps currently in memory.
      Returns:
      the maps currently in memory
      Since:
      0.1.0
    • delete

      void delete(MapView view)
      Deletes a map: its file for a saved map, its id for a temporary one. Items still showing it show an unknown map.
      Parameters:
      view - the map
      Since:
      0.1.0
    • lockedCopy

      MapView lockedCopy(MapView source)
      Copies a map as a cartography table locks it: a new map with the same pixels and markers whose terrain never changes again.
      Parameters:
      source - the map to copy
      Returns:
      the new, locked map
      Since:
      0.1.0
    • zoomedOut

      MapView zoomedOut(MapView source)
      Makes the zoomed out version of a map, as a cartography table with paper does: a new, empty map of the next scale, centered on the grid cell holding the old center.
      Parameters:
      source - the map to zoom out
      Returns:
      the new map; a copy of the same scale if the source is already the widest
      Since:
      0.1.0
    • colorOf

      MapColor colorOf(BlockData block)
      Returns the color a block is drawn with on terrain maps.

      That is the color given by the behaviour of the block if it gives one, or the vanilla one.

      Parameters:
      block - a block state
      Returns:
      its color, MapColor.NONE for blocks that maps look through
      Since:
      0.1.0
    • palette

      MapPalette palette()
      Returns the colors of map pixels.
      Returns:
      the colors of map pixels
      Since:
      0.1.0
    • createCanvas

      MapCanvas createCanvas()
      Creates a canvas that belongs to no map, filled with transparent pixels. Useful to prepare a picture, then copy it onto maps.
      Returns:
      the canvas
      Since:
      0.1.0
    • image

      MapImage image(int width, int height, byte[] pixels)
      Wraps pixels that are already map pixels.
      Parameters:
      width - the width, at least 1
      height - the height, at least 1
      pixels - width * height map pixels, row by row; copied
      Returns:
      the image
      Since:
      0.1.0
    • image

      MapImage image(int width, int height, int[] argb, MapImage.Dithering dithering)
      Converts colors to map pixels. Colors with an alpha below 128 become transparent, the others take the closest map color.
      Parameters:
      width - the width, at least 1
      height - the height, at least 1
      argb - width * height colors as 0xAARRGGBB, row by row
      dithering - how to approximate colors
      Returns:
      the image
      Since:
      0.1.0
    • image

      MapImage image(BufferedImage image, MapImage.Dithering dithering)
      Converts a picture to map pixels, at its own size.
      Parameters:
      image - the picture
      dithering - how to approximate colors
      Returns:
      the image
      Since:
      0.1.0
    • image

      MapImage image(BufferedImage image, int width, int height, MapImage.Dithering dithering)
      Scales a picture, then converts it to map pixels. To fill a wall of n×m maps, scale to 128n×128m and cut the result into tiles.
      Parameters:
      image - the picture
      width - the width to scale to, at least 1
      height - the height to scale to, at least 1
      dithering - how to approximate colors
      Returns:
      the image
      Since:
      0.1.0
    • standardFont

      MapFont standardFont()
      Returns the built-in font: proportional, 7 pixels high, with the accents of Western European languages above capitals.
      Returns:
      the built-in font: proportional, 7 pixels high, with the accents of Western European languages above capitals
      Since:
      0.1.0
    • fontBuilder

      MapFont.Builder fontBuilder(int lineHeight, int ascent)
      Starts a font of your own.
      Parameters:
      lineHeight - how many pixels apart lines are, at least 1
      ascent - how many pixels below the top of a line glyph row 0 is, at least 0
      Returns:
      the builder
      Since:
      0.1.0
    • layer

      MapLayer layer(MapLayer.Scope scope, int repaintInterval, Consumer<MapLayer.Context> painter)
      Creates a layer from a painter.
      Parameters:
      scope - for whom it is painted
      repaintInterval - repaint every that many ticks; 0 only repaints on MapView.repaint() and, for a per-viewer layer, when someone starts seeing the map
      painter - what to paint
      Returns:
      the layer, to add to maps
      Since:
      0.1.0
    • alignedCenter

      int alignedCenter(int coordinate, MapScale scale)
      Snaps a coordinate to the center of the grid cell it falls in, as vanilla does for new maps, so that maps of the same scale tile the world without overlapping.
      Parameters:
      coordinate - a block X or Z coordinate
      scale - the scale of the map
      Returns:
      the X or Z of the center of the map covering that coordinate
      Since:
      0.1.0
    • directionOf

      int directionOf(float yaw)
      Converts a yaw to the direction of an icon.
      Parameters:
      yaw - a yaw in degrees, as in a location: 0 faces south, 90 west
      Returns:
      the direction a player arrow must have to point the same way on a terrain map
      Since:
      0.1.0