Got a question that the wiki doesn't answer? Ask on the forum (preferred), or join us on IRC.

BeastNode

Bukkit map API

From EngineHub.org Wiki
Jump to: navigation, search

Goals:

  • Two types of maps: "actual" maps that contain the original in-game map and "virtual" maps that have their own "base" renderer.
  • "Overlay" renderers that draw on a buffer (another layer, basically) on top of the base layer can be registered. For actual maps, since the Minecraft map is already the base layer, you can only register overlay renderers.
  • Per-user maps should be supported.
  • Have an expansive drawing API with font and shape support.
Warning: The API is not entirely final yet. There are problems that need to be fixed.

Overview

A starting point may be the API overview.

Sample code

Register map listener

getServer().getPluginManager().registerEvent(Event.Type.MAP_INITIALIZE,
    new MapListener(), Priority.Normal, this);

Map listener

public class MapListener {
    @Override
    public void onMapInitialize(MapInitializeEvent event) {
        if (event.getMapView().getId() == 1) {
            event.getMapView().registerVirtualBase(new NyanCatBase(), plugin);
            return;
        }
    }
}

Base map renderer

import org.bukkit.maps.MapCanvas;
import org.bukkit.maps.MapPrintOrder;
import org.bukkit.maps.MapRenderer;
import org.bukkit.maps.MapView;
import com.sk89q.mapbook.Liquid.LiquidTest;
 
public class NyanCatBase implements MapRenderer {
    int inj = -1;
    int cont = 0;
 
    public void render(MapView map, MapCanvas canvas) {
        map.setRate(128);
        map.setPrintOrder(MapPrintOrder.Sequential);
 
        if ((cont++ % 60) != 0)
            return;
 
        inj++; 
        BufferedImage img;
 
        try {
            img = ImageIO.read(new File("acertaincat_"
                    + (((inj) % 12) + 1) + ".png"));
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
 
        map.getDrawer().drawImage(img);
 
        return;
    }
 
    public void initialize(MapView map) {
    }
 
}

Examples of the API

Doable with the API

Warning: That video required ~300 kilobytes/sec of bandwidth.

Navigation menu