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(); shopCreationThreadPool.shutdown();
} }
for (Shop shop : shopUtils.getShopsCopy()) { for (Shop shop : shopUtils.getShops()) {
shopUtils.removeShop(shop, false); shopUtils.removeShop(shop, false);
debug("Removed shop (#" + shop.getID() + ")"); debug("Removed shop (#" + shop.getID() + ")");
} }

View File

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

View File

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

View File

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

View File

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