From aaa45ea72ee0d00ccf0d512567b61193390b4e9e Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 10 Jul 2020 15:13:53 +0800 Subject: [PATCH] Paper seems to prefer despawning immediately --- .../java/net/citizensnpcs/EventListen.java | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index 2a0ee13e5..52bdc4e80 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -172,43 +172,41 @@ public class EventListen implements Listener { } 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; + } + ((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(); } } - if (loadChunk) { - Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { - @Override - public void run() { - if (!event.getChunk().isLoaded()) { - event.getChunk().load(); - } - } - }, 10); - } - } - }); + }, 10); + } } @EventHandler(priority = EventPriority.MONITOR)