Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Optimize performance and default use fast algorithm
Browse files Browse the repository at this point in the history
Former-commit-id: 0360082
  • Loading branch information
Ghost-chu committed Feb 6, 2020
1 parent 8a3ec6e commit 9f5442c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/maxgamer/quickshop/QuickShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,11 @@ private void updateConfig(int selectedVersion) {
getConfig().set("config-version", 80);
selectedVersion = 80;
}
if(selectedVersion == 80){
getConfig().set("shop.use-fast-shop-search-algorithm",true);
getConfig().set("config-version", 81);
selectedVersion = 81;
}
saveConfig();
reloadConfig();
File file = new File(getDataFolder(), "example.config.yml");
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ public void createShop(@NotNull Shop shop, @NotNull Info info) {
}

if (this.useFastShopSearchAlgorithm) {
return getShopIncludeAttached_Fast(loc);
return getShopIncludeAttached_Fast(loc,false);
} else {
return getShopIncludeAttached_Classic(loc);
}
Expand Down Expand Up @@ -1048,15 +1048,22 @@ public void createShop(@NotNull Shop shop, @NotNull Info info) {
return null;
}

private @Nullable Shop getShopIncludeAttached_Fast(@NotNull Location loc) {
private @Nullable Shop getShopIncludeAttached_Fast(@NotNull Location loc, boolean fromAttach) {
@Nullable Shop shop;
shop = getShop(loc);
if (shop != null) {
return shop;
}
@Nullable Block attachedBlock = Util.getSecondHalf(loc.getBlock());
if (attachedBlock != null) {
return getShop(attachedBlock.getLocation());
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) {
return getShop(half.getLocation());
} else {
return null;
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/maxgamer/quickshop/Util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.bukkit.block.Container;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.EnderChest;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -471,8 +472,9 @@ public static String format(double n) {
*/
@Nullable
public static Block getAttached(@NotNull Block b) {
if (b.getBlockData() instanceof Directional) {
Directional directional = (Directional) b.getBlockData();
BlockData blockData = b.getBlockData();
if (blockData instanceof Directional) {
Directional directional = (Directional) blockData;
return b.getRelative(directional.getFacing().getOppositeFace());
} else {
return null;
Expand Down Expand Up @@ -600,10 +602,11 @@ public static Entry<Double, Double> getPriceRestriction(@NotNull Material materi
*/
@Nullable
public static Block getSecondHalf(@NotNull Block b) {
if(!(b.getState() instanceof Chest)){
BlockState state = b.getState();
if(!(state instanceof Chest)){
return null;
}
Chest oneSideOfChest = (Chest) b.getState();
Chest oneSideOfChest = (Chest)state;
InventoryHolder chestHolder = oneSideOfChest.getInventory().getHolder();
if (chestHolder instanceof DoubleChest) {
DoubleChest doubleChest = (DoubleChest) chestHolder;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#This is example config, don't direct modify this file, all changes will revert when you reload the plugin.

#Do not touch if you not clear know about this
config-version: 81
config-version: 82

#Select the language you want to use, (e.g de), use only supported language codes from the list below.
#If you use a not exist/not support language, plugin will move to use en_US to keep everything working.
Expand Down Expand Up @@ -274,7 +274,7 @@ shop:
allow-free-shop: false

#Use fast algorithm for ShopManager#getShopIncludeAttached, it should improve HUGE performance on it. (BETA)
use-fast-shop-search-algorithm: false
use-fast-shop-search-algorithm: true

#The shop ongoing fee, if a shop's owner had no enough money, shop will auto-remove.
ongoing-fee:
Expand Down

0 comments on commit 9f5442c

Please sign in to comment.