diff --git a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java index ccdc578..5d30e93 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java @@ -13,12 +13,13 @@ import org.bukkit.block.DoubleChest; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.List; +import java.util.Set; public class ShopUtils { @@ -252,18 +253,7 @@ public class ShopUtils { } if (plugin.getShopChestConfig().only_show_shops_in_sight) { - HashSet transparent = new HashSet<>(); - transparent.add(Material.AIR); - - List sight; - - try { - sight = player.getLineOfSight(transparent, (int) plugin.getShopChestConfig().maximal_distance); - } catch (IllegalStateException e) { - // This method is occasionally throwing this exception but the exact reason is unknown... - plugin.debug("Failed to get line of sight: " + e.getMessage()); - return; - } + Set sight = getBlocksInSight(player); ArrayList shopsInSight = new ArrayList<>(); @@ -320,6 +310,28 @@ public class ShopUtils { playerLocation.put(player, player.getLocation()); } + private Set getBlocksInSight(Player player) { + double dist = plugin.getShopChestConfig().maximal_distance; + + Location loc = player.getEyeLocation(); + Vector direction = loc.getDirection(); + + Set blocks = new HashSet<>(); + blocks.add(loc.getBlock()); + + double i = 0; + + do { + blocks.add(loc.add(direction).getBlock()); + i++; + } while (i < dist - (dist%1)); + + direction.multiply(dist - (dist%1)); + blocks.add(loc.add(direction).getBlock()); + + return blocks; + } + /** * Update hologram and item of the shop for a player based on their distance to each other * @param shop Shop to update