Fix "chest blocked" error with cave/void air

This commit is contained in:
Eric 2019-04-28 22:10:27 +02:00
parent 77a837fc05
commit 8ef1fb391f
4 changed files with 10 additions and 3 deletions

View File

@ -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<Void>(plugin) {

View File

@ -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();

View File

@ -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);

View File

@ -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"}