From 0ab51482d2c6b161ad1102793b63bb437ef220f9 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 1 Jan 2021 19:00:32 +0100 Subject: [PATCH] No world access on plugin disable --- src/main/java/de/epiceric/shopchest/ShopChest.java | 8 +++----- .../de/epiceric/shopchest/utils/ShopUtils.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java index c269e57..cdaf9e8 100644 --- a/src/main/java/de/epiceric/shopchest/ShopChest.java +++ b/src/main/java/de/epiceric/shopchest/ShopChest.java @@ -255,11 +255,9 @@ public class ShopChest extends JavaPlugin { if (shopCreationThreadPool != null) { shopCreationThreadPool.shutdown(); } - - for (Shop shop : shopUtils.getShops()) { - shopUtils.removeShop(shop, false); - debug("Removed shop (#" + shop.getID() + ")"); - } + + shopUtils.removeShops(); + debug("Removed shops"); if (database != null && database.isInitialized()) { if (database instanceof SQLite) { diff --git a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java index 46937e0..88960ee 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java @@ -132,6 +132,20 @@ public class ShopUtils { addShop(shop, addToDatabase, null); } + /** + * Removes (i.e. unloads) all currently loaded shops + */ + public void removeShops() { + shopLocation.forEach((location, shop) -> { + if (!shop.isCreated()) return; + + plugin.debug("Removing shop " + shop.getID()); + shop.removeItem(); + shop.removeHologram(); + }); + shopLocation.clear(); + } + /** Remove a shop. May not work properly if double chest doesn't exist! * @param shop Shop to remove * @param removeFromDatabase Whether the shop should also be removed from the database