From 26025ef64a99efd4455b94a572cf8b5cbd0a2362 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 21 Feb 2020 13:11:35 +0100 Subject: [PATCH] Only add shop if chunk is still loaded --- .../de/epiceric/shopchest/utils/ShopUtils.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java index e72ce4d..3ee7b35 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java @@ -309,15 +309,23 @@ public class ShopUtils { plugin.getShopDatabase().getShopsInChunks(chunks, new Callback>(plugin) { @Override public void onResult(Collection result) { + Collection loadedShops = new HashSet<>(); + for (Shop shop : result) { - if (shop.create(true)) { + Location loc = shop.getLocation(); + int x = loc.getBlockX() / 16; + int z = loc.getBlockZ() / 16; + + // Only add shop if chunk is still loaded + if (loc.getWorld().isChunkLoaded(x, z) && shop.create(true)) { addShop(shop, false); + loadedShops.add(shop); } } - if (callback != null) callback.onResult(result.size()); + if (callback != null) callback.onResult(loadedShops.size()); - Bukkit.getPluginManager().callEvent(new ShopsLoadedEvent(result)); + Bukkit.getPluginManager().callEvent(new ShopsLoadedEvent(Collections.unmodifiableCollection(loadedShops))); } @Override