diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 0cf909a4c..2593af552 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1181,6 +1181,7 @@ public class QuickShop extends JavaPlugin { getConfig().set("database.auto-fix-encoding-issue-in-database", false); getConfig().set("send-shop-protection-alert", false); getConfig().set("send-display-item-protection-alert", false); + getConfig().set("shop.use-fast-shop-search-algorithm",false); getConfig().set("config-version", 77); } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index fb58b2ab9..c815981f8 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -61,8 +61,11 @@ public class ShopManager { private Set loadedShops = new CopyOnWriteArraySet<>(); + private boolean useFastShopSearchAlgorithm = false; + public ShopManager(@NotNull QuickShop plugin) { this.plugin = plugin; + this.useFastShopSearchAlgorithm = plugin.getConfig().getBoolean("shop.use-fast-shop-search-algorithm",false); } @SuppressWarnings("deprecation") @@ -782,6 +785,18 @@ public class ShopManager { Util.debugLog("Location is null."); return null; } + + if(this.useFastShopSearchAlgorithm){ + return getShopIncludeAttached_Fast(loc); + }else{ + return getShopIncludeAttached_Classic(loc); + } + } + public @Nullable Shop getShopIncludeAttached_Classic(@Nullable Location loc) { + if (loc == null) { + Util.debugLog("Location is null."); + return null; + } Util.debugLog("Start searching the shops..."); @Nullable Shop shop; //Get location's chunk all shops @@ -833,6 +848,24 @@ public class ShopManager { return null; } + private @Nullable Shop getShopIncludeAttached_Fast(@Nullable Location loc){ + if (loc == null) { + Util.debugLog("Location is null."); + return null; + } + Util.debugLog("Use fast shop search algorithm to searching the shops..."); + @Nullable Shop shop; + shop = getShop(loc); + if(shop != null){ + return shop; + } + @Nullable Block attachedBlock = Util.getAttached(loc.getBlock()); + if(attachedBlock != null){ + return getShop(attachedBlock.getLocation()); + }else{ + return null; + } + } /** * Returns a hashmap of Chunk - Shop diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f261b6e15..8cb9d60ff 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -277,6 +277,9 @@ shop: #THIS MAY BROKEN SOMETHING allow-free-shop: false + #Use fast algorithm for ShopManager#getShopIncludeAttached, it should improve HUGE performance on it. (BETA) + use-fast-shop-search-algorithm: false + #The shop ongoing fee, if a shop's owner had no enough money, shop will auto-remove. ongoing-fee: enable: false