Only add shop if chunk is still loaded

This commit is contained in:
Eric 2020-02-21 13:11:35 +01:00
parent 8717a282c2
commit 26025ef64a
1 changed files with 11 additions and 3 deletions

View File

@ -309,15 +309,23 @@ public class ShopUtils {
plugin.getShopDatabase().getShopsInChunks(chunks, new Callback<Collection<Shop>>(plugin) { plugin.getShopDatabase().getShopsInChunks(chunks, new Callback<Collection<Shop>>(plugin) {
@Override @Override
public void onResult(Collection<Shop> result) { public void onResult(Collection<Shop> result) {
Collection<Shop> loadedShops = new HashSet<>();
for (Shop shop : result) { 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); 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 @Override