Remove entity if world failed to add

This commit is contained in:
fullwall 2022-06-11 12:41:24 +08:00
parent d98833ca66
commit aaf870372c
1 changed files with 4 additions and 2 deletions

View File

@ -299,10 +299,12 @@ public class CitizensNPC extends AbstractNPC {
@Override
public void run() {
if (timer++ > 10) {
cancel();
Messaging.debug("Couldn't spawn", CitizensNPC.this, "entity not added to world");
entityController.remove();
cancel();
return;
}
if (getEntity() == null || !getEntity().isValid())
return;
@ -314,9 +316,9 @@ public class CitizensNPC extends AbstractNPC {
Bukkit.getPluginManager().callEvent(spawnEvent);
if (spawnEvent.isCancelled()) {
entityController.remove();
Messaging.debug("Couldn't spawn", CitizensNPC.this, "SpawnReason." + reason,
"due to event cancellation.");
entityController.remove();
cancel();
return;
}