From d161fc60acfa7dbe5997eba336d8805a43c42110 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 19 Apr 2017 14:07:22 +0200 Subject: [PATCH] Only show the shop the player targets instead of all the shops he sees (configurable) --- .../java/de/epiceric/shopchest/config/Config.java | 6 +++++- .../de/epiceric/shopchest/utils/ShopUtils.java | 14 ++++++++++---- src/main/resources/config.yml | 6 +++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index bee834b..f2bef7b 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -143,9 +143,12 @@ public class Config { /** Whether players are allowed to sell/buy broken items **/ public boolean allow_broken_items; - /** Whether only the shops a player points on should be shown to him **/ + /** Whether only the shops a player has in sight should be shown to him **/ public boolean only_show_shops_in_sight; + /** Whether only the shop a player is looking at should be shown to him **/ + public boolean only_show_first_shop_in_sight; + /** *

Whether shops should automatically be removed from the database if an error occurred while loading

* (e.g. when no chest is found at a shop's location) @@ -373,6 +376,7 @@ public class Config { enable_vendor_messages = plugin.getConfig().getBoolean("enable-vendor-messages"); explosion_protection = plugin.getConfig().getBoolean("explosion-protection"); only_show_shops_in_sight = plugin.getConfig().getBoolean("only-show-shops-in-sight"); + only_show_first_shop_in_sight = plugin.getConfig().getBoolean("only-show-first-shop-in-sight"); exclude_admin_shops = plugin.getConfig().getBoolean("shop-limits.exclude-admin-shops"); append_potion_level_to_item_name = plugin.getConfig().getBoolean("append-potion-level-to-item-name"); show_shop_items = plugin.getConfig().getBoolean("show-shop-items"); diff --git a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java index b8d5213..ccdc578 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java @@ -269,23 +269,27 @@ public class ShopUtils { for (Block block : sight) { if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST) { - if (isShop(block.getLocation())) { - Shop shop = getShop(block.getLocation()); + Shop shop = getShop(block.getLocation()); + if (shop != null) { shopsInSight.add(shop); if (shop.getHologram() != null && !shop.getHologram().isVisible(player)) { shop.getHologram().showPlayer(player); } + + if (plugin.getShopChestConfig().only_show_first_shop_in_sight) break; } } else { Block below = block.getRelative(BlockFace.DOWN); - if (isShop(below.getLocation())) { - Shop shop = getShop(below.getLocation()); + Shop shop = getShop(below.getLocation()); + if (shop != null) { shopsInSight.add(shop); if (shop.getHologram() != null && !shop.getHologram().isVisible(player)) { shop.getHologram().showPlayer(player); } + + if (plugin.getShopChestConfig().only_show_first_shop_in_sight) break; } } } @@ -322,6 +326,8 @@ public class ShopUtils { * @param player Player to show the update */ public void updateShop(Shop shop, Player player) { + if (shop.getLocation().getChunk().isLoaded()) return; + double holoDistSqr = Math.pow(plugin.getShopChestConfig().maximal_distance, 2); double itemDistSqr = Math.pow(plugin.getShopChestConfig().maximal_item_distance, 2); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b91b535..62e5e98 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -65,11 +65,15 @@ enable-islandworld-integration: true # buy or sell something from/to his shop or if his shop is out of stock enable-vendor-messages: true -# Set whether only the shops a player points on should be shown to him. +# Set whether only the shops a player has in sight should be shown to him. # If set to false, every shop near the player (with the specified # distance) will be shown to him. only-show-shops-in-sight: true +# Set whether only the shop a player is looking at should be shown to him. +# This only has effect if 'only-show-shops-in-sight' is enabled +only-show-first-shop-in-sight: true + # Set whether the buy- and sell price should be arranged below each other. # The first line will be the buy price with the message # "message.hologram.only-buy", the second line will be the sell price