Changes to world unloading

This commit is contained in:
fullwall 2013-04-14 18:23:21 +08:00
parent 1a80036bd5
commit cfefa87081
2 changed files with 9 additions and 4 deletions

View File

@ -252,10 +252,15 @@ public class EventListen implements Listener {
for (NPC npc : getAllNPCs()) { for (NPC npc : getAllNPCs()) {
if (!npc.isSpawned() || !npc.getBukkitEntity().getWorld().equals(event.getWorld())) if (!npc.isSpawned() || !npc.getBukkitEntity().getWorld().equals(event.getWorld()))
continue; continue;
storeForRespawn(npc); boolean despawned = npc.despawn(DespawnReason.WORLD_UNLOAD);
npc.despawn(DespawnReason.WORLD_UNLOAD); if (event.isCancelled() || !despawned) {
if (event.isCancelled()) for (ChunkCoord coord : toRespawn.keySet()) {
if (event.getWorld().getName().equals(coord.worldName))
respawnAllFromCoord(coord);
}
return; return;
}
storeForRespawn(npc);
Messaging.debug("Despawned", npc.getId() + "due to world unload at", event.getWorld().getName()); Messaging.debug("Despawned", npc.getId() + "due to world unload at", event.getWorld().getName());
} }
} }

View File

@ -96,7 +96,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
@Override @Override
public boolean update() { public boolean update() {
if (target == null || target.dead) { if (target == null || !target.getBukkitEntity().isValid()) {
cancelReason = CancelReason.TARGET_DIED; cancelReason = CancelReason.TARGET_DIED;
return true; return true;
} }