Manipulating Maps

Discussion in 'Plugin Development' started by TheTrixsta, Jul 16, 2012.

  1. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I want to give a player a map upon joining the server and then the map will display custom text and images. Is there anyway I could get a small pseudocode or something?
  2. Offline

    Kodfod

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    try the spout forums, not sure that this is possible with out it
  3. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    No it is ;)
  4. Offline

    Kodfod

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Then i would love to know how to =D *goes to look in the docs*
  5. Offline

    Kodfod

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  6. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  7. Offline

    sayaad

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Here is a documentation of the map API and example usage ;)
  8. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @TheTrixsta let me link you to this. There's some kind of chicken and egg problem: We need a MapCanvas to render but we don't know how to create it...
    TheTrixsta likes this.
  9. Offline

    desht

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You don't need to ever create a MapCanvas - there's more info on the thread @V10lator linked to, but in summary:
    • You can use Bukkit.getMap() or Bukkit.createMap() to get yourself a MapView object. The map id you pass to getMap() is the map item's durability value (http://jd.bukkit.org/apidocs/org/bukkit/inventory/ItemStack.html#getDurability())
    • You need to create a class which extends the Bukkit MapRenderer abstract class, and implement the render() method. That method is passed the MapView, a MapCanvas (already created for you!) and the Player that is holding the map. You do all your drawing in there.
    • Now you can add your custom renderer to the MapView for the map in question with the MapView addRenderer() method. You will probably also want to remove the vanilla map renderer with the removeRenderer() method.
    • You can use player.sendMap(mapview) in your render() method (usually at the end) to send all changes at once - if you don't, you'll see the map redraw itself slowly, like an ordinary map does. Do be careful not to spend too much time in the render() method, and don't call player.sendMap() unless there's actually a new image to send - render() gets called every tick that a player is holding a map up, and you don't want to cause lag.
    bobacadodl, TheTrixsta and Digi like this.
  10. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Your awesome :3
  11. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Your post really helped!
  12. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Im still not understading this :p, do you have and pseudo code, i dont know where to update the map the player is holding :/
  13. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Synaps3, TheTrixsta and desht like this.
  14. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  15. Offline

    Cirno

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Suddenly, after md_5 made his offtopic post, everyone seems to want to use the MapAPI.
  16. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I never saw that post ;)
  17. Offline

    Cirno

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I never said everyone saw the post, I just said after the post :3
  18. Offline

    TheTrixsta

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    touche

Share This Page