1.12.2 BlockBreakEvent - ConcurrentModificationException

Discussion in 'Spigot Plugin Development' started by XATuKO, Feb 8, 2020.

Thread Status:
Not open for further replies.
  1. Hey. Getting ConcurrentModification exception in console:
    [18:52:31 ERROR]: Could not pass event BlockBreakEvent to CauldronTP v1.1-SNAPSHOT
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:72) ~[paper.jar:git-Paper-1611]
    at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78) ~[paper.jar:git-Paper-1611]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[paper.jar:git-Paper-1611]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:513) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.PlayerInteractManager.breakBlock(PlayerInteractManager.java:322) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.PlayerInteractManager.a(PlayerInteractManager.java:124) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:920) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.PacketPlayInBlockDig.a(SourceFile:40) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.PacketPlayInBlockDig.a(SourceFile:10) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14) ~[paper.jar:git-Paper-1611]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_211]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_211]
    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:850) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:423) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:774) ~[paper.jar:git-Paper-1611]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:666) ~[paper.jar:git-Paper-1611]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(Unknown Source) ~[?:1.8.0_211]
    at java.util.ArrayList$Itr.next(Unknown Source) ~[?:1.8.0_211]
    at ru.ibusewinner.fundaily.caltp.PlayersListener.onBlockBreak(PlayersListener.java:151) ~[?:?]
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor3.execute(Unknown Source) ~[?:?]
    at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:70) ~[paper.jar:git-Paper-1611]
    ... 17 more

    151 line: if(b.getType().equals(Material.CAULDRON)) {

    My code:
    Code (Java):
        @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
            Player p = e.getPlayer();
            Block b = e.getBlock();
            Location loc = b.getLocation();
            int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
            World w = loc.getWorld();

            if(b.getType().equals(Material.CAULDRON)) {
                p.sendMessage("yes 1");
                for(ICauldron cal : CauldronTP.cauls) {
                    Location caul = cal.getCauldron();
                    Location tp = cal.getTeleportTo();
                    p.sendMessage(caul.toString());
                    if((caul.getBlockX() == x && caul.getBlockY() == y && caul.getBlockZ() == z && caul.getWorld().equals(w))
                            || (tp.getBlockX() == x && tp.getBlockY() == y && tp.getBlockZ() == z && tp.getWorld().equals(w))) {
                        p.sendMessage("yes 2");
                        CauldronTP.cauls.remove(cal);
                        CauldronTP.removeFromCfg(cal);
                        p.sendMessage(CauldronTP.getStringCfg("messages.broke"));
                    }
                }
            }
        }

    Maybe someone knows how to fix it?
     
  2. Yes.
    Code (Text):
    Iterator<ICauldrom> iter = CauldronTP.cauls.iterator();
    while(iter.hasNext()) {
        final ICauldron caul = iter.next();

        // ...

        iter.remove();
    }
     
    • Like Like x 1
  3. SteelPhoenix

    Moderator

    You are modifying your collection while iterating over it - which causes this exception. Use an iterator like mentioned above.

    Also, what's with the static abuse and public field access?
     
Thread Status:
Not open for further replies.