Skip to content

Commit

Permalink
Paper seems to prefer despawning immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 10, 2020
1 parent 0586f2a commit aaa45ea
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions main/src/main/java/net/citizensnpcs/EventListen.java
Expand Up @@ -172,43 +172,41 @@ public void onChunkUnload(final ChunkUnloadEvent event) {
}
if (toDespawn.isEmpty())
return;
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
ChunkCoord coord = new ChunkCoord(event.getChunk());
boolean loadChunk = false;
for (NPC npc : toDespawn) {
if (!npc.despawn(DespawnReason.CHUNK_UNLOAD)) {
if (!(event instanceof Cancellable)) {
loadChunk = true;
toRespawn.put(coord, npc);
continue;
}
((Cancellable) event).setCancelled(true);
if (Messaging.isDebugging()) {
Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]");
}
respawnAllFromCoord(coord, event);
return;
}
toRespawn.put(coord, npc);
ChunkCoord coord = new ChunkCoord(event.getChunk());
boolean loadChunk = false;
for (NPC npc : toDespawn) {
if (!npc.despawn(DespawnReason.CHUNK_UNLOAD)) {
if (!(event instanceof Cancellable)) {
if (Messaging.isDebugging()) {
Messaging.debug("Despawned id", npc.getId(),
"due to chunk unload at [" + coord.x + "," + coord.z + "]");
Messaging.debug("Reloading chunk because", npc.getId(), "couldn't despawn");
}
loadChunk = true;
toRespawn.put(coord, npc);
continue;
}
if (loadChunk) {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (!event.getChunk().isLoaded()) {
event.getChunk().load();
}
}
}, 10);
((Cancellable) event).setCancelled(true);
if (Messaging.isDebugging()) {
Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]");
}
respawnAllFromCoord(coord, event);
return;
}
});
toRespawn.put(coord, npc);
if (Messaging.isDebugging()) {
Messaging.debug("Despawned id", npc.getId(),
"due to chunk unload at [" + coord.x + "," + coord.z + "]");
}
}
if (loadChunk) {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (!event.getChunk().isLoaded()) {
event.getChunk().load();
}
}
}, 10);
}
}

@EventHandler(priority = EventPriority.MONITOR)
Expand Down

0 comments on commit aaa45ea

Please sign in to comment.