Make ShopUtils#getShops() return a new copy

ShopUtils#getShopsCopy() is now deprecated
This commit is contained in:
Eric 2020-03-25 14:50:21 +01:00
parent 443cab6df5
commit 30a2b8aefc
5 changed files with 12 additions and 12 deletions

View File

@ -249,7 +249,7 @@ public class ShopChest extends JavaPlugin {
shopCreationThreadPool.shutdown();
}
for (Shop shop : shopUtils.getShopsCopy()) {
for (Shop shop : shopUtils.getShops()) {
shopUtils.removeShop(shop, false);
debug("Removed shop (#" + shop.getID() + ")");
}

View File

@ -202,9 +202,8 @@ class ShopCommandExecutor implements CommandExecutor {
plugin.getUpdater().restart();
// Remove all shops
Iterator<Shop> iter = shopUtils.getShops().iterator();
while (iter.hasNext()) {
shopUtils.removeShop(iter.next(), false);
for (Shop shop : shopUtils.getShops()) {
shopUtils.removeShop(shop, false);
}
Chunk[] loadedChunks = Bukkit.getWorlds().stream().map(World::getLoadedChunks)

View File

@ -53,7 +53,7 @@ public class AreaShopListener implements Listener {
private void removeShopsInRegion(GeneralRegion generalRegion) {
if (!plugin.hasWorldGuard()) return;
for (Shop shop : plugin.getShopUtils().getShopsCopy()) {
for (Shop shop : plugin.getShopUtils().getShops()) {
if (!shop.getLocation().getWorld().getName().equals(generalRegion.getWorldName())) continue;
for (IWrappedRegion r : WorldGuardWrapper.getInstance().getRegions(shop.getLocation())) {

View File

@ -70,7 +70,7 @@ public class BentoBoxListener implements Listener {
if (!Config.enableBentoBoxIntegration)
return;
Collection<Shop> shops = plugin.getShopUtils().getShopsCopy();
Collection<Shop> shops = plugin.getShopUtils().getShops();
for (Shop shop : shops) {
if (!shop.getLocation().getWorld().getName().equals(world.getName())) {
continue;

View File

@ -65,23 +65,24 @@ public class ShopUtils {
}
/**
* Get all shops
* Do not use for removing while iteration!
* Get a collection of all loaded shops
* <p>
* This collection is safe to use for looping over and removing shops.
*
* @see #getShopsCopy()
* @return Read-only collection of all shops, may contain duplicates
* @return Read-only collection of all shops, may contain duplicates for double chests
*/
public Collection<Shop> getShops() {
return shopLocationValues;
return Collections.unmodifiableCollection(new ArrayList<>(shopLocationValues));
}
/**
* Get all shops
* Same as {@link #getShops()} but this is safe to remove while iterating
*
* @see #getShops()
* @return Copy of collection of all shops, may contain duplicates
* @deprecated Use {@link #getShops()} instead
*/
@Deprecated
public Collection<Shop> getShopsCopy() {
return new ArrayList<>(getShops());
}