Solved MapSend - ConcurrentModificationException

Discussion in 'Plugin Development' started by pollag, Dec 22, 2012.

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

    pollag

    Hello,
    I am trying to create a plugin that generate custom map (item) and I would like the render to be instantaneous. So I use the function sendMap(MapView) in a custom MapRender class in function render(MapView MV, MapCanvas MC, Player P). When I launch my plugin, an Exception appear ( ConcurrentModificationException ) in the line that contains the function sendMap.

    I would know how I can resolve it

    Pollag

    Candera - https://www.youtube.com/playlist?list=PLFemUQtvBHc_rkwZfKbx-GGO5lld5wVIM - A french Server

    PS : Sorry for my bad english
    PHP:
    package fr.pollag.masterMap;
     
    import org.bukkit.entity.Player;
    import org.bukkit.map.MapCanvas;
    import org.bukkit.map.MapRenderer;
    import org.bukkit.map.MapView;
    import org.bukkit.map.MinecraftFont;
     
    public class 
    MMRMainMenu extends MapRenderer {
       
        
    boolean send;
        static 
    String type;
       
        public 
    MMRMainMenu() {
            
    super(true);
            
    send false;
        }
       
        public static 
    void setMenu(String menu) {
            
    type menu;
        }
       
        @
    Override
        
    public void render(MapView MVMapCanvas MCPlayer P) {
            if(
    send == false) {
                
    send true;
                
    P.sendMap(MV);
            } else if(
    send == true) {
                if(
    type.equalsIgnoreCase("Main1")) {
                    
    MC.drawText(1010MinecraftFont.Font"1");
                }
                if(
    type.equalsIgnoreCase("Main2")) {
                    
    MC.drawText(1010MinecraftFont.Font"2");
                }
                if(
    type.equalsIgnoreCase("Main3")) {
                    
    MC.drawText(1010MinecraftFont.Font"3");
                }
                if(
    type.equalsIgnoreCase("Main4")) {
                    
    MC.drawText(1010MinecraftFont.Font"4");
                }
                if(
    type.equalsIgnoreCase("Main5")) {
                    
    MC.drawText(1010MinecraftFont.Font"5");
                }
                if(
    type.equalsIgnoreCase("Main6")) {
                    
    MC.drawText(1010MinecraftFont.Font"6");
                }
                for (
    MapRenderer r MV.getRenderers()) {
                    
    MV.removeRenderer(r);
                }
            }
        }
    }

     
  2. Offline

    ferrybig

    What is the exact error?
     
  3. Offline

    pollag

    11:24:45 [WARNING] Failed to handle packet for charliag22/127.0.0.1: java.util.C
    oncurrentModificationException
    java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
    at java.util.AbstractList$Itr.next(Unknown Source)
    at org.bukkit.craftbukkit.map.CraftMapView.render(CraftMapView.java:138)

    at org.bukkit.craftbukkit.entity.CraftPlayer.sendMap(CraftPlayer.java:33
    4)
    at fr.pollag.masterMap.MMRMainMenu.render(MMRMainMenu.java:27)
    at org.bukkit.craftbukkit.map.CraftMapView.render(CraftMapView.java:146)

    at net.minecraft.server.WorldMapHumanTracker.a(WorldMapHumanTracker.java
    :44)
    at net.minecraft.server.WorldMap.getUpdatePacket(WorldMap.java:213)
    at net.minecraft.server.ItemWorldMap.c(ItemWorldMap.java:231)
    at net.minecraft.server.EntityPlayer.g(EntityPlayer.java:198)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:350)
    at net.minecraft.server.Packet10Flying.handle(SourceFile:136)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:290)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:113)
    at net.minecraft.server.ServerConnection.b(SourceFile:39)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595)
    at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    >
     
  4. Offline

    ftbastler

    A ConcurrentModificationException occurs when u are removing an item from an ArrayList in an for loop of that ArrayList.

    You are removing an item of MV while looping through MV.
    PHP:
    for (MapRenderer r MV.getRenderers()) {
      
    MV.removeRenderer(r);
    }
    Resolve the issue:
    PHP:
    MV.getRenderers().clear()
     
  5. Offline

    pollag

    Thanks ! It's working perfectly !
     
Thread Status:
Not open for further replies.

Share This Page