Map API

Discussion in 'Plugin Development' started by Windwaker, Nov 3, 2011.

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

    Windwaker

    I am having trouble with the Map API. For some reason, it will only let me draw text only on one map, one time, for each world.

    Main class:
    Code:java
    1. package com.gmail.walkercrouse.ArvinaMaps;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.event.Event.Priority;
    7. import org.bukkit.event.Event.Type;
    8. import org.bukkit.plugin.PluginManager;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. import com.gmail.walkercrouse.ArvinaMaps.listeners.ArvinaServerListener;
    12.  
    13. public class ArvinaMaps extends JavaPlugin{
    14. // declare listeners
    15. private final ArvinaServerListener serverListener = new ArvinaServerListener(this);
    16. // misc. strings
    17. public String version = "v0.1";
    18. public String prefix = "[" + ChatColor.GOLD + "ArvinaMaps" + ChatColor.WHITE + "]";
    19. public static final Logger log = Logger.getLogger("Minecraft");
    20. public void onEnable(){
    21. // register events
    22. PluginManager pm = getServer().getPluginManager();
    23. pm.registerEvent(Type.MAP_INITIALIZE, serverListener, Priority.Normal, this);
    24. log.info("[ArvinaMaps] ArvinaMaps " + version + " enabled!");
    25. }
    26. public void onDisable(){
    27. log.info("[ArvinaMaps] ArvinaMaps " + version + " enabled.");
    28. }
    29. }


    NameRenderer class:
    Code:java
    1. package com.gmail.walkercrouse.ArvinaMaps;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.map.MapCanvas;
    5. import org.bukkit.map.MapRenderer;
    6. import org.bukkit.map.MapView;
    7. import org.bukkit.map.MinecraftFont;
    8.  
    9. public class NameRenderer extends MapRenderer{
    10. public static ArvinaMaps plugin;
    11. public NameRenderer(ArvinaMaps instance){
    12. plugin = instance;
    13. }
    14. @Override
    15. public void render(MapView map, MapCanvas canvas, Player player) {
    16. canvas.drawText(10, 10, MinecraftFont.Font, "Hello world!");
    17. }
    18. public static void drawToMap(MapView map){
    19. for (MapRenderer renderer : map.getRenderers()) {
    20. map.removeRenderer(renderer);
    21. }
    22. map.addRenderer(new NameRenderer(plugin));
    23. }
    24. }


    ServerListener class:
    Code:java
    1. package com.gmail.walkercrouse.ArvinaMaps.listeners;
    2.  
    3. import org.bukkit.event.server.MapInitializeEvent;
    4. import org.bukkit.event.server.ServerListener;
    5. import org.bukkit.map.MapView;
    6.  
    7. import com.gmail.walkercrouse.ArvinaMaps.ArvinaMaps;
    8. import com.gmail.walkercrouse.ArvinaMaps.NameRenderer;
    9.  
    10. public class ArvinaServerListener extends ServerListener{
    11. public static ArvinaMaps plugin;
    12. public ArvinaServerListener(ArvinaMaps instance){
    13. plugin = instance;
    14. }
    15. public void onMapInitialize(MapInitializeEvent event){
    16. MapView map = event.getMap();
    17. System.out.println("Map initialized");
    18. NameRenderer.drawToMap(map);
    19. }
    20. }


    Insight?

    To re-iterate, what happens:
    • If I create a new world, and render a map it works
    • If I try to initialize any other maps, my renderer does not work
    • If I delete the world and make a new one I can do it again
    The map only renders one time, in one world only if the world hasn't had a rendered map in it before :3

    I'm nearly convinced this is a Bukkit bug @EvilSeph @Dinnerbone

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  2. Offline

    feildmaster Retired Staff

Thread Status:
Not open for further replies.

Share This Page