From 75eb8243f727870fd04881cb8c99329f420b94a6 Mon Sep 17 00:00:00 2001 From: Aikar Date: Fri, 15 Apr 2016 21:31:12 -0400 Subject: [PATCH] Ensure we actually removed entity from chunk before decrementing counts If a plugin hacks into NMS and triggers entity removal, it could result in an entity being attempted to remove from the chunk twice. The 2nd pass will return false, as it did not find the entity in the list. We should not touch entity counts if the entity was not removed, to avoid going negative. --- .../Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch | 13 +++++++++++++ Spigot-Server-Patches/MC-Utils.patch | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch b/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch index 68099732fd..d1cac0b518 100644 --- a/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch +++ b/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch @@ -13,6 +13,19 @@ Specially with servers using smaller mob spawn ranges than view distance, as wel This patch returns mob counting to use all loaded chunks, and 17x17 division. +diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/Chunk.java ++++ b/src/main/java/net/minecraft/server/Chunk.java +@@ -0,0 +0,0 @@ public class Chunk { + i = this.entitySlices.length - 1; + } + +- this.entitySlices[i].remove(entity); ++ if (!this.entitySlices[i].remove(entity)) { return; } // Paper + // Paper start - update counts + if (entity instanceof EntityItem) { + itemCounts[i]--; diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/SpawnerCreature.java diff --git a/Spigot-Server-Patches/MC-Utils.patch b/Spigot-Server-Patches/MC-Utils.patch index 6d0356e034..491f6270cf 100644 --- a/Spigot-Server-Patches/MC-Utils.patch +++ b/Spigot-Server-Patches/MC-Utils.patch @@ -120,6 +120,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return new Location(entity.getWorld().getWorld(), entity.locX, entity.locY, entity.locZ); + } + ++ public static BlockPosition toBlockPosition(Location loc) { ++ return new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); ++ } ++ + public static boolean isEdgeOfChunk(BlockPosition pos) { + final int modX = pos.getX() & 15; + final int modZ = pos.getZ() & 15;