diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index 73aba9430..54f63b50f 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -20,10 +20,6 @@ package org.maxgamer.quickshop.Shop; import com.google.common.collect.Sets; -import java.text.DecimalFormat; -import java.util.*; -import java.util.logging.Level; -import java.util.stream.Collectors; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -45,6 +41,11 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Util.MsgUtil; import org.maxgamer.quickshop.Util.Util; +import java.text.DecimalFormat; +import java.util.*; +import java.util.logging.Level; +import java.util.stream.Collectors; + /** * Manage a lot of shops. */ @@ -1013,27 +1014,29 @@ public class ShopManager { } private @Nullable Shop getShopIncludeAttached_Fast(@NotNull Location loc, boolean fromAttach) { - @Nullable Shop shop; + Shop shop; + //Try to get it directly shop = getShop(loc); - if (shop != null) { - plugin.getShopCache().setCache(loc, shop); - return shop; - } - Block currentBlock = loc.getBlock(); - if (!fromAttach && Util.isWallSign(currentBlock.getType())) { - Block attached = Util.getAttached(currentBlock); - if (attached != null) { - this.getShopIncludeAttached_Fast(attached.getLocation(), true); + + //failed, get attached shop + if (shop == null) { + Block currentBlock = loc.getBlock(); + if (!fromAttach && Util.isWallSign(currentBlock.getType())) { + Block attached = Util.getAttached(currentBlock); + if (attached != null) { + this.getShopIncludeAttached_Fast(attached.getLocation(), true); + } + } + @Nullable Block half = Util.getSecondHalf(currentBlock); + if (half != null) { + shop = getShop(half.getLocation()); } } - @Nullable Block half = Util.getSecondHalf(currentBlock); - if (half != null) { - plugin.getShopCache().setCache(loc, getShop(half.getLocation())); - return getShop(half.getLocation()); - } else { - plugin.getShopCache().setCache(loc, null); - return null; + if(plugin.getShopCache()!=null) { + plugin.getShopCache().setCache(loc, shop); } + + return shop; } public class ShopIterator implements Iterator {