Fix NPE and improve logic

Former-commit-id: 28ef4c190d735136dbd54136640909805f62e43c
This commit is contained in:
sandtechnology committed 2020-03-31 12:22:09 +08:00
1 parent 036442d5a9
commit 010e9747af
1 file changed
+24 -21
@@ -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<Shop> {