From ea41f6759e04866dad9c111d4d1d23f4596f3f5a Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 25 Mar 2017 13:18:52 +0100 Subject: [PATCH] Shop chests can only be broken with an axe --- .../shopchest/listeners/ChestProtectListener.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index a9d57f6..c49f762 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -12,6 +12,7 @@ import de.epiceric.shopchest.language.LocalizedMessage; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.utils.Permissions; import de.epiceric.shopchest.utils.ShopUtils; +import de.epiceric.shopchest.utils.Utils; import de.epiceric.shopchest.worldguard.ShopFlag; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -29,8 +30,11 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public class ChestProtectListener implements Listener { @@ -80,7 +84,10 @@ public class ChestProtectListener implements Listener { final Shop shop = shopUtils.getShop(e.getBlock().getLocation()); Player p = e.getPlayer(); - if (p.isSneaking()) { + ItemStack item = Utils.getPreferredItemInHand(p); + List axes = Arrays.asList(Material.WOOD_AXE, Material.STONE_AXE, Material.IRON_AXE, Material.GOLD_AXE, Material.DIAMOND_AXE); + + if (p.isSneaking() && item != null && axes.contains(item.getType())) { plugin.debug(String.format("%s tries to break %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); if (shop.getShopType() == Shop.ShopType.ADMIN) {