From d890391c19a047f2ed8dd5c5561082512d6c077d Mon Sep 17 00:00:00 2001 From: sandtechnology <20417547+sandtechnology@users.noreply.github.com> Date: Wed, 1 Apr 2020 21:03:30 +0800 Subject: [PATCH] Implement search attached shop logic(non-cache) Former-commit-id: b36037d72bb19dc9cd9fbc48d2aea19b4965b8a4 --- .../Listeners/ProtectionListenerBase.java | 4 ++-- .../maxgamer/quickshop/Shop/ShopManager.java | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/ProtectionListenerBase.java b/src/main/java/org/maxgamer/quickshop/Listeners/ProtectionListenerBase.java index f42a602e8..d9e53f4e3 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/ProtectionListenerBase.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/ProtectionListenerBase.java @@ -46,7 +46,7 @@ public class ProtectionListenerBase { */ @Nullable public Shop getShopPlayer(@NotNull Location location, boolean includeAttached) { - return plugin.getShopManager().getShop(location); + return includeAttached ? plugin.getShopManager().getShopIncludeAttached(location,false):plugin.getShopManager().getShop(location); } /** @@ -58,7 +58,7 @@ public class ProtectionListenerBase { */ @Nullable public Shop getShopNature(@NotNull Location location, boolean includeAttached) { - return plugin.getShopManager().getShop(location); + return includeAttached ? plugin.getShopManager().getShopIncludeAttached(location,false):plugin.getShopManager().getShop(location); } } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index 7f9f8de78..487b50ec6 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -318,13 +318,24 @@ public class ShopManager { * @return The shop at that location */ public @Nullable Shop getShopIncludeAttached(@Nullable Location loc) { + return getShopIncludeAttached(loc,true); + } + + /** + * Gets a shop in a specific location Include the attached shop, e.g DoubleChest shop. + * + * @param loc The location to get the shop from + * @param useCache whether to use cache + * @return The shop at that location + */ + public @Nullable Shop getShopIncludeAttached(@Nullable Location loc,boolean useCache) { if (loc == null) { Util.debugLog("Location is null."); return null; } if (this.useFastShopSearchAlgorithm) { - return getShopIncludeAttached_Fast(loc, false); + return getShopIncludeAttached_Fast(loc, false,useCache); } else { return getShopIncludeAttached_Classic(loc); } @@ -1014,6 +1025,10 @@ public class ShopManager { } private @Nullable Shop getShopIncludeAttached_Fast(@NotNull Location loc, boolean fromAttach) { + return getShopIncludeAttached_Fast(loc,fromAttach,true); + } + + private @Nullable Shop getShopIncludeAttached_Fast(@NotNull Location loc, boolean fromAttach,boolean useCache) { Shop shop; //Try to get it directly shop = getShop(loc); @@ -1038,7 +1053,7 @@ public class ShopManager { } } //add cache if using - if(plugin.getShopCache()!=null) { + if(plugin.getShopCache()!=null&&useCache) { plugin.getShopCache().setCache(loc, shop); }