From 8ef1fb391fb6d648583202a3fa21db7965fc96ec Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 28 Apr 2019 22:10:27 +0200 Subject: [PATCH] Fix "chest blocked" error with cave/void air --- .../epiceric/shopchest/listeners/ChestProtectListener.java | 3 ++- .../epiceric/shopchest/listeners/ShopInteractListener.java | 3 ++- src/main/java/de/epiceric/shopchest/shop/Shop.java | 2 +- src/main/java/de/epiceric/shopchest/utils/ItemUtils.java | 5 +++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index efd8fe8..2869b26 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -17,6 +17,7 @@ import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.utils.Callback; +import de.epiceric.shopchest.utils.ItemUtils; import de.epiceric.shopchest.utils.Permissions; import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.Utils; @@ -274,7 +275,7 @@ public class ChestProtectListener implements Listener { if (externalPluginsAllowed || p.hasPermission(Permissions.EXTEND_PROTECTED)) { if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.EXTEND_OTHER)) { - if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { + if (ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) { final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); shopUtils.removeShop(shop, true, new Callback(plugin) { diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 2beafb8..1e5dabd 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -28,6 +28,7 @@ import de.epiceric.shopchest.shop.ShopProduct; import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.sql.Database; import de.epiceric.shopchest.utils.ClickType; +import de.epiceric.shopchest.utils.ItemUtils; import de.epiceric.shopchest.utils.Permissions; import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.Utils; @@ -308,7 +309,7 @@ public class ShopInteractListener implements Listener { e.setCancelled(true); - if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { + if (ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) { ClickType clickType = ClickType.getPlayerClickType(p); ShopProduct product = clickType.getProduct(); double buyPrice = clickType.getBuyPrice(); diff --git a/src/main/java/de/epiceric/shopchest/shop/Shop.java b/src/main/java/de/epiceric/shopchest/shop/Shop.java index 0a81b91..2b27412 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 ((b.getRelative(BlockFace.UP).getType() != Material.AIR) && Config.showShopItems) { + } else if ((!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) && Config.showShopItems) { 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); diff --git a/src/main/java/de/epiceric/shopchest/utils/ItemUtils.java b/src/main/java/de/epiceric/shopchest/utils/ItemUtils.java index 3a7a0c7..da96b3c 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ItemUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ItemUtils.java @@ -8,6 +8,7 @@ import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.Potion; import org.bukkit.potion.PotionType; +import java.util.Arrays; import java.util.Map; public class ItemUtils { @@ -49,6 +50,10 @@ public class ItemUtils { return itemStack.getType().name().endsWith("BANNER_PATTERN"); } + public static boolean isAir(Material type) { + return Arrays.asList("AIR", "CAVE_AIR", "VOID_AIR").contains(type.name()); + } + /** * Get the {@link ItemStack} from a String * @param item Serialized ItemStack e.g. {@code "STONE"} or {@code "STONE:1"}