From 845090e5704a14e662de109451d62f814c439c2f 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. --- Spigot-Server-Patches/0004-MC-Utils.patch | 10 +++++++--- ...140-Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Spigot-Server-Patches/0004-MC-Utils.patch b/Spigot-Server-Patches/0004-MC-Utils.patch index 7f9a24a5d..0cb32dc35 100644 --- a/Spigot-Server-Patches/0004-MC-Utils.patch +++ b/Spigot-Server-Patches/0004-MC-Utils.patch @@ -1,4 +1,4 @@ -From c3b8ab1a653c005db884e9393ddcf82f0e71a73e Mon Sep 17 00:00:00 2001 +From a3092ca4d2f76ef79198b6011d380dadd4d5d601 Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 28 Mar 2016 20:55:47 -0400 Subject: [PATCH] MC Utils @@ -7,10 +7,10 @@ Collection of utils to help reduce NMS diff diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java new file mode 100644 -index 0000000..349f2fc +index 0000000..ffd3152 --- /dev/null +++ b/src/main/java/net/minecraft/server/MCUtil.java -@@ -0,0 +1,115 @@ +@@ -0,0 +1,119 @@ +package net.minecraft.server; + +import org.bukkit.Location; @@ -120,6 +120,10 @@ index 0000000..349f2fc + 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; diff --git a/Spigot-Server-Patches/0140-Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch b/Spigot-Server-Patches/0140-Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch index 82ae922c2..5ca4d6ed8 100644 --- a/Spigot-Server-Patches/0140-Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch +++ b/Spigot-Server-Patches/0140-Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch @@ -1,4 +1,4 @@ -From 8ff5e997fd6df8487be017803e257e0b664e4886 Mon Sep 17 00:00:00 2001 +From e4e4bb6ea35b2bf711d57c1f9f694c366a6fa105 Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 14 Apr 2016 21:01:39 -0400 Subject: [PATCH] Fix Bugs with Spigot Mob Spawn Logic @@ -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 9334a0a..5c1685d 100644 +--- a/src/main/java/net/minecraft/server/Chunk.java ++++ b/src/main/java/net/minecraft/server/Chunk.java +@@ -704,7 +704,7 @@ 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 15a0ce9..b47feb2 100644 --- a/src/main/java/net/minecraft/server/SpawnerCreature.java