diff --git a/src/main/java/org/maxgamer/quickshop/Command/QS.java b/src/main/java/org/maxgamer/quickshop/Command/QS.java index c750ba8..a206bf5 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/QS.java +++ b/src/main/java/org/maxgamer/quickshop/Command/QS.java @@ -396,12 +396,17 @@ public class QS implements CommandExecutor { int i = 0; while (shIt.hasNext()) { Shop shop = shIt.next(); - if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) { - ContainerShop cs = (ContainerShop) shop; - if (cs.isDoubleShop()) - continue; - shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely. - i++; + + try { + if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) { + ContainerShop cs = (ContainerShop) shop; + if (cs.isDoubleShop()) + continue; + shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely. + i++; + } + } catch (IllegalStateException e) { + shIt.remove(); // The shop is not there anymore, remove it } } MsgUtil.clean(); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 0a6baa3..1138912 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -216,9 +216,14 @@ public class ContainerShop implements Shop { /** * @return The chest this shop is based on. */ - public Inventory getInventory() { - InventoryHolder container = (InventoryHolder) this.loc.getBlock().getState(); - return container.getInventory(); + public Inventory getInventory() throws IllegalStateException { + InventoryHolder container; + try { + container = (InventoryHolder) this.loc.getBlock().getState(); + return container.getInventory(); + } catch (Exception e) { + throw new IllegalStateException("Inventory doesn't exist anymore"); + } } /**