Work around chunk unload change

This commit is contained in:
fullwall 2019-04-28 20:45:38 +08:00
parent b7d43bf13b
commit ca8d9c41ea
2 changed files with 12 additions and 3 deletions

View File

@ -146,7 +146,7 @@ public class EventListen implements Listener {
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) { public void onChunkUnload(final ChunkUnloadEvent event) {
ChunkCoord coord = toCoord(event.getChunk()); ChunkCoord coord = toCoord(event.getChunk());
Location loc = new Location(null, 0, 0, 0); Location loc = new Location(null, 0, 0, 0);
for (NPC npc : getAllNPCs()) { for (NPC npc : getAllNPCs()) {
@ -160,7 +160,17 @@ public class EventListen implements Listener {
try { try {
((Cancellable) event).setCancelled(true); ((Cancellable) event).setCancelled(true);
} catch (Throwable e) { } catch (Throwable e) {
// TODO: event.getChunk().setForceLoaded(true); // TODO: event.getChunk().setForceLoaded(true); ?
toRespawn.put(coord, npc);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (!event.getChunk().isLoaded()) {
event.getChunk().load();
}
}
}, 10);
return;
} }
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]"); Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]");

View File

@ -187,7 +187,6 @@ public class SkinPacketTracker {
if (location.distanceSquared(CACHE_LOCATION) > radius) if (location.distanceSquared(CACHE_LOCATION) > radius)
continue; continue;
updateViewer(player); updateViewer(player);
} }
} }