NerdNu/MobLimiter — pull request #9 by totemo (2014-04-25 08:16:48+00:00)
Title: Fix despawning of mobs on chunk unload.

To whoever gets to review this (probably slide23): this is actually quite an important one and may significantly improve the tps on P. In essence: after the special mobs change to protect pets and Doppelgangers, MobLimiter was not and did not. :)

In addition to what I said in the commit message (I couldn't get git commit --amend to fix it after I had pushed), I should add that in onCreatureSpawnEvent() I replaced the cancellation of the spawn event with Entity.remove(), since we're already using that method on chunk unload. It should not *compound* the problem of https://github.com/NerdNu/NerdBugs/issues/180, but I am not sure if it is sufficient or whether MobLimiter needs to be dependent on BKCommonLib, which uses NMS methods. In any case, this code is called in relatively rare circumstances, particularly in comparison to WorldGuard which does cancel the spawn event anyway.

From the commit message:

* Mobs were being treated as "special" because unarmored mobs spawn with an
item (1xAIR) in their armor array. The armor test in isSpecialMob() has been
amended to ignore AIR.

* In onCreatureSpawnEvent(), the sheep cap was incorrectly looked up under the
key "sheep", rather than e.g. "sheepwhite". Access to the cap values is now
through methods in all cases.

* An additional debug trace has been added in the case where a mob is exempted
from removal when the chunk unloads because it is a "special" mob. This debug
message is off by default, as with the others.

* Duplicated code to format the entity "type" and location (e.g.
"sheepblue at (world,0,70,0)") has been encapsulated in a method.

* I've seen a mixture of tabs and spaces in NerdNu code. I've come to the
conclusion that using only spaces leads to properly formatted diffs on github
and is therefore preferable (except in the case of CH code where a consistent
tab-based style is already in effect). Apologies for the pain in reading this
one diff.