From 446ef149377c677411faefa129313873794263ce Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Tue, 22 Dec 2020 22:19:56 +0800 Subject: [PATCH] Bug fixed --- .../command/subcommand/SubCommand_Find.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Find.java b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Find.java index d6d0a500c..9a5339c49 100644 --- a/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Find.java +++ b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Find.java @@ -93,12 +93,14 @@ public class SubCommand_Find implements CommandProcesser { Map aroundShops = new HashMap<>(); + //Choose finding source Collection scanPool; if (allShops) { scanPool = plugin.getShopManager().getAllShops(); } else { scanPool = plugin.getShopManager().getLoadedShops(); } + //Calc distance between player and shop for (Shop shop : scanPool) { if (!Objects.equals(shop.getLocation().getWorld(), loc.getWorld())) { continue; @@ -108,12 +110,7 @@ public class SubCommand_Find implements CommandProcesser { aroundShops.put(shop, new Vector(shop.getLocation().getBlockX(), shop.getLocation().getBlockY(), shop.getLocation().getBlockZ()).distance(playerVector)); } } - - if (aroundShops.isEmpty()) { - MsgUtil.sendMessage(sender, MsgUtil.getMessage("no-nearby-shop", sender, lookFor)); - return; - } - + //Collect valid shop that trading items we want List missedShops = new ArrayList<>(); for (Shop shop : aroundShops.keySet()) { if (!Util.getItemStackName(shop.getItem()).toLowerCase().contains(lookFor)) { @@ -122,13 +119,21 @@ public class SubCommand_Find implements CommandProcesser { } } } + missedShops.forEach(aroundShops::remove); + //Check if no shops finded + if (aroundShops.isEmpty()) { + MsgUtil.sendMessage(sender, MsgUtil.getMessage("no-nearby-shop", sender, lookFor)); + return; + } + //Okay now all shops is our wanted shop in Map List> sortedShops = aroundShops.entrySet().stream().sorted(Comparator.comparingDouble(Map.Entry::getValue)) .collect(Collectors.toList()); + //Function if (usingOldLogic) { Map.Entry closest = sortedShops.get(0); Location lookAt = closest.getKey().getLocation().clone().add(0.5, 0.5, 0.5);