Solved Map Cursors resetting when leaving server

Discussion in 'Spigot Plugin Development' started by Ajneb97, Jul 6, 2018.

  1. Hello, I am trying to do a minigame plugin using Maps. When users join the minigame they will receive a map containing a lot of blue mapcursors and their own position. Everything works fine at the first game. When people leaves the arena the map is removed from its inventory. I am removing the MapRenderer for each map like this:
    Code (Java):
    for(MapRenderer r : mapView.getRenderers()){
            mapView.removeRenderer(r);
    }
    But when users play again, they receive the same map with the previous Map Cursors on it. The Cursors should be resetting every time but I don't know why is not happening. As the title says, when player leave the servers and rejoin the issue is fixed and the Map Cursors are removed correctly.

    So my question is: How can I remove the Map Cursors without the player leaving the server? Is there a file that saves this player data?

    I've also tried this at the start of the "render" method and doesn't work:
    Code (Java):
    MapCursorCollection cursores = canvas.getCursors();
    for(int i=0;i<cursores.size();i++){
        cursores.removeCursor(cursores.getCursor(i));
    }
     
  2. First of all, you need to post your rendering code so we can see where the issue is. AFAIK cursors should be permanently removed when you remove them from a MapCanvas.

    For each map? Are you creating a new map for every player? If so, you can use one contextual map instead.
     
  3. This is my class which extends from MapRenderer

    Code (Java):



    public class Renderer extends MapRenderer{

        private double radio;
        private double coordx;
        private double coordz;
        private Image image;
        private int i;
     
        public Renderer(double coordx, double coordz, double radio,Image image){
            this.radio = radio;
            this.coordx = coordx;
            this.coordz = coordz;
            this.image = image;
            this.i = 0;
        }
        @SuppressWarnings("deprecation")
        @Override
        public void render(MapView view, MapCanvas canvas, Player player) {
            MapCursorCollection cursores = canvas.getCursors();
            for(int i=0;i<cursores.size();i++){
                cursores.removeCursor(cursores.getCursor(i));
            }
            if(i==0){
                i++;
                canvas.drawImage(0,0,image);
            }
            int jugadorZ = (int) player.getLocation().getZ();
            int jugadorX = (int) player.getLocation().getX();
            int coordenadaJugadorZ = getCoordenadaZ(jugadorZ);
            int coordenadaJugadorX = getCoordenadaX(jugadorX);
            cursores.addCursor(coordenadaJugadorX, coordenadaJugadorZ, (byte) 0,MapCursor.Type.WHITE_POINTER.getValue(),true);
            /*
            int z = (int) (coordz-radio);
            int coordenadaZ = getCoordenadaZ(z);
            cursores.addCursor(0, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(15, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(30, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(45, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(60, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(75, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(90, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(105, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(120, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-15, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-30, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-45, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-60, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-75, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-90, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-105, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-120, coordenadaZ, (byte) 0,MapCursor.Type.BLUE_POINTER.getValue(),true);
            z = (int) (coordz+radio);
            coordenadaZ = getCoordenadaZ(z);
            cursores.addCursor(0, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(15, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(30, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(45, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(60, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(75, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(90, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(105, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(120, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-15, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-30, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-45, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-60, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-75, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-90, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-105, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(-120, coordenadaZ, (byte) 8,MapCursor.Type.BLUE_POINTER.getValue(),true);
            int x = (int) (coordx+radio);
            int coordenadaX = getCoordenadaX(x);
            cursores.addCursor(coordenadaX, 0, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 15, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 30, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 45, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 60, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 75, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 90, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 105, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 120, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -15, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -30, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -45, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -60, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);  
            cursores.addCursor(coordenadaX, -75, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -90, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -105, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -120, (byte) 4,MapCursor.Type.BLUE_POINTER.getValue(),true);
            x = (int) (coordx-radio);
            coordenadaX = getCoordenadaX(x);
            cursores.addCursor(coordenadaX, 0, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 15, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 30, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 45, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 60, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 75, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 90, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 105, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, 120, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -15, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -30, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -45, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -60, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -75, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -90, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -105, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            cursores.addCursor(coordenadaX, -120, (byte) 12,MapCursor.Type.BLUE_POINTER.getValue(),true);
            */

            canvas.setCursors(cursores);
               
       
        }
        //De parametro de entrada es una coordenada Z
        private int getCoordenadaZ(int z){
            //radio = 490/2 = 245
            //6425,-595 -> 0,0
       
            //6425,-840 -> 0,-128
            // x1=-595 y1=-0
            // x2=-840 y2=-128
       
            //Ecuacion de la recta
       
            // y = mx1 + y1;  
            double x1=coordz;
            double x2=coordz-radio;  
            double y1=0;
            double y2=-128;
            double m = (y2-y1)/(x2-x1);
            double resultado = m*(z-coordz);
            int r = (int) resultado;
            if(r == 128){
                return 127;
            }
            return r;
        }
     
        private int getCoordenadaX(int x){
            double x1=coordx;
            double x2=coordx-radio;  
            double y1=0;
            double y2=-128;
            double m = (y2-y1)/(x2-x1);
            double resultado = m*(x-coordx);
            int r = (int) resultado;
            if(r == 128){
                return 127;
            }
            return r;
        }
    }
     
    It is the same number of map for each player, but it is renderer different for them. One player sees himself on the map but can't see others. I want a way to remove/reset the cursors from the map when the player finishes or leave the minigame.
     
  4. Sorry, I missed this in your original post. The issue is that you're looping through the cursors (i++) and removing at the same time. Use this instead:
    Code (Text):
    while(cursores.size() > 0)
    {
        cursores.removeCursor(cursores.getCursor(0));
    }
     
  5. Not working, the cursors are still there. But again, when player leaves the server, rejoin, and join a game, the map is resetted correctly.
     
  6. Weird. Please print the canvas' cursors when the player sees the old cursor on the map. Also, what spigot version are you using?
     
  7. The player see their old cursor on the map and he can't see their current one. I am using spigot 1.8.8

    [​IMG]
     
  8. I actually meant print as text to the console :p, but your image helped me understand your issue so no need to do it.
    Since the player's new cursor only appears after a relog, I'm guessing that this is a client-side bug. I remember seeing something like this when I was working with maps.
    You could try sending a map packet with the correct cursors (or none) if nothing else works.
    You should also use a recent version Spigot since this issue might already be fixed.
     
  9. Its a Mojang bug. It's marked as "Resolved: Wont Fix" so they are not going to fix this.

    Here's what a commenter said in the report:
    So pretty much anything to do with map cursors is as-is and wont get fixed.
     
    • Useful Useful x 2
  10. Lol I didn't know that, thanks. If I want to continue this project then, I think I would need to set up the arenas in different servers, so when the player quits, map items will be resetted correctly. (It is a personal plugin so it is not really a big deal)