Handle removing entity while ticking. Fixes BUKKIT-1331 and BUKKIT-5405
Manual merge of 71f5cbd and dce2b35