From bb54c7da679cb969c27c6c704960bade8f4c6f49 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 6 Aug 2016 13:32:37 +0200 Subject: [PATCH] Fixed NPE when player clicks in air --- .../listeners/ShopInteractListener.java | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 1f01431..1eaeb5c 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -62,39 +62,41 @@ public class ShopInteractListener implements Listener { Player p = e.getPlayer(); Block b = e.getClickedBlock(); - if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { - if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { - if (ClickType.getPlayerClickType(p) != null) { - if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) { - if (!shopUtils.isShop(b.getLocation())) { - if (e.isCancelled() && !perm.has(p, "shopchest.create.protected")) { - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); - ClickType.removePlayerClickType(p); - plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest"); - return; - } + if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { + if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (ClickType.getPlayerClickType(p) != null) { + if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) { + if (!shopUtils.isShop(b.getLocation())) { + if (e.isCancelled() && !perm.has(p, "shopchest.create.protected")) { + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); + ClickType.removePlayerClickType(p); + plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest"); + return; + } - e.setCancelled(true); + e.setCancelled(true); - if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { - ClickType clickType = ClickType.getPlayerClickType(p); - ItemStack product = clickType.getProduct(); - double buyPrice = clickType.getBuyPrice(); - double sellPrice = clickType.getSellPrice(); - ShopType shopType = clickType.getShopType(); + if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { + ClickType clickType = ClickType.getPlayerClickType(p); + ItemStack product = clickType.getProduct(); + double buyPrice = clickType.getBuyPrice(); + double sellPrice = clickType.getSellPrice(); + ShopType shopType = clickType.getShopType(); - create(p, b.getLocation(), product, buyPrice, sellPrice, shopType); + create(p, b.getLocation(), product, buyPrice, sellPrice, shopType); + } else { + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED)); + plugin.debug("Chest is blocked"); + } } else { - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED)); - plugin.debug("Chest is blocked"); + e.setCancelled(true); + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP)); + plugin.debug("Chest is already a shop"); } - } else { - e.setCancelled(true); - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP)); - plugin.debug("Chest is already a shop"); - } - ClickType.removePlayerClickType(p); + ClickType.removePlayerClickType(p); + } } } }