mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
Only show shops to players who point on the shop (configurable)
This commit is contained in:
parent
3459a8ccba
commit
00323510bb
@ -119,6 +119,9 @@ 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 **/
|
||||
public boolean only_show_shops_in_sight;
|
||||
|
||||
/**
|
||||
* <p>Whether shops should automatically be removed from the database if an error occurred while loading</p>
|
||||
* (e.g. when no chest is found at a shop's location)
|
||||
@ -337,6 +340,7 @@ public class Config {
|
||||
enable_towny_integration = plugin.getConfig().getBoolean("enable-towny-integration");
|
||||
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");
|
||||
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");
|
||||
|
@ -3,19 +3,22 @@ package de.epiceric.shopchest.utils;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ShopUtils {
|
||||
|
||||
@ -227,13 +230,62 @@ public class ShopUtils {
|
||||
* @param location Location of the player
|
||||
*/
|
||||
public void updateShops(Player player, Location location) {
|
||||
for (Shop shop : getShops()) {
|
||||
updateShop(shop, player, location);
|
||||
if (plugin.getShopChestConfig().only_show_shops_in_sight) {
|
||||
HashSet<Material> transparent = new HashSet<>();
|
||||
transparent.add(Material.AIR);
|
||||
List<Block> sight = player.getLineOfSight(transparent, (int) plugin.getShopChestConfig().maximal_distance);
|
||||
|
||||
ArrayList<Shop> shopsInSight = new ArrayList<>();
|
||||
|
||||
for (Block block : sight) {
|
||||
if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST) {
|
||||
if (isShop(block.getLocation())) {
|
||||
Shop shop = getShop(block.getLocation());
|
||||
shopsInSight.add(shop);
|
||||
|
||||
if (shop.getHologram() != null && !shop.getHologram().isVisible(player)) {
|
||||
shop.getHologram().showPlayer(player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Block below = block.getRelative(BlockFace.DOWN);
|
||||
if (isShop(below.getLocation())) {
|
||||
Shop shop = getShop(below.getLocation());
|
||||
shopsInSight.add(shop);
|
||||
|
||||
if (shop.getHologram() != null && !shop.getHologram().isVisible(player)) {
|
||||
shop.getHologram().showPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double itemDistSqr = Math.pow(plugin.getShopChestConfig().maximal_item_distance, 2);
|
||||
|
||||
for (Shop shop : getShops()) {
|
||||
if (shop.getItem() != null && shop.getLocation().getWorld().getName().equals(player.getWorld().getName())) {
|
||||
if (shop.getLocation().distanceSquared(player.getEyeLocation()) <= itemDistSqr) {
|
||||
shop.getItem().setVisible(player, true);
|
||||
} else {
|
||||
shop.getItem().setVisible(player, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!shopsInSight.contains(shop)) {
|
||||
if (shop.getHologram() != null) {
|
||||
shop.getHologram().hidePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Shop shop : getShops()) {
|
||||
updateShop(shop, player, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update hologram and item of the shop for a player
|
||||
* Update hologram and item of the shop for a player based on their distance to each other
|
||||
* @param shop Shop to update
|
||||
* @param player Player to show the update
|
||||
* @param location Location of the player
|
||||
|
@ -45,6 +45,11 @@ enable-towny-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.
|
||||
# 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 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
|
||||
|
Loading…
Reference in New Issue
Block a user