From ae5a874349a9d986d3b30b395ca025ecf90769bf Mon Sep 17 00:00:00 2001
From: Thinkofdeath <thethinkofdeath@gmail.com>
Date: Tue, 14 Jan 2014 20:11:25 +0000
Subject: [PATCH] Fix ConcurrentModificationException while being idle kicked
 in a vehicle


diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 61fa519..40325bf 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -1043,23 +1043,24 @@ public abstract class World implements IBlockAccess {
             this.players.remove(entity);
             this.everyoneSleeping();
         }
-
-        int i = entity.ah;
-        int j = entity.aj;
-
-        if (entity.ag && this.isChunkLoaded(i, j)) {
-            this.getChunkAt(i, j).b(entity);
-        }
-
-        // CraftBukkit start - Decrement loop variable field if we've already ticked this entity
-        int index = this.entityList.indexOf(entity);
-        if (index != -1) {
-            if (index <= this.tickPosition) {
-                this.tickPosition--;
+        // Spigot start
+        if (!guardEntityList) { // It will get removed after the tick if we are ticking
+            int i = entity.ah;
+            int j = entity.aj;
+            if (entity.ag && this.isChunkLoaded(i, j)) {
+                this.getChunkAt(i, j).b(entity);
             }
-            this.entityList.remove(index);
+            // CraftBukkit start - Decrement loop variable field if we've already ticked this entity
+            int index = this.entityList.indexOf(entity);
+            if (index != -1) {
+                if (index <= this.tickPosition) {
+                    this.tickPosition--;
+                }
+                this.entityList.remove(index);
+            }
+            // CraftBukkit end
         }
-        // CraftBukkit end
+        // Spigot end
 
         this.b(entity);
     }
-- 
1.8.3.2