Solved Need help with rendering a custom image on multiple maps

Discussion in 'Spigot Plugin Development' started by zackatack108, Aug 2, 2018.

  1. Okay so I'm trying to make a plugin to replace one I currently have since it doesn't seem to be updating to 1.13. The plugin I'm trying to replace is to put custom images on maps. Now I followed this tutorial https://www.spigotmc.org/threads/tutorial-maps.136533/ and got it to render an image on one map. However when I try to do a second image it will give me a new map but it also replaces the image on the previous map to be the new image. I don't know why it's doing this since I'm new to doing the images on maps. Any help would be appreciated thanks.

    Code (Text):
    @SuppressWarnings("deprecation")
        private void createMap(Player player, String[] args) {
           
            if(args.length == 2) {
               
                String url = args[1];
               
                try {
                   
                    BufferedImage image = ImageIO.read(new URL(url));
                    Renderer.setImage(image);
                   
                    World world = Bukkit.getServer().getWorld("world");
                   
                    MapView view = Bukkit.getServer().createMap(world);              
                    view.removeRenderer(view.getRenderers().get(0));
                    view.getRenderers().clear();
                    view.addRenderer(new Renderer());
                   
                    ItemStack mapItem = new ItemStack(Material.FILLED_MAP, 1);
                   
                    MapMeta mapMeta = (MapMeta) mapItem.getItemMeta();
                    mapMeta.setMapId(view.getId());
                    mapItem.setItemMeta(mapMeta);
                   
                    //mapItem.setDurability(view.getId());
                   
                    player.getInventory().addItem(mapItem);
                   
                    //int ID = view.getId();              
                    //MapListener.addMapID(ID);
                   
                   
                } catch (IOException e) {
                    e.printStackTrace();
                }
               
            }
           
        }

    Code (Text):
    static BufferedImage image;

        static public void setImage(BufferedImage image_) {
            if(image_ != null) {
                image = image_;
            }
        }

        @Override
        public void render(MapView view, MapCanvas canvas, Player player) {
            canvas.drawImage(0, 0, image);
        }
     
  2. Code (Text):
    static BufferedImage image;
    You're sharing the same BufferedImage across all instances of your Renderer- that needs to be non-static.