From 48bb669c0191dfd8d310964460b89eb68e36d78d Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 3 Jun 2019 15:58:13 +0200 Subject: [PATCH] Remove a couple config options - Shop items cannot be hidden - Hologram interaction had to be removed - Hopper/Explosion protection cannot be disabled - Admin shops cannot be counted in shop limit - Only the nearest shop the player points at is shown --- .../command/ShopCommandExecutor.java | 2 +- .../de/epiceric/shopchest/config/Config.java | 38 +--------- .../listeners/BlockExplodeListener.java | 11 ++- .../listeners/ChestProtectListener.java | 31 ++++---- .../listeners/ShopInteractListener.java | 72 ------------------- .../de/epiceric/shopchest/nms/Hologram.java | 27 +------ .../java/de/epiceric/shopchest/shop/Shop.java | 12 ++-- .../epiceric/shopchest/utils/ShopUtils.java | 21 +----- src/main/resources/config.yml | 28 +------- 9 files changed, 31 insertions(+), 211 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java b/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java index b455dd7..cca1ea7 100644 --- a/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java +++ b/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java @@ -234,7 +234,7 @@ class ShopCommandExecutor implements CommandExecutor { int limit = shopUtils.getShopLimit(p); if (limit != -1) { if (shopUtils.getShopAmount(p) >= limit) { - if (shopType != Shop.ShopType.ADMIN || !Config.excludeAdminShops) { + if (shopType != Shop.ShopType.ADMIN) { p.sendMessage(LanguageUtils.getMessage(Message.SHOP_LIMIT_REACHED, new Replacement(Placeholder.LIMIT, String.valueOf(limit)))); plugin.debug(p.getName() + " has reached the limit"); return; diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index a9a3ff5..ea8f092 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -131,16 +131,6 @@ public class Config { **/ public static boolean buyGreaterOrEqualSell; - /** - * Whether shops should be protected by hoppers - **/ - public static boolean hopperProtection; - - /** - * Whether shops should be protected by explosions - **/ - public static boolean explosionProtection; - /** * Whether buys and sells must be confirmed **/ @@ -157,11 +147,6 @@ public class Config { **/ public static boolean enableUpdateChecker; - /** - * Whether hologram interaction should be enabled - **/ - public static boolean enableHologramInteraction; - /** * Whether the debug log file should be created **/ @@ -229,36 +214,21 @@ public class Config { **/ public static boolean enableVendorMessages; - /** - * Whether admin shops should be excluded of the shop limits - **/ - public static boolean excludeAdminShops; - /** * Whether the extension of a potion or tipped arrow (if available) should be appended to the item name. **/ public static boolean appendPotionLevelToItemName; - /** - * Whether the shop items should be shown - **/ - public static boolean showShopItems; - /** * Whether players are allowed to sell/buy broken items **/ public static boolean allowBrokenItems; /** - * Whether only the shops a player has in sight should be shown to him + * Whether only the shop a player is pointing at should be shown **/ public static boolean onlyShowShopsInSight; - /** - * Whether only the shop a player is looking at should be shown to him - **/ - public static boolean onlyShowFirstShopInSight; - /** *

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) @@ -494,12 +464,9 @@ public class Config { creativeSelectItem = plugin.getConfig().getBoolean("creative-select-item"); blacklist = (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList() : plugin.getConfig().getStringList("blacklist"); buyGreaterOrEqualSell = plugin.getConfig().getBoolean("buy-greater-or-equal-sell"); - hopperProtection = plugin.getConfig().getBoolean("hopper-protection"); - explosionProtection = plugin.getConfig().getBoolean("explosion-protection"); confirmShopping = plugin.getConfig().getBoolean("confirm-shopping"); refundShopCreation = plugin.getConfig().getBoolean("refund-shop-creation"); enableUpdateChecker = plugin.getConfig().getBoolean("enable-update-checker"); - enableHologramInteraction = plugin.getConfig().getBoolean("enable-hologram-interaction"); enableDebugLog = plugin.getConfig().getBoolean("enable-debug-log"); enableEconomyLog = plugin.getConfig().getBoolean("enable-economy-log"); cleanupEconomyLogDays = plugin.getConfig().getInt("cleanup-economy-log-days"); @@ -514,10 +481,7 @@ public class Config { enableAreaShopIntegration = plugin.getConfig().getBoolean("enable-areashop-integration"); enableVendorMessages = plugin.getConfig().getBoolean("enable-vendor-messages"); onlyShowShopsInSight = plugin.getConfig().getBoolean("only-show-shops-in-sight"); - onlyShowFirstShopInSight = plugin.getConfig().getBoolean("only-show-first-shop-in-sight"); - excludeAdminShops = plugin.getConfig().getBoolean("shop-limits.exclude-admin-shops"); appendPotionLevelToItemName = plugin.getConfig().getBoolean("append-potion-level-to-item-name"); - showShopItems = plugin.getConfig().getBoolean("show-shop-items"); removeShopOnError = plugin.getConfig().getBoolean("remove-shop-on-error"); invertMouseButtons = plugin.getConfig().getBoolean("invert-mouse-buttons"); hologramFixedBottom = plugin.getConfig().getBoolean("hologram-fixed-bottom"); diff --git a/src/main/java/de/epiceric/shopchest/listeners/BlockExplodeListener.java b/src/main/java/de/epiceric/shopchest/listeners/BlockExplodeListener.java index 07ef86b..cdae016 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/BlockExplodeListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/BlockExplodeListener.java @@ -1,7 +1,6 @@ package de.epiceric.shopchest.listeners; import de.epiceric.shopchest.ShopChest; -import de.epiceric.shopchest.config.Config; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; @@ -20,12 +19,10 @@ public class BlockExplodeListener implements Listener { @EventHandler public void onBlockExplode(BlockExplodeEvent e) { - if (Config.explosionProtection) { - ArrayList bl = new ArrayList<>(e.blockList()); - for (Block b : bl) { - if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { - if (plugin.getShopUtils().isShop(b.getLocation())) e.blockList().remove(b); - } + ArrayList bl = new ArrayList<>(e.blockList()); + for (Block b : bl) { + if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { + if (plugin.getShopUtils().isShop(b.getLocation())) e.blockList().remove(b); } } } diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index 9681573..9065d85 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -115,12 +115,10 @@ public class ChestProtectListener implements Listener { @EventHandler(ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent e) { - if (Config.explosionProtection) { - ArrayList bl = new ArrayList<>(e.blockList()); - for (Block b : bl) { - if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { - if (shopUtils.isShop(b.getLocation())) e.blockList().remove(b); - } + ArrayList bl = new ArrayList<>(e.blockList()); + for (Block b : bl) { + if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { + if (shopUtils.isShop(b.getLocation())) e.blockList().remove(b); } } } @@ -224,22 +222,19 @@ public class ChestProtectListener implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onItemMove(InventoryMoveItemEvent e) { - if (Config.hopperProtection) { - if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) { + if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) { - if (e.getSource().getHolder() instanceof DoubleChest) { - DoubleChest dc = (DoubleChest) e.getSource().getHolder(); - Chest r = (Chest) dc.getRightSide(); - Chest l = (Chest) dc.getLeftSide(); + if (e.getSource().getHolder() instanceof DoubleChest) { + DoubleChest dc = (DoubleChest) e.getSource().getHolder(); + Chest r = (Chest) dc.getRightSide(); + Chest l = (Chest) dc.getLeftSide(); - if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) e.setCancelled(true); + if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) e.setCancelled(true); - } else if (e.getSource().getHolder() instanceof Chest) { - Chest c = (Chest) e.getSource().getHolder(); - - if (shopUtils.isShop(c.getLocation())) e.setCancelled(true); - } + } else if (e.getSource().getHolder() instanceof Chest) { + Chest c = (Chest) e.getSource().getHolder(); + if (shopUtils.isShop(c.getLocation())) e.setCancelled(true); } } } diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 6d636ea..401b942 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -15,7 +15,6 @@ import de.epiceric.shopchest.external.PlotSquaredShopFlag.GroupFlag; import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.Message; import de.epiceric.shopchest.language.Replacement; -import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.nms.JsonBuilder; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.ShopProduct; @@ -39,16 +38,12 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.Inventory; @@ -455,79 +450,12 @@ public class ShopInteractListener implements Listener { } } - @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { if (Config.enableAuthMeIntegration && plugin.hasAuthMe() && !AuthMeApi.getInstance().isAuthenticated(e.getPlayer())) return; handleInteractEvent(e); } - @EventHandler - public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent e) { - if (!Config.enableHologramInteraction) return; - - Entity entity = e.getRightClicked(); - Player p = e.getPlayer(); - if (Config.enableAuthMeIntegration && plugin.hasAuthMe() && !AuthMeApi.getInstance().isAuthenticated(p)) return; - - if (Utils.getMajorVersion() == 8 || e.getHand() == EquipmentSlot.HAND) { - if (entity instanceof ArmorStand) { - ArmorStand armorStand = (ArmorStand) entity; - if (Hologram.isPartOfHologram(armorStand)) { - Hologram hologram = Hologram.getHologram(armorStand); - if (hologram != null) { - Block b = null; - for (Shop shop : plugin.getShopUtils().getShops()) { - if (shop.getHologram() != null && shop.getHologram().equals(hologram)) { - b = shop.getLocation().getBlock(); - } - } - - if (b != null) { - PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null); - handleInteractEvent(interactEvent); - } - - } - } - } - } - } - - @EventHandler - public void onPlayerDamageEntity(EntityDamageByEntityEvent e) { - if (!Config.enableHologramInteraction) return; - - Entity entity = e.getEntity(); - Entity damager = e.getDamager(); - - if (!(damager instanceof Player)) return; - Player p = (Player) damager; - if (Config.enableAuthMeIntegration && plugin.hasAuthMe() && !AuthMeApi.getInstance().isAuthenticated(p)) return; - - if (entity instanceof ArmorStand) { - ArmorStand armorStand = (ArmorStand) entity; - if (Hologram.isPartOfHologram(armorStand)) { - Hologram hologram = Hologram.getHologram(armorStand); - if (hologram != null) { - Block b = null; - for (Shop shop : plugin.getShopUtils().getShops()) { - if (shop.getHologram() != null && shop.getHologram().equals(hologram)) { - b = shop.getLocation().getBlock(); - } - } - - if (b != null) { - PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null); - handleInteractEvent(interactEvent); - e.setCancelled(true); - } - - } - } - } - } - /** * Create a new shop * diff --git a/src/main/java/de/epiceric/shopchest/nms/Hologram.java b/src/main/java/de/epiceric/shopchest/nms/Hologram.java index f3343d2..afcbe56 100644 --- a/src/main/java/de/epiceric/shopchest/nms/Hologram.java +++ b/src/main/java/de/epiceric/shopchest/nms/Hologram.java @@ -44,7 +44,6 @@ public class Hologram { private final ShopChest plugin; private boolean exists; - private ArmorStandWrapper interactArmorStandWrapper; public Hologram(ShopChest plugin, String[] lines, Location location) { this.plugin = plugin; @@ -54,14 +53,6 @@ public class Hologram { addLine(i, lines[i]); } - if (Config.enableHologramInteraction) { - double y = 0.6; - if (Config.hologramFixedBottom) y = 0.85; - - Location loc = getLocation().add(0, y, 0); - interactArmorStandWrapper = new ArmorStandWrapper(plugin, loc, null, true); - } - this.exists = true; HOLOGRAMS.add(this); } @@ -90,7 +81,7 @@ public class Hologram { return true; } } - return interactArmorStandWrapper != null && armorStand.getUniqueId().equals(interactArmorStandWrapper.getUuid()); + return false; } /** @@ -100,13 +91,6 @@ public class Hologram { return wrappers; } - /** - * @return The {@link ArmorStandWrapper} of this hologram that is positioned higher to be used for interaction - */ - public ArmorStandWrapper getInteractArmorStandWrapper() { - return interactArmorStandWrapper; - } - /** * @param p Player to check * @return Whether the hologram is visible to the player @@ -163,11 +147,6 @@ public class Hologram { } wrappers.clear(); - if (interactArmorStandWrapper != null) { - interactArmorStandWrapper.remove(); - } - interactArmorStandWrapper = null; - exists = false; HOLOGRAMS.remove(this); } @@ -185,10 +164,6 @@ public class Hologram { for (ArmorStandWrapper wrapper : wrappers) { wrapper.setVisible(p, visible); } - - if (interactArmorStandWrapper != null) { - interactArmorStandWrapper.setVisible(p, visible); - } } /** diff --git a/src/main/java/de/epiceric/shopchest/shop/Shop.java b/src/main/java/de/epiceric/shopchest/shop/Shop.java index 2b27412..5e8e88e 100644 --- a/src/main/java/de/epiceric/shopchest/shop/Shop.java +++ b/src/main/java/de/epiceric/shopchest/shop/Shop.java @@ -117,7 +117,7 @@ public class Shop { plugin.debug("Failed to create shop (#" + id + ")"); plugin.debug(ex); return false; - } else if ((!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) && Config.showShopItems) { + } else if ((!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType()))) { NotEnoughSpaceException ex = new NotEnoughSpaceException(String.format("No space above chest in world '%s' at location: %d; %d; %d", b.getWorld().getName(), b.getX(), b.getY(), b.getZ())); plugin.getShopUtils().removeShop(this, Config.removeShopOnError); @@ -175,14 +175,12 @@ public class Shop { * Call this after {@link #createHologram()}, because it depends on the hologram's location */ private void createItem() { - if (Config.showShopItems) { - plugin.debug("Creating item (#" + id + ")"); + plugin.debug("Creating item (#" + id + ")"); - Location itemLocation; + Location itemLocation; - itemLocation = new Location(location.getWorld(), holoLocation.getX(), location.getY() + 0.9, holoLocation.getZ()); - item = new ShopItem(plugin, product.getItemStack(), itemLocation); - } + itemLocation = new Location(location.getWorld(), holoLocation.getX(), location.getY() + 0.9, holoLocation.getZ()); + item = new ShopItem(plugin, product.getItemStack(), itemLocation); } /** diff --git a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java index 325a724..bf76fd5 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java @@ -204,7 +204,7 @@ public class ShopUtils { for (Shop shop : getShops()) { if (shop.getVendor().equals(p)) { - if (shop.getShopType() != Shop.ShopType.ADMIN || !Config.excludeAdminShops) { + if (shop.getShopType() != Shop.ShopType.ADMIN) { shopCount++; InventoryHolder ih = shop.getInventoryHolder(); @@ -304,10 +304,8 @@ public class ShopUtils { private void updateVisibleShops(Player player) { double itemDistSquared = Math.pow(Config.maximalItemDistance, 2); - boolean firstShopInSight = Config.onlyShowFirstShopInSight; double maxDist = Config.maximalDistance; - List shopsInSight = new ArrayList<>(); double nearestDistSquared = Double.MAX_VALUE; Shop nearestShop = null; @@ -330,7 +328,6 @@ public class ShopUtils { } if (shop != null && shop.hasHologram()) { - shopsInSight.add(shop); double distSquared = pLoc.distanceSquared(loc); if (distSquared < nearestDistSquared) { nearestDistSquared = distSquared; @@ -340,14 +337,8 @@ public class ShopUtils { } for (Shop shop : getShops()) { - if (firstShopInSight) { - if (!shop.equals(nearestShop) && shop.hasHologram()) { - shop.getHologram().hidePlayer(player); - } - } else { - if (!shopsInSight.contains(shop)) { - shop.getHologram().hidePlayer(player); - } + if (!shop.equals(nearestShop) && shop.hasHologram()) { + shop.getHologram().hidePlayer(player); } // Display item based on distance @@ -368,12 +359,6 @@ public class ShopUtils { if (nearestShop != null) { nearestShop.getHologram().showPlayer(player); } - - if (!firstShopInSight) { - for (Shop otherShop : shopsInSight) { - otherShop.getHologram().showPlayer(player); - } - } } private void updateNearestShops(Player p) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f920edb..1de2a03 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,9 +13,6 @@ main-command-name: "shop" # (without the '.lang' extension) language-file: "en_US" -# Set whether the floating shop items on top of the chest should be shown -show-shop-items: true - # Set the item with which a player can click a shop to retrieve information. # You can set this to an empty string to disable this feature. shop-info-item: "STICK" @@ -44,12 +41,6 @@ refund-shop-creation: false # check for updates. enable-update-checker: true -# Set whether interaction with the hologram should be enabled. -# If set to true, a player can do the exact same thing with the -# hologram, as with the chest. You can even open the chest if you -# are the vendor or have permission. -enable-hologram-interaction: true - # Set whether buys and sells should be logged in the database. enable-economy-log: false @@ -107,10 +98,6 @@ enable-vendor-messages: true # 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 hologram's location should be fixed at the bottom, # so when it gets more lines, it won't interfere with the item or chest, # but goes higher. @@ -180,12 +167,6 @@ shop-creation-price: # ...an admin shop admin: 0 -# Set whether the shop's chest should be protected by hoppers -hopper-protection: true - -# Set whether the shop's chest should be protected by explosions -explosion-protection: true - # Set whether the buy price must be greater than or equal sell price. buy-greater-or-equal-sell: true @@ -248,8 +229,8 @@ towny-shop-plots: - "COMMERCIAL" # Configuration of the database, where everything is stored. -# Shops are found in the table 'shop_list', and logged economy -# transactions are found in the table 'shop_log' +# Shops are found in the table 'shopchest_shops', and logged economy +# transactions are found in the table 'shopchest_economy_logs' database: # Select the type of database which should be used @@ -287,12 +268,9 @@ database: # Shop limits are handled with permissions. # A player with permission "shopchest.limit.X" has a limit of X shops, # a player with permission "shopchest.limit.*" does not have a shop limit. +# Admin shops are excluded from the shop limit. shop-limits: - # Set whether admin shops should be excluded of the shop limits. - # If set to true, admin shops won't be added to a player's shop count. - exclude-admin-shops: true - # Set the amount of shops that anyone who doesn't have a # specific permission may have. # If you don't want the players to have a limit by default