Skip to content

Commit

Permalink
Changes to world unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 14, 2013
1 parent 14144dd commit fc53c6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/main/java/net/citizensnpcs/EventListen.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,15 @@ public void onWorldUnload(WorldUnloadEvent event) {
for (NPC npc : getAllNPCs()) {
if (!npc.isSpawned() || !npc.getBukkitEntity().getWorld().equals(event.getWorld()))
continue;
storeForRespawn(npc);
npc.despawn(DespawnReason.WORLD_UNLOAD);
if (event.isCancelled())
boolean despawned = npc.despawn(DespawnReason.WORLD_UNLOAD);
if (event.isCancelled() || !despawned) {
for (ChunkCoord coord : toRespawn.keySet()) {
if (event.getWorld().getName().equals(coord.worldName))
respawnAllFromCoord(coord);
}
return;
}
storeForRespawn(npc);
Messaging.debug("Despawned", npc.getId() + "due to world unload at", event.getWorld().getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void stop() {

@Override
public boolean update() {
if (target == null || target.dead) {
if (target == null || !target.getBukkitEntity().isValid()) {
cancelReason = CancelReason.TARGET_DIED;
return true;
}
Expand Down

0 comments on commit fc53c6e

Please sign in to comment.