mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-30 01:43:22 +01: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