Solved Working with Map Items

Discussion in 'Plugin Development' started by Jogy34, Jul 31, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Jogy34

    For one of my plugins I want to use maps to essentially track things and I've looked around and couldn't find anything on working with maps.

    Here's a list of things I want to be able to do with them:
    • Create a new map and put it in an item frame
    • Set the map's center X and Z at will
    • draw cursors on to them at will
    • Render the entire map area using any available scale
    Any help anyone can give is greatly appreciated.
     
  2. Offline

    xTrollxDudex

    Jogy34
    Create a new map
    PHP:
    MapView map Bukkit.createMap(/*world*/);
    1. Put in itemframe
    PHP:
    //hanging place event
    Hanging h event.getEntity();
    if(
    instanceof ItemFrame){
    ItemFrame f = (ItemFrameh;
    f.setItem(new ItemStack(Material.MAP1map.getId()));
    f.setRotation(Rotation.NONE);
    }
    2. Set center
    PHP:
    map.setCenterX(/*int*/);
    map.setCenterZ(/*int*/);
    3. Draw cursors

    PHP:
    public class Renderer extends MapRenderer{
    public 
    MapCursorCollection col;
    public 
    MapView.Scale scale;

    @
    Override
    public void render(MapView vMapCanvas mcPlayer p){
    for(
    MapCursor c mc.getCursors()){
    mc.getCursors().removeCursor(c);
    }
    mc.setCursors(this.col);
    v.setScale(this.scale);
    }
    public static 
    void renderMap(MapView mMapCursorCollection colMapView.Scale scale){
    for(
    MapRenderer r m.getRenderers()){
    m.removeRenderer(r);
    }
    this.scale scale;
    map.addRenderer(new Renderer(col));
    }
    }
    To use, for example get players
    PHP:
    public MapCursorCollection c = new MapCursorCollection();
    public 
    void addPlayers(){
    for(
    MapCursor m c){
    c.removeCursor(m);
    }

    for(
    Player p Bukkit.getOnlinePlayers()){
    Location l p.getLocation();
    MapCursor mc = new MapCursor((bytel.getX(), (bytel.getZ(), (byte2, (byteMapCusor.Type.GREEN_POINTERtrue);
    //x is from 127- -128; z is from 127- -128, 2 is from 0-15(direction), green pointer is the type, and true is visibility

    c.addCursor(mc);
    }
    addPlayers();
    Renderer.renderMap(mapcMapView.Scale.FAR);
    4. Render map
    Included above
     
    LRRoberts0122 likes this.
  3. Offline

    Jogy34


    Thanks. That's a lot simpler than I thought it would be.
     
  4. Offline

    xTrollxDudex

    Jogy34
    Glad to help. I honestly had no idea how it worked before this thread, an hour of googling/looking at the javadocs relvealed the solution
     
  5. Offline

    Jogy34

    Do you happen to know how I would go about forcing a map to render at it's location but from a different world? I was thinking about doing that in my own renderer using what minecraft does for choosing the color of each pixel but I can't find where that's done.
     
  6. Offline

    xTrollxDudex

    Jogy34
    I didn't get the "render from a different world" part
     
  7. Offline

    Jogy34

    The map's center is in one world but a player has the map in a different world. The map won't render the terrain.
     
  8. Offline

    xTrollxDudex

    Jogy34
    Create a new map for the world and replace the one in his inventory with the new one?
     
  9. Offline

    Jogy34

    When I do that the map is blank with the cursors that I put on it.
     
  10. Offline

    xTrollxDudex

    Jogy34
    Could I see the code?
     
  11. Offline

    Jogy34

    I don't do anything special for drawing the terrain. I only add cursors and change the center.
     
Thread Status:
Not open for further replies.

Share This Page