mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 02:12:25 +00:00
Only add shop if chunk is still loaded
This commit is contained in:
parent
8717a282c2
commit
26025ef64a
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user