spigot/CraftBukkit-Patches/0065-Guard-Entity-List.patch
2018-07-15 10:00:00 +10:00

79 lines
3 KiB
Diff

From 6e42d463a1530690bd442a3fba5e19485900f5e2 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Mon, 10 Mar 2014 09:03:28 +1100
Subject: [PATCH] Guard Entity List
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 6207a4cd..33f606a9 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -38,7 +38,32 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
protected static final Logger e = LogManager.getLogger();
private static final EnumDirection[] a = EnumDirection.values();
private int b = 63;
- public final List<Entity> entityList = Lists.newArrayList();
+ // Spigot start - guard entity list from removals
+ public final List<Entity> entityList = new java.util.ArrayList<Entity>()
+ {
+ @Override
+ public Entity remove(int index)
+ {
+ guard();
+ return super.remove( index );
+ }
+
+ @Override
+ public boolean remove(Object o)
+ {
+ guard();
+ return super.remove( o );
+ }
+
+ private void guard()
+ {
+ if ( guardEntityList )
+ {
+ throw new java.util.ConcurrentModificationException();
+ }
+ }
+ };
+ // Spigot end
protected final List<Entity> g = Lists.newArrayList();
public final List<TileEntity> tileEntityList = Lists.newArrayList();
public final List<TileEntity> tileEntityListTick = Lists.newArrayList();
@@ -103,6 +128,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
public final SpigotTimings.WorldTimingsHandler timings; // Spigot
+ private boolean guardEntityList; // Spigot
public CraftWorld getWorld() {
return this.world;
@@ -1067,6 +1093,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
org.spigotmc.ActivationRange.activateEntities(this); // Spigot
timings.entityTick.startTiming(); // Spigot
+ guardEntityList = true; // Spigot
// CraftBukkit start - Use field for loop variable
for (this.tickPosition = 0; this.tickPosition < this.entityList.size(); ++this.tickPosition) {
entity = (Entity) this.entityList.get(this.tickPosition);
@@ -1105,12 +1132,15 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
this.getChunkAt(j, l).b(entity);
}
+ guardEntityList = false; // Spigot
this.entityList.remove(this.tickPosition--); // CraftBukkit - Use field for loop variable
+ guardEntityList = true; // Spigot
this.c(entity);
}
this.methodProfiler.e();
}
+ guardEntityList = false; // Spigot
timings.entityTick.stopTiming(); // Spigot
this.methodProfiler.c("blockEntities");
--
2.17.1