Allow user switch to new fast-shop-search-algorithm to improve a lot performance(BETA).

Former-commit-id: 1acba410d9d9ac195e32b964050559e6f10437b5
This commit is contained in:
Ghost_chu committed 2020-01-16 18:06:00 +08:00
1 parent 2d0a62bb75
commit 4430dab7f4
3 files changed
+37

No files matched your search

@@ -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);
}
@@ -61,8 +61,11 @@ public class ShopManager {
private Set<Shop> 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
+3
View File
@@ -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